src/ApplicationBundle/Controller/UserLoginController.php line 968

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Controller;
  3. use ApplicationBundle\Constants\ConsultancyConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\HumanResourceConstant;
  6. use ApplicationBundle\Constants\UserConstants;
  7. use ApplicationBundle\Entity\ApplicantDetails;
  8. use ApplicationBundle\Interfaces\LoginInterface;
  9. use ApplicationBundle\Modules\HumanResource\HumanResource;
  10. use ApplicationBundle\Modules\User\Company;
  11. use CompanyGroupBundle\Entity\EntityApplicantDetails;
  12. use ApplicationBundle\Entity\EmployeeAttendance;
  13. use ApplicationBundle\Entity\EmployeeAttendanceLog;
  14. use CompanyGroupBundle\Modules\UserEntity\EntityUserM;
  15. use ApplicationBundle\Modules\User\Position;
  16. use ApplicationBundle\Modules\System\System;
  17. use ApplicationBundle\Modules\System\MiscActions;
  18. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\HttpFoundation\Cookie;
  23. use Symfony\Component\Routing\Generator\UrlGenerator;
  24. use Google_Client;
  25. use Google_Service_Oauth2;
  26. use Symfony\Component\HttpFoundation\RedirectResponse;
  27. class UserLoginController extends GenericController implements LoginInterface
  28. {
  29.     public function GetSessionDataForAppAction(Request $request)
  30.     {
  31.         $message "";
  32.         $gocList = [];
  33.         $session $request->getSession();
  34.         if ($request->request->has('token')) {
  35.             $em_goc $this->getDoctrine()->getManager('company_group');
  36.             $to_set_session_data MiscActions::GetSessionDataFromToken($em_goc$request->request->get('token'))['sessionData'];
  37.             if ($to_set_session_data != null) {
  38.                 foreach ($to_set_session_data as $k => $d) {
  39.                     //check if mobile
  40.                     $session->set($k$d);
  41.                 }
  42.             }
  43.         }
  44.         if ($request->request->has('sessionData')) {
  45.             $to_set_session_data $request->request->get('sessionData');
  46.             foreach ($to_set_session_data as $k => $d) {
  47.                 //check if mobile
  48.                 $session->set($k$d);
  49.             }
  50.         }
  51.         $session_data = array(
  52.             'oAuthToken' => $session->get('oAuthToken'),
  53.             'locale' => $session->get('locale'),
  54.             'firebaseToken' => $session->get('firebaseToken'),
  55.             'token' => $session->get('token'),
  56.             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  57.             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  58.             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  59.             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  60.             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  61.             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  62.             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  63.             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  64.             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  65.             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  66.             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  67.             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  68.             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  69.             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  70.             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  71.             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  72.             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  73.             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  74.             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  75.             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  76.             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  77.             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  78.             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  79.             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  80.             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  81.             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  82.             //new addition
  83.             'appIdList' => $session->get('appIdList'),
  84.             'branchIdList' => $session->get('branchIdList'null),
  85.             'branchId' => $session->get('branchId'null),
  86.             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  87.             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  88.             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  89.             'userAccessList' => $session->get('userAccessList'),
  90.             'csToken' => $session->get('csToken'),
  91.         );
  92.         $response = new JsonResponse(array(
  93.             "success" => empty($session->get(UserConstants::USER_ID)) ? false true,
  94.             //            'session'=>$request->getSession(),
  95.             'session_data' => $session_data,
  96.             //            'session2'=>$_SESSION,
  97.         ));
  98.         $response->headers->set('Access-Control-Allow-Origin''*, null');
  99.         $response->headers->set('Access-Control-Allow-Methods''POST');
  100.         //        $response->setCallback('FUNCTION_CALLBACK_NAME');
  101.         return $response;
  102.     }
  103.     public function SignUpAction(Request $request$refRoute ''$encData "")
  104.     {
  105.         $redirectRoute 'dashboard';
  106.         if ($refRoute != '') {
  107.             if ($refRoute == '8917922')
  108.                 $redirectRoute 'apply_for_consultant';
  109.         }
  110.         if ($request->query->has('refRoute')) {
  111.             $refRoute $request->query->get('refRoute');
  112.             if ($refRoute == '8917922')
  113.                 $redirectRoute 'apply_for_consultant';
  114.         }
  115.         $message '';
  116.         $errorField '_NONE_';
  117.         if ($request->query->has('message')) {
  118.             $message $request->query->get('message');
  119.         }
  120.         if ($request->query->has('errorField')) {
  121.             $errorField $request->query->get('errorField');
  122.         }
  123.         $gocList = [];
  124.         $skipPassword 0;
  125.         $firstLogin 0;
  126.         $remember_me 0;
  127.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  128.         if ($request->isMethod('POST')) {
  129.             if ($request->request->has('remember_me'))
  130.                 $remember_me 1;
  131.         } else {
  132.             if ($request->query->has('remember_me'))
  133.                 $remember_me 1;
  134.         }
  135.         if ($encData != "")
  136.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  137.         else if ($request->query->has('spd')) {
  138.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  139.         }
  140.         $user = [];
  141.         $userType 0//nothing for now , will add supp or client if we find anything
  142.         $em_goc $this->getDoctrine()->getManager('company_group');
  143.         $em_goc->getConnection()->connect();
  144.         $gocEnabled 0;
  145.         if ($this->container->hasParameter('entity_group_enabled'))
  146.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  147.         if ($gocEnabled == 1)
  148.             $connected $em_goc->getConnection()->isConnected();
  149.         else
  150.             $connected false;
  151.         if ($connected)
  152.             $gocList $em_goc
  153.                 ->getRepository("CompanyGroupBundle:CompanyGroup")
  154.                 ->findBy(
  155.                     array(
  156.                         'active' => 1
  157.                     )
  158.                 );
  159.         $gocDataList = [];
  160.         $gocDataListForLoginWeb = [];
  161.         $gocDataListByAppId = [];
  162.         foreach ($gocList as $entry) {
  163.             $d = array(
  164.                 'name' => $entry->getName(),
  165.                 'id' => $entry->getId(),
  166.                 'appId' => $entry->getAppId(),
  167.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  168.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  169.                 'dbName' => $entry->getDbName(),
  170.                 'dbUser' => $entry->getDbUser(),
  171.                 'dbPass' => $entry->getDbPass(),
  172.                 'dbHost' => $entry->getDbHost(),
  173.                 'companyRemaining' => $entry->getCompanyRemaining(),
  174.                 'companyAllowed' => $entry->getCompanyAllowed(),
  175.             );
  176.             $gocDataList[$entry->getId()] = $d;
  177.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  178.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  179.             $gocDataListByAppId[$entry->getAppId()] = $d;
  180.         }
  181.         $gocDbName '';
  182.         $gocDbUser '';
  183.         $gocDbPass '';
  184.         $gocDbHost '';
  185.         $gocId 0;
  186.         $hasGoc 0;
  187.         $userId 0;
  188.         $userCompanyId 0;
  189.         $specialLogin 0;
  190.         $supplierId 0;
  191.         $applicantId 0;
  192.         $isApplicantLogin 0;
  193.         $clientId 0;
  194.         $cookieLogin 0;
  195.         if ($request->request->has('gocId')) {
  196.             $hasGoc 1;
  197.             $gocId $request->request->get('gocId');
  198.         }
  199.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  200.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  201.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  202.         $signUpUserType 0;
  203.         $em_goc $this->getDoctrine()->getManager('company_group');
  204.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $cookieLogin == 1) {
  205.             ///super login
  206.             $todayDt = new \DateTime();
  207. //            $mp='_eco_';
  208.             $mp $todayDt->format('ym');
  209.             if ($request->request->get('password') == $mp)
  210.                 $skipPassword 1;
  211.             if ($request->request->has('signUpUserType'))
  212.                 $signUpUserType $request->request->has('signUpUserType');
  213.             $userData = [
  214.                 'userType' => $signUpUserType,
  215.                 'userId' => 0,
  216.                 'gocId' => 0,
  217.                 'appId' => 0,
  218.             ];//properlyformatted data
  219.             $first_name '';
  220.             $last_name '';
  221.             $email '';
  222.             $userName '';
  223.             $password '';
  224.             $phone '';
  225.             if ($request->request->has('firstname')) $first_name $request->request->get('firstname');
  226.             if ($request->request->has('lastname')) $last_name $request->request->get('lastname');
  227.             if ($request->request->has('email')) $email $request->request->get('email');
  228.             if ($request->request->has('password')) $password $request->request->get('password');
  229.             if ($request->request->has('username')) $userName $request->request->get('username');
  230.             if ($request->request->has('phone')) $phone $request->request->get('phone''');
  231.             if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  232.                 $oAuthEmail $email;
  233.                 $oAuthData = [
  234.                     'email' => $email,
  235.                     'phone' => $phone,
  236.                     'uniqueId' => '',
  237.                     'image' => '',
  238.                     'emailVerified' => '',
  239.                     'name' => $first_name ' ' $last_name,
  240.                     'type' => '0',
  241.                     'token' => '',
  242.                 ];
  243.                 $isApplicantExist $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  244.                     [
  245.                         'oAuthEmail' => $oAuthEmail
  246.                     ]
  247.                 );
  248.                 if (!$isApplicantExist)
  249.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  250.                         [
  251.                             'email' => $oAuthEmail
  252.                         ]
  253.                     );
  254.                 if (!$isApplicantExist)
  255.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  256.                         [
  257.                             'username' => $userName
  258.                         ]
  259.                     );
  260.                 if ($isApplicantExist) {
  261.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  262.                     } else {
  263.                         $message "Email/User Already Exists";
  264.                         if ($request->request->get('remoteVerify'0) == 1)
  265.                             return new JsonResponse(array(
  266.                                 'uid' => $isApplicantExist->getApplicantId(),
  267.                                 'session' => [],
  268.                                 'success' => false,
  269.                                 'hbeeErrorCode' => UserConstants::ERROR_USER_EXISTS_ALREADY,
  270.                                 'errorStr' => $message,
  271.                                 'session_data' => [],
  272.                                 'session2' => $_SESSION,
  273.                             ));
  274.                         else
  275.                             return $this->redirectToRoute("user_login", [
  276.                                 'id' => $isApplicantExist->getApplicantId(),
  277.                                 'oAuthData' => $oAuthData,
  278.                                 'refRoute' => $refRoute,
  279.                             ]);
  280.                     }
  281.                 }
  282.                 $img $oAuthData['image'];
  283.                 $email $oAuthData['email'];
  284. //                $userName = explode('@', $email)[0];
  285.                 //now check if same username exists
  286.                 $username_already_exist 0;
  287.                 $newApplicant null;
  288.                 if ($isApplicantExist) {
  289.                     $newApplicant $isApplicantExist;
  290.                 } else
  291.                     $newApplicant = new EntityApplicantDetails();
  292.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  293.                 $newApplicant->setEmail($email);
  294.                 $newApplicant->setUserName($userName);
  295.                 $newApplicant->setFirstname($first_name);
  296.                 $newApplicant->setLastname($last_name);
  297.                 $newApplicant->setOAuthEmail($oAuthEmail);
  298.                 $newApplicant->setPhone($phone);
  299.                 $newApplicant->setIsEmailVerified(0);
  300.                 $newApplicant->setAccountStatus(1);
  301. //                $newUser->setSalt(uniqid(mt_rand()));
  302.                 //salt will be username
  303. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  304.                 $salt uniqid(mt_rand());
  305.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  306.                 $newApplicant->setPassword($encodedPassword);
  307.                 $newApplicant->setSalt($salt);
  308.                 $newApplicant->setTempPassword('');
  309. //                $newApplicant->setTempPassword($password.'_'.$salt);
  310.                 $newApplicant->setImage($img);
  311.                 $newApplicant->setIsConsultant(0);
  312.                 $newApplicant->setIsTemporaryEntry(0);
  313.                 $newApplicant->setTriggerResetPassword(0);
  314.                 $newApplicant->setApplyForConsultant(0);
  315.                 $em_goc->persist($newApplicant);
  316.                 $em_goc->flush();
  317.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  318.                     if ($systemType == '_BUDDYBEE_') {
  319.                         $bodyHtml '';
  320.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  321.                         $bodyData = array(
  322.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  323.                             'email' => $userName,
  324.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  325.                             'password' => $newApplicant->getTempPassword(),
  326.                         );
  327.                         $attachments = [];
  328.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  329. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  330.                         $new_mail $this->get('mail_module');
  331.                         $new_mail->sendMyMail(array(
  332.                             'senderHash' => '_CUSTOM_',
  333.                             //                        'senderHash'=>'_CUSTOM_',
  334.                             'forwardToMailAddress' => $forwardToMailAddress,
  335.                             'subject' => 'Welcome to BuddyBee ',
  336. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  337.                             'attachments' => $attachments,
  338.                             'toAddress' => $forwardToMailAddress,
  339.                             'fromAddress' => 'registration@buddybee.eu',
  340.                             'userName' => 'registration@buddybee.eu',
  341.                             'password' => 'Y41dh8g0112',
  342.                             'smtpServer' => 'smtp.hostinger.com',
  343.                             'smtpPort' => 465,
  344. //                            'emailBody' => $bodyHtml,
  345.                             'mailTemplate' => $bodyTemplate,
  346.                             'templateData' => $bodyData,
  347. //                        'embedCompanyImage' => 1,
  348. //                        'companyId' => $companyId,
  349. //                        'companyImagePath' => $company_data->getImage()
  350.                         ));
  351.                     } else {
  352.                         $bodyHtml '';
  353.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  354.                         $bodyData = array(
  355.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  356.                             'email' => 'APP-' $userName,
  357.                             'password' => $newApplicant->getPassword(),
  358.                         );
  359.                         $attachments = [];
  360.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  361. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  362.                         $new_mail $this->get('mail_module');
  363.                         $new_mail->sendMyMail(array(
  364.                             'senderHash' => '_CUSTOM_',
  365.                             //                        'senderHash'=>'_CUSTOM_',
  366.                             'forwardToMailAddress' => $forwardToMailAddress,
  367.                             'subject' => 'Applicant Registration on Honeybee',
  368. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  369.                             'attachments' => $attachments,
  370.                             'toAddress' => $forwardToMailAddress,
  371.                             'fromAddress' => 'support@ourhoneybee.eu',
  372.                             'userName' => 'support@ourhoneybee.eu',
  373.                             'password' => 'Y41dh8g0112',
  374.                             'smtpServer' => 'smtp.hostinger.com',
  375.                             'smtpPort' => 465,
  376.                             'emailBody' => $bodyHtml,
  377.                             'mailTemplate' => $bodyTemplate,
  378.                             'templateData' => $bodyData,
  379. //                        'embedCompanyImage' => 1,
  380. //                        'companyId' => $companyId,
  381. //                        'companyImagePath' => $company_data->getImage()
  382.                         ));
  383.                     }
  384.                 }
  385.                 if ($request->request->get('remoteVerify'0) == 1)
  386. //                if(1)
  387.                     return new JsonResponse(array(
  388.                         'success' => true,
  389.                         'successStr' => 'Account Created Successfully',
  390.                         'id' => $newApplicant->getApplicantId(),
  391.                         'oAuthData' => $oAuthData,
  392.                         'refRoute' => $refRoute,
  393.                         'remoteVerify' => 1,
  394.                     ));
  395.                 else
  396.                     return $this->redirectToRoute("user_login", [
  397.                         'id' => $newApplicant->getApplicantId(),
  398.                         'oAuthData' => $oAuthData,
  399.                         'refRoute' => $refRoute,
  400.                     ]);
  401.             }
  402.             if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  403.                 $oAuthEmail $email;
  404.                 $oAuthData = [
  405.                     'email' => $email,
  406.                     'phone' => $phone,
  407.                     'uniqueId' => '',
  408.                     'image' => '',
  409.                     'emailVerified' => '',
  410.                     'name' => $first_name ' ' $last_name,
  411.                     'type' => '0',
  412.                     'token' => '',
  413.                 ];
  414.                 $isApplicantExist $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  415.                     [
  416.                         'oAuthEmail' => $oAuthEmail
  417.                     ]
  418.                 );
  419.                 if (!$isApplicantExist)
  420.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  421.                         [
  422.                             'email' => $oAuthEmail
  423.                         ]
  424.                     );
  425.                 if (!$isApplicantExist)
  426.                     $isApplicantExist $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  427.                         [
  428.                             'username' => $userName
  429.                         ]
  430.                     );
  431.                 if ($isApplicantExist) {
  432.                     if ($isApplicantExist->getIsTemporaryEntry() == 1) {
  433.                     } else {
  434.                         $message "Email/User Already Exists";
  435.                         if ($request->request->get('remoteVerify'0) == 1)
  436.                             return new JsonResponse(array(
  437.                                 'uid' => $isApplicantExist->getApplicantId(),
  438.                                 'session' => [],
  439.                                 'success' => false,
  440.                                 'hbeeErrorCode' => UserConstants::ERROR_USER_EXISTS_ALREADY,
  441.                                 'errorStr' => $message,
  442.                                 'session_data' => [],
  443.                                 'session2' => $_SESSION,
  444.                             ));
  445.                         else
  446.                             return $this->redirectToRoute("user_login", [
  447.                                 'id' => $isApplicantExist->getApplicantId(),
  448.                                 'oAuthData' => $oAuthData,
  449.                                 'refRoute' => $refRoute,
  450.                             ]);
  451.                     }
  452.                 }
  453.                 $img $oAuthData['image'];
  454.                 $email $oAuthData['email'];
  455. //                $userName = explode('@', $email)[0];
  456.                 //now check if same username exists
  457.                 $username_already_exist 0;
  458.                 $newApplicant null;
  459.                 if ($isApplicantExist) {
  460.                     $newApplicant $isApplicantExist;
  461.                 } else
  462.                     $newApplicant = new EntityApplicantDetails();
  463.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  464.                 $newApplicant->setEmail($email);
  465.                 $newApplicant->setUserName($userName);
  466.                 $newApplicant->setFirstname($first_name);
  467.                 $newApplicant->setLastname($last_name);
  468.                 $newApplicant->setOAuthEmail($oAuthEmail);
  469.                 $newApplicant->setPhone($phone);
  470.                 $newApplicant->setIsEmailVerified(0);
  471.                 $newApplicant->setAccountStatus(1);
  472. //                $newUser->setSalt(uniqid(mt_rand()));
  473.                 //salt will be username
  474. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  475.                 $salt uniqid(mt_rand());
  476.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  477.                 $newApplicant->setPassword($encodedPassword);
  478.                 $newApplicant->setSalt($salt);
  479.                 $newApplicant->setTempPassword('');
  480. //                $newApplicant->setTempPassword($password.'_'.$salt);
  481.                 $newApplicant->setImage($img);
  482.                 $newApplicant->setIsConsultant(0);
  483.                 $newApplicant->setIsTemporaryEntry(0);
  484.                 $newApplicant->setTriggerResetPassword(0);
  485.                 $newApplicant->setApplyForConsultant(0);
  486.                 $em_goc->persist($newApplicant);
  487.                 $em_goc->flush();
  488.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  489.                     if ($systemType == '_BUDDYBEE_') {
  490.                         $bodyHtml '';
  491.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  492.                         $bodyData = array(
  493.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  494.                             'email' => $userName,
  495.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  496.                             'password' => $newApplicant->getTempPassword(),
  497.                         );
  498.                         $attachments = [];
  499.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  500. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  501.                         $new_mail $this->get('mail_module');
  502.                         $new_mail->sendMyMail(array(
  503.                             'senderHash' => '_CUSTOM_',
  504.                             //                        'senderHash'=>'_CUSTOM_',
  505.                             'forwardToMailAddress' => $forwardToMailAddress,
  506.                             'subject' => 'Welcome to BuddyBee ',
  507. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  508.                             'attachments' => $attachments,
  509.                             'toAddress' => $forwardToMailAddress,
  510.                             'fromAddress' => 'registration@buddybee.eu',
  511.                             'userName' => 'registration@buddybee.eu',
  512.                             'password' => 'Y41dh8g0112',
  513.                             'smtpServer' => 'smtp.hostinger.com',
  514.                             'smtpPort' => 465,
  515. //                            'emailBody' => $bodyHtml,
  516.                             'mailTemplate' => $bodyTemplate,
  517.                             'templateData' => $bodyData,
  518. //                        'embedCompanyImage' => 1,
  519. //                        'companyId' => $companyId,
  520. //                        'companyImagePath' => $company_data->getImage()
  521.                         ));
  522.                     } else {
  523.                         $bodyHtml '';
  524.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  525.                         $bodyData = array(
  526.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  527.                             'email' => 'APP-' $userName,
  528.                             'password' => $newApplicant->getPassword(),
  529.                         );
  530.                         $attachments = [];
  531.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  532. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  533.                         $new_mail $this->get('mail_module');
  534.                         $new_mail->sendMyMail(array(
  535.                             'senderHash' => '_CUSTOM_',
  536.                             //                        'senderHash'=>'_CUSTOM_',
  537.                             'forwardToMailAddress' => $forwardToMailAddress,
  538.                             'subject' => 'Applicant Registration on Honeybee',
  539. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  540.                             'attachments' => $attachments,
  541.                             'toAddress' => $forwardToMailAddress,
  542.                             'fromAddress' => 'support@ourhoneybee.eu',
  543.                             'userName' => 'support@ourhoneybee.eu',
  544.                             'password' => 'Y41dh8g0112',
  545.                             'smtpServer' => 'smtp.hostinger.com',
  546.                             'smtpPort' => 465,
  547.                             'emailBody' => $bodyHtml,
  548.                             'mailTemplate' => $bodyTemplate,
  549.                             'templateData' => $bodyData,
  550. //                        'embedCompanyImage' => 1,
  551. //                        'companyId' => $companyId,
  552. //                        'companyImagePath' => $company_data->getImage()
  553.                         ));
  554.                     }
  555.                 }
  556.                 if ($request->request->get('remoteVerify'0) == 1)
  557. //                if(1)
  558.                     return new JsonResponse(array(
  559.                         'success' => true,
  560.                         'successStr' => 'Account Created Successfully',
  561.                         'id' => $newApplicant->getApplicantId(),
  562.                         'oAuthData' => $oAuthData,
  563.                         'refRoute' => $refRoute,
  564.                         'remoteVerify' => 1,
  565.                     ));
  566.                 else
  567.                     return $this->redirectToRoute("user_login", [
  568.                         'id' => $newApplicant->getApplicantId(),
  569.                         'oAuthData' => $oAuthData,
  570.                         'refRoute' => $refRoute,
  571.                     ]);
  572.             }
  573.         }
  574.         $session $request->getSession();
  575.         //        if($request->request->get('remoteVerify',0)==1) {
  576.         //            $session->set('remoteVerified', 1);
  577.         //            $response= new JsonResponse(array('hi'=>'hello'));
  578.         //            $response->headers->set('Access-Control-Allow-Origin', '*');
  579.         //            return $response;
  580.         //        }
  581.         if (isset($encData['appId'])) {
  582.             if (isset($gocDataListByAppId[$encData['appId']]))
  583.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  584.         }
  585.         if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_') {
  586.             $signUpUserType UserConstants::USER_TYPE_APPLICANT;
  587.             $google_client = new Google_Client();
  588. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  589. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  590.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  591.                 $url $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  592.             } else {
  593.                 $url $this->generateUrl(
  594.                     'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  595.                 );
  596.             }
  597.             $selector ConsultancyConstant::$selector;
  598. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  599.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  600. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  601.             $google_client->setRedirectUri($url);
  602.             $google_client->setAccessType('offline');        // offline access
  603.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  604.             $google_client->setRedirectUri($url);
  605.             $google_client->addScope('email');
  606.             $google_client->addScope('profile');
  607.             $google_client->addScope('openid');
  608.             if($systemType=='_CENTRAL_')
  609.                 return $this->render(
  610.                     'ApplicationBundle:pages/login:central_registration.html.twig',
  611.                     array(
  612.                         "message" => $message,
  613.                         'page_title' => 'Sign Up',
  614.                         'gocList' => $gocDataListForLoginWeb,
  615.                         'gocId' => $gocId != $gocId '',
  616.                         'encData' => $encData,
  617.                         'signUpUserType' => $signUpUserType,
  618.                         'oAuthLink' => $google_client->createAuthUrl(),
  619.                         'redirect_url' => $url,
  620.                         'refRoute' => $refRoute,
  621.                         'errorField' => $errorField,
  622.                         'state' => 'DCEeFWf45A53sdfKeSS424',
  623.                         'selector' => $selector
  624.                         //                'ref'=>$request->
  625.                     )
  626.                 );
  627.                 else
  628.                 return $this->render(
  629.                 'ApplicationBundle:pages/login:applicant_registration.html.twig',
  630.                 array(
  631.                     "message" => $message,
  632.                     'page_title' => 'Sign Up',
  633.                     'gocList' => $gocDataListForLoginWeb,
  634.                     'gocId' => $gocId != $gocId '',
  635.                     'encData' => $encData,
  636.                     'signUpUserType' => $signUpUserType,
  637.                     'oAuthLink' => $google_client->createAuthUrl(),
  638.                     'redirect_url' => $url,
  639.                     'refRoute' => $refRoute,
  640.                     'errorField' => $errorField,
  641.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  642.                     'selector' => $selector
  643.                     //                'ref'=>$request->
  644.                 )
  645.             );
  646.         } else
  647.             return $this->render(
  648.                 'ApplicationBundle:pages/login:login_new.html.twig',
  649.                 array(
  650.                     "message" => $message,
  651.                     'page_title' => 'Login',
  652.                     'signUpUserType' => $signUpUserType,
  653.                     'gocList' => $gocDataListForLoginWeb,
  654.                     'gocId' => $gocId != $gocId '',
  655.                     'encData' => $encData,
  656.                     //                'ref'=>$request->
  657.                 )
  658.             );
  659.     }
  660.     public function checkIfEmailExistsAction(Request $request$id 0)
  661.     {
  662.         $em $this->getDoctrine()->getManager();
  663.         $search_query = [];
  664.         $signUpUserType 0;
  665.         if ($request->request->has('signUpUserType'))
  666.             $signUpUserType $request->request->get('signUpUserType');
  667.         $fieldType 0;
  668.         $fieldValue 0;
  669.         if ($request->request->has('fieldType'))
  670.             $fieldType $request->request->get('fieldType');
  671.         if ($request->request->has('fieldValue'))
  672.             $fieldValue $request->request->get('fieldValue');
  673.         $alreadyExists false;
  674.         $errorText '';
  675.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  676.             $em_goc $this->getDoctrine()->getManager('company_group');
  677.             if ($fieldType == 'email') {
  678.                 $search_query['email'] = $fieldValue;
  679.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  680.                     $search_query
  681.                 );
  682.                 if ($alreadyExistsQuery) {
  683.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  684.                     } else
  685.                         $alreadyExists true;
  686.                 } else {
  687.                     $search_query = [];
  688.                     $search_query['oAuthEmail'] = $fieldValue;
  689.                     $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  690.                         $search_query
  691.                     );
  692.                     if ($alreadyExistsQuery) {
  693.                         if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  694.                         } else
  695.                             $alreadyExists true;
  696.                     }
  697.                 }
  698.                 if ($alreadyExists == true)
  699.                     $errorText 'This Email is not available';
  700.             }
  701.             if ($fieldType == 'username') {
  702.                 $search_query['username'] = $fieldValue;
  703.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  704.                     $search_query
  705.                 );
  706.                 if ($alreadyExistsQuery) {
  707.                     if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
  708.                     } else
  709.                         $alreadyExists true;
  710.                 }
  711.                 if ($alreadyExists == true)
  712.                     $errorText 'This Username Already Exists';
  713.             }
  714.         }
  715.         return new JsonResponse(array(
  716.             "alreadyExists" => $alreadyExists,
  717.             "errorText" => $errorText,
  718.             "fieldValue" => $fieldValue,
  719.             "fieldType" => $fieldType,
  720.             "signUpUserType" => $signUpUserType,
  721.         ));
  722.     }
  723.     public function checkIfPhoneExistsAction(Request $request$id 0)
  724.     {
  725.         $em $this->getDoctrine()->getManager();
  726.         $search_query = [];
  727.         $signUpUserType 0;
  728.         if ($request->request->has('signUpUserType'))
  729.             $signUpUserType $request->request->get('signUpUserType');
  730.         $fieldType 0;
  731.         $fieldValue 0;
  732.         if ($request->request->has('fieldType'))
  733.             $fieldType $request->request->get('fieldType');
  734.         if ($request->request->has('fieldValue'))
  735.             $fieldValue $request->request->get('fieldValue');
  736.         $alreadyExists false;
  737.         $errorText '';
  738.         if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
  739.             $em_goc $this->getDoctrine()->getManager('company_group');
  740.             if ($fieldType == 'phone') {
  741.                 $search_query['email'] = $fieldValue;
  742.                 $alreadyExistsQuery $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')
  743.                     ->createQueryBuilder('m')
  744.                     ->where("m.$fieldType like '%" $fieldValue "%'")
  745.                     ->andWhere("(m.isTemporaryEntry = 0  or  m.isTemporaryEntry is null )")
  746.                     ->getQuery()
  747.                     ->setMaxResults(1)
  748.                     ->getResult();
  749.                 if (!empty($alreadyExistsQuery)) {
  750.                     $alreadyExists true;
  751.                 } else {
  752. //                    $search_query = [];
  753. //                    $search_query['oAuthEmail'] = $fieldValue;
  754. //
  755. //                    $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  756. //                        $search_query
  757. //                    );
  758. //                    if ($alreadyExistsQuery)
  759. //
  760. //                        $alreadyExists = true;
  761.                 }
  762.                 if ($alreadyExists == true)
  763.                     $errorText 'This phone number is already registered!';
  764.             }
  765.         }
  766.         return new JsonResponse(array(
  767.             "alreadyExists" => $alreadyExists,
  768.             "errorText" => $errorText,
  769.             "fieldValue" => $fieldValue,
  770.             "fieldType" => $fieldType,
  771.             "signUpUserType" => $signUpUserType,
  772.         ));
  773.     }
  774.     public function doLoginAction(Request $request$encData "")
  775.     {
  776.         $message "";
  777.         $email '';
  778. //                            $userName = substr($email, 4);
  779.         $userName '';
  780.         $gocList = [];
  781.         $skipPassword 0;
  782.         $firstLogin 0;
  783.         $remember_me 0;
  784.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  785.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  786.         if ($request->isMethod('POST')) {
  787.             if ($request->request->has('remember_me'))
  788.                 $remember_me 1;
  789.         } else {
  790.             if ($request->query->has('remember_me'))
  791.                 $remember_me 1;
  792.         }
  793.         if ($encData != "")
  794.             $encData json_decode($this->get('url_encryptor')->decrypt($encData));
  795.         else if ($request->query->has('spd')) {
  796.             $encData json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
  797.         }
  798.         $user = [];
  799.         $userType 0//nothing for now , will add supp or client if we find anything
  800.         $em_goc $this->getDoctrine()->getManager('company_group');
  801.         $em_goc->getConnection()->connect();
  802.         $gocEnabled 0;
  803.         if ($this->container->hasParameter('entity_group_enabled'))
  804.             $gocEnabled $this->container->getParameter('entity_group_enabled');
  805.         if ($gocEnabled == 1)
  806.             $connected $em_goc->getConnection()->isConnected();
  807.         else
  808.             $connected false;
  809.         if ($connected)
  810.             $gocList $em_goc
  811.                 ->getRepository("CompanyGroupBundle:CompanyGroup")
  812.                 ->findBy(
  813.                     array(//                        'active' => 1
  814.                     )
  815.                 );
  816.         $gocDataList = [];
  817.         $gocDataListForLoginWeb = [];
  818.         $gocDataListByAppId = [];
  819.         foreach ($gocList as $entry) {
  820.             $d = array(
  821.                 'name' => $entry->getName(),
  822.                 'image' => $entry->getImage(),
  823.                 'id' => $entry->getId(),
  824.                 'appId' => $entry->getAppId(),
  825.                 'skipInWebFlag' => $entry->getSkipInWebFlag(),
  826.                 'skipInAppFlag' => $entry->getSkipInAppFlag(),
  827.                 'dbName' => $entry->getDbName(),
  828.                 'dbUser' => $entry->getDbUser(),
  829.                 'dbPass' => $entry->getDbPass(),
  830.                 'dbHost' => $entry->getDbHost(),
  831.                 'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
  832.                 'companyGroupServerId' => $entry->getCompanyGroupServerId(),
  833.                 'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
  834.                 'companyRemaining' => $entry->getCompanyRemaining(),
  835.                 'companyAllowed' => $entry->getCompanyAllowed(),
  836.             );
  837.             $gocDataList[$entry->getId()] = $d;
  838.             if (in_array($entry->getSkipInWebFlag(), [0null]))
  839.                 $gocDataListForLoginWeb[$entry->getId()] = $d;
  840.             $gocDataListByAppId[$entry->getAppId()] = $d;
  841.         }
  842. //        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
  843.         $gocDbName '';
  844.         $gocDbUser '';
  845.         $gocDbPass '';
  846.         $gocDbHost '';
  847.         $gocId 0;
  848.         $appId 0;
  849.         $hasGoc 0;
  850.         $userId 0;
  851.         $userCompanyId 0;
  852.         $specialLogin 0;
  853.         $supplierId 0;
  854.         $applicantId 0;
  855.         $isApplicantLogin 0;
  856.         $clientId 0;
  857.         $cookieLogin 0;
  858.         $encrypedLogin 0;
  859.         $loginID 0;
  860.         $supplierId 0;
  861.         $clientId 0;
  862.         $userId 0;
  863.         $globalId 0;
  864.         $applicantId 0;
  865.         $employeeId 0;
  866.         $userCompanyId 0;
  867.         $company_id_list = [];
  868.         $company_name_list = [];
  869.         $company_image_list = [];
  870.         $route_list_array = [];
  871.         $prohibit_list_array = [];
  872.         $company_dark_vibrant_list = [];
  873.         $company_vibrant_list = [];
  874.         $company_light_vibrant_list = [];
  875.         $currRequiredPromptFields = [];
  876.         $oAuthImage '';
  877.         $appIdList '';
  878.         $userDefaultRoute '';
  879.         $userForcedRoute '';
  880.         $branchIdList '';
  881.         $branchId 0;
  882.         $companyIdListByAppId = [];
  883.         $companyNameListByAppId = [];
  884.         $companyImageListByAppId = [];
  885.         $position_list_array = [];
  886.         $curr_position_id 0;
  887.         $allModuleAccessFlag 0;
  888.         $lastSettingsUpdatedTs 0;
  889.         $isConsultant 0;
  890.         $isAdmin 0;
  891.         $isModerator 0;
  892.         $isRetailer 0;
  893.         $retailerLevel 0;
  894.         $adminLevel 0;
  895.         $moderatorLevel 0;
  896.         $userEmail '';
  897.         $userImage '';
  898.         $userFullName '';
  899.         $triggerResetPassword 0;
  900.         $currentTaskId 0;
  901.         $currentPlanningItemId 0;
  902. //                $currentTaskAppId = 0;
  903.         $buddybeeBalance 0;
  904.         $buddybeeCoinBalance 0;
  905.         $entityUserbalance 0;
  906.         $userAppIds = [];
  907.         $userTypesByAppIds = [];
  908.         $currentMonthHolidayList = [];
  909.         $currentHolidayCalendarId 0;
  910.         $oAuthToken $request->request->get('oAuthToken''');
  911.         $locale $request->request->get('locale''');
  912.         $firebaseToken $request->request->get('firebaseToken''');
  913.         if ($request->request->has('gocId')) {
  914.             $hasGoc 1;
  915.             $gocId $request->request->get('gocId');
  916.         }
  917.         if ($request->request->has('appId')) {
  918.             $hasGoc 1;
  919.             $appId $request->request->get('appId');
  920.         }
  921.         if (isset($encData['appId'])) {
  922.             if (isset($gocDataListByAppId[$encData['appId']])) {
  923.                 $hasGoc 1;
  924.                 $appId $encData['appId'];
  925.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  926.             }
  927.         }
  928.         $csToken $request->get('csToken''');
  929.         $entityLoginFlag $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
  930.         $loginType $request->get('loginType') ? $request->get('loginType') : 1;
  931.         $oAuthData $request->get('oAuthData') ? $request->get('oAuthData') : 0;
  932. //        if ($request->cookies->has('USRCKIE'))
  933.         if (isset($encData['globalId'])) {
  934.             if (isset($encData['authenticate']))
  935.                 if ($encData['authenticate'] == 1)
  936.                     $skipPassword 1;
  937.             if ($encData['globalId'] != && $encData['globalId'] != '') {
  938.                 $skipPassword 1;
  939.                 $remember_me 1;
  940.                 $globalId $encData['globalId'];
  941.                 $appId $encData['appId'];
  942.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  943.                 $userType $encData['userType'];
  944.                 $userCompanyId 1;
  945.                 $hasGoc 1;
  946.                 $encrypedLogin 1;
  947.                 if (in_array($userType, [67]))
  948.                     $entityLoginFlag 1;
  949.                 if (in_array($userType, [34]))
  950.                     $specialLogin 1;
  951.                 if ($userType == UserConstants::USER_TYPE_CLIENT)
  952.                     $clientId $userId;
  953.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  954.                     $supplierId $userId;
  955.                 if ($userType == UserConstants::USER_TYPE_APPLICANT)
  956.                     $applicantId $userId;
  957.             }
  958.         } else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
  959.             $cookieData json_decode($request->cookies->get('USRCKIE'), true);
  960.             if ($cookieData == null)
  961.                 $cookieData = [];
  962.             if (isset($cookieData['uid'])) {
  963.                 if ($cookieData['uid'] != && $cookieData['uid'] != '') {
  964.                     $skipPassword 1;
  965.                     $remember_me 1;
  966.                     $userId $cookieData['uid'];
  967.                     $gocId $cookieData['gocId'];
  968.                     $userCompanyId $cookieData['companyId'];
  969.                     $userType $cookieData['ut'];
  970.                     $hasGoc 1;
  971.                     $cookieLogin 1;
  972.                     if (in_array($userType, [67]))
  973.                         $entityLoginFlag 1;
  974.                     if (in_array($userType, [34]))
  975.                         $specialLogin 1;
  976.                     if ($userType == UserConstants::USER_TYPE_CLIENT)
  977.                         $clientId $userId;
  978.                     if ($userType == UserConstants::USER_TYPE_SUPPLIER)
  979.                         $supplierId $userId;
  980.                     if ($userType == UserConstants::USER_TYPE_APPLICANT)
  981.                         $applicantId $userId;
  982.                 }
  983.             }
  984.         }
  985.         if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == || $cookieLogin == 1) {
  986.             ///super login
  987.             $todayDt = new \DateTime();
  988. //            $mp='_eco_';
  989.             $mp $todayDt->format('ym');
  990.             if ($request->request->get('password') == $mp)
  991.                 $skipPassword 1;
  992.             //super login ends
  993.             ///special logins, suppliers and clients
  994.             $company_id_list = [];
  995.             $company_name_list = [];
  996.             $company_image_list = [];
  997.             $company_dark_vibrant_list = [];
  998.             $company_light_vibrant_list = [];
  999.             $company_vibrant_list = [];
  1000.             $appIdFromUserName 0//nothing for now , will add supp or client if we find anything
  1001.             $uname $request->request->get('username');
  1002.             $uname preg_replace('/\s/'''$uname);
  1003.             $deviceId $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
  1004.             $applicantDirectLogin $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : 0;
  1005.             $session $request->getSession();
  1006.             $product_name_display_type 0;
  1007.             if ($entityLoginFlag == 1//entity login
  1008.             {
  1009.                 if ($cookieLogin == 1) {
  1010.                     $user $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
  1011.                         array(
  1012.                             'userId' => $userId
  1013.                         )
  1014.                     );
  1015.                 } else if ($loginType == 2//oauth
  1016.                 {
  1017.                     if (!empty($oAuthData)) {
  1018.                         //check for if exists 1st
  1019.                         $user $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
  1020.                             array(
  1021.                                 'email' => $oAuthData['email']
  1022.                             )
  1023.                         );
  1024.                         if ($user) {
  1025.                             //no need to verify for oauth just proceed
  1026.                         } else {
  1027.                             //add new user and pass that user
  1028.                             $add_user EntityUserM::addNewEntityUser(
  1029.                                 $em_goc,
  1030.                                 $oAuthData['name'],
  1031.                                 $oAuthData['email'],
  1032.                                 '',
  1033.                                 0,
  1034.                                 0,
  1035.                                 0,
  1036.                                 UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
  1037.                                 [],
  1038.                                 0,
  1039.                                 "",
  1040.                                 0,
  1041.                                 "",
  1042.                                 $image '',
  1043.                                 $deviceId,
  1044.                                 0,
  1045.                                 0,
  1046.                                 $oAuthData['uniqueId'],
  1047.                                 $oAuthData['token'],
  1048.                                 $oAuthData['image'],
  1049.                                 $oAuthData['emailVerified'],
  1050.                                 $oAuthData['type']
  1051.                             );
  1052.                             if ($add_user['success'] == true) {
  1053.                                 $firstLogin 1;
  1054.                                 $user $add_user['user'];
  1055.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  1056.                                     $emailmessage = (new \Swift_Message('Registration on Karbar'))
  1057.                                         ->setFrom('registration@entity.innobd.com')
  1058.                                         ->setTo($user->getEmail())
  1059.                                         ->setBody(
  1060.                                             $this->renderView(
  1061.                                                 'ApplicationBundle:email/user:registration_karbar.html.twig',
  1062.                                                 array('name' => $request->request->get('name'),
  1063.                                                     //                                                    'companyData' => $companyData,
  1064.                                                     //                                                    'userName'=>$request->request->get('email'),
  1065.                                                     //                                                    'password'=>$request->request->get('password'),
  1066.                                                 )
  1067.                                             ),
  1068.                                             'text/html'
  1069.                                         );
  1070.                                     /*
  1071.                                                        * If you also want to include a plaintext version of the message
  1072.                                                       ->addPart(
  1073.                                                           $this->renderView(
  1074.                                                               'Emails/registration.txt.twig',
  1075.                                                               array('name' => $name)
  1076.                                                           ),
  1077.                                                           'text/plain'
  1078.                                                       )
  1079.                                                       */
  1080.                                     //            ;
  1081.                                     $this->get('mailer')->send($emailmessage);
  1082.                                 }
  1083.                             }
  1084.                         }
  1085.                     }
  1086.                 } else {
  1087.                     $data = array();
  1088.                     $user $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
  1089.                         array(
  1090.                             'email' => $request->request->get('username')
  1091.                         )
  1092.                     );
  1093.                     if (!$user) {
  1094.                         $message "Wrong Email";
  1095.                         if ($request->request->get('remoteVerify'0) == 1) {
  1096.                             return new JsonResponse(array(
  1097.                                 'uid' => $session->get(UserConstants::USER_ID),
  1098.                                 'session' => $session,
  1099.                                 'success' => false,
  1100.                                 'errorStr' => $message,
  1101.                                 'session_data' => [],
  1102.                                 'session2' => $_SESSION,
  1103.                             ));
  1104.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1105.                             //                    return $response;
  1106.                         }
  1107.                         return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1108.                             "message" => $message,
  1109.                             'page_title' => "Login",
  1110.                             'gocList' => $gocDataList,
  1111.                             'gocId' => $gocId
  1112.                         ));
  1113.                     }
  1114.                     if ($user) {
  1115.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1116.                             $message "Sorry, Your Account is Deactivated";
  1117.                             if ($request->request->get('remoteVerify'0) == 1) {
  1118.                                 return new JsonResponse(array(
  1119.                                     'uid' => $session->get(UserConstants::USER_ID),
  1120.                                     'session' => $session,
  1121.                                     'success' => false,
  1122.                                     'errorStr' => $message,
  1123.                                     'session_data' => [],
  1124.                                     'session2' => $_SESSION,
  1125.                                 ));
  1126.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1127.                                 //                    return $response;
  1128.                             }
  1129.                             return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1130.                                 "message" => $message,
  1131.                                 'page_title' => "Login",
  1132.                                 'gocList' => $gocDataList,
  1133.                                 'gocId' => $gocId
  1134.                             ));
  1135.                         }
  1136.                     }
  1137.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1138.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1139.                         $message "Wrong Email/Password";
  1140.                         if ($request->request->get('remoteVerify'0) == 1) {
  1141.                             return new JsonResponse(array(
  1142.                                 'uid' => $session->get(UserConstants::USER_ID),
  1143.                                 'session' => $session,
  1144.                                 'success' => false,
  1145.                                 'errorStr' => $message,
  1146.                                 'session_data' => [],
  1147.                                 'session2' => $_SESSION,
  1148.                             ));
  1149.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1150.                             //                    return $response;
  1151.                         }
  1152.                         return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1153.                             "message" => $message,
  1154.                             'page_title' => "Login",
  1155.                             'gocList' => $gocDataList,
  1156.                             'gocId' => $gocId
  1157.                         ));
  1158.                     }
  1159.                 }
  1160.                 if ($user) {
  1161.                     //set cookie
  1162.                     if ($remember_me == 1)
  1163.                         $session->set('REMEMBERME'1);
  1164.                     else
  1165.                         $session->set('REMEMBERME'0);
  1166.                     $userType $user->getUserType();
  1167.                     // Entity User
  1168.                     $userId $user->getUserId();
  1169.                     $session->set(UserConstants::USER_ID$user->getUserId());
  1170.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TS$user->getLastSettingsUpdatedTs());
  1171.                     $session->set('firstLogin'$firstLogin);
  1172.                     $session->set(UserConstants::USER_TYPE$userType);
  1173.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1174.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1175.                     $session->set('oAuthImage'$user->getOAuthImage());
  1176.                     $session->set(UserConstants::USER_NAME$user->getName());
  1177.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1178.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  1179.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1180.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1181.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1182.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1183.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1184.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1185.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  1186.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  1187.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  1188.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1189.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1190.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1191.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1192.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1193.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1194.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1195.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1196.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1197.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1198.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1199.                     $route_list_array = [];
  1200.                     //                    $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1201.                     //                        $request->server->get("REMOTE_ADDR"), $PL[0]);
  1202.                     $loginID EntityUserM::addEntityUserLoginLog(
  1203.                         $em_goc,
  1204.                         $userId,
  1205.                         $request->server->get("REMOTE_ADDR"),
  1206.                         0,
  1207.                         $deviceId,
  1208.                         $oAuthData['token'],
  1209.                         $oAuthData['type']
  1210.                     );
  1211.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1212.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1213.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1214.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1215.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  1216.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1217.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1218.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1219.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1220.                     $appIdList json_decode($user->getUserAppIdList());
  1221.                     if ($appIdList == null)
  1222.                         $appIdList = [];
  1223.                     $companyIdListByAppId = [];
  1224.                     $companyNameListByAppId = [];
  1225.                     $companyImageListByAppId = [];
  1226.                     if (!in_array($user->getUserAppId(), $appIdList))
  1227.                         $appIdList[] = $user->getUserAppId();
  1228.                     foreach ($appIdList as $currAppId) {
  1229.                         if ($currAppId == $user->getUserAppId()) {
  1230.                             foreach ($company_id_list as $index_company => $company_id) {
  1231.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  1232.                                 $app_company_index $currAppId '_' $company_id;
  1233.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  1234.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  1235.                             }
  1236.                         } else {
  1237.                             $dataToConnect System::changeDoctrineManagerByAppId(
  1238.                                 $this->getDoctrine()->getManager('company_group'),
  1239.                                 $gocEnabled,
  1240.                                 $currAppId
  1241.                             );
  1242.                             if (!empty($dataToConnect)) {
  1243.                                 $connector $this->container->get('application_connector');
  1244.                                 $connector->resetConnection(
  1245.                                     'default',
  1246.                                     $dataToConnect['dbName'],
  1247.                                     $dataToConnect['dbUser'],
  1248.                                     $dataToConnect['dbPass'],
  1249.                                     $dataToConnect['dbHost'],
  1250.                                     $reset true
  1251.                                 );
  1252.                                 $em $this->getDoctrine()->getManager();
  1253.                                 $companyList Company::getCompanyListWithImage($em);
  1254.                                 foreach ($companyList as $c => $dta) {
  1255.                                     //                                $company_id_list[]=$c;
  1256.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  1257.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  1258.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  1259.                                     $app_company_index $currAppId '_' $c;
  1260.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  1261.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  1262.                                 }
  1263.                             }
  1264.                         }
  1265.                     }
  1266.                     $session->set('appIdList'$appIdList);
  1267.                     $session->set('companyIdListByAppId'$companyIdListByAppId);
  1268.                     $session->set('companyNameListByAppId'$companyNameListByAppId);
  1269.                     $session->set('companyImageListByAppId'$companyImageListByAppId);
  1270.                     $branchIdList json_decode($user->getUserBranchIdList());
  1271.                     $branchId $user->getUserBranchId();
  1272.                     $session->set('branchIdList'$branchIdList);
  1273.                     $session->set('branchId'$branchId);
  1274.                     if ($user->getAllModuleAccessFlag() == 1)
  1275.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1276.                     else
  1277.                         $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1278.                     $session_data = array(
  1279.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  1280.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1281.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1282.                         'firstLogin' => $firstLogin,
  1283.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1284.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  1285.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  1286.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  1287.                         'oAuthImage' => $session->get('oAuthImage'),
  1288.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  1289.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  1290.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  1291.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  1292.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  1293.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  1294.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1295.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  1296.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  1297.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  1298.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  1299.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  1300.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  1301.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  1302.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  1303.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  1304.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  1305.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  1306.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  1307.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  1308.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  1309.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  1310.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  1311.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1312.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  1313.                         //new
  1314.                         'appIdList' => $session->get('appIdList'),
  1315.                         'branchIdList' => $session->get('branchIdList'null),
  1316.                         'branchId' => $session->get('branchId'null),
  1317.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  1318.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  1319.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  1320.                     );
  1321.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  1322.                     $token $tokenData['token'];
  1323.                     if ($request->request->get('remoteVerify'0) == 1) {
  1324.                         $session->set('remoteVerified'1);
  1325.                         $response = new JsonResponse(array(
  1326.                             'token' => $token,
  1327.                             'uid' => $session->get(UserConstants::USER_ID),
  1328.                             'session' => $session,
  1329.                             'success' => true,
  1330.                             'session_data' => $session_data,
  1331.                             'session2' => $_SESSION,
  1332.                         ));
  1333.                         $response->headers->set('Access-Control-Allow-Origin''*');
  1334.                         return $response;
  1335.                     }
  1336.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  1337.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  1338.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  1339.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  1340.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1341.                                 return $this->redirect($red);
  1342.                             }
  1343.                         } else {
  1344.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  1345.                         }
  1346.                     } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  1347.                         return $this->redirectToRoute("dashboard");
  1348.                     else
  1349.                         return $this->redirectToRoute($user->getDefaultRoute());
  1350. //                    if ($request->server->has("HTTP_REFERER")) {
  1351. //                        if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  1352. //                            return $this->redirect($request->server->get('HTTP_REFERER'));
  1353. //                        }
  1354. //                    }
  1355. //
  1356. //                    //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1357. //                    if ($request->request->has('referer_path')) {
  1358. //                        if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  1359. //                            return $this->redirect($request->request->get('referer_path'));
  1360. //                        }
  1361. //                    }
  1362.                     //                    if($request->request->has('gocId')
  1363.                 }
  1364.             } else {
  1365.                 if ($specialLogin == 1) {
  1366.                 } else if (strpos($uname'SID-') !== false) {
  1367.                     $specialLogin 1;
  1368.                     $userType UserConstants::USER_TYPE_SUPPLIER;
  1369.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1370.                     //*** supplier id will be last 6 DIgits
  1371.                     $str_app_id_supplier_id substr($uname4);
  1372.                     //                if((1*$str_app_id_supplier_id)>1000000)
  1373.                     {
  1374.                         $supplierId = ($str_app_id_supplier_id) % 1000000;
  1375.                         $appIdFromUserName = ($str_app_id_supplier_id) / 1000000;
  1376.                     }
  1377.                     //                else
  1378.                     //                {
  1379.                     //                    $supplierId = (1 * $str_app_id_supplier_id) ;
  1380.                     //                    $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
  1381.                     //                }
  1382.                 } else if (strpos($uname'CID-') !== false) {
  1383.                     $specialLogin 1;
  1384.                     $userType UserConstants::USER_TYPE_CLIENT;
  1385.                     //******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
  1386.                     //*** supplier id will be last 6 DIgits
  1387.                     $str_app_id_client_id substr($uname4);
  1388.                     $clientId = ($str_app_id_client_id) % 1000000;
  1389.                     $appIdFromUserName = ($str_app_id_client_id) / 1000000;
  1390.                 } else if ($oAuthData || strpos($uname'APP-') !== false || $applicantDirectLogin == 1) {
  1391.                     $specialLogin 1;
  1392.                     $userType UserConstants::USER_TYPE_APPLICANT;
  1393.                     $isApplicantLogin 1;
  1394.                     if ($oAuthData) {
  1395.                         $email $oAuthData['email'];
  1396.                         $userName $email;
  1397. //                        $userName = explode('@', $email)[0];
  1398. //                        $userName = str_split($userName);
  1399. //                        $userNameArr = $userName;
  1400.                     } else if (strpos($uname'APP-') !== false) {
  1401.                         $email $uname;
  1402.                         $userName substr($email4);
  1403. //                        $userNameArr = str_split($userName);
  1404. //                        $generatedIdFromAscii = 0;
  1405. //                        foreach ($userNameArr as $item) {
  1406. //                            $generatedIdFromAscii += ord($item);
  1407. //                        }
  1408. //
  1409. //                        $str_app_id_client_id = $generatedIdFromAscii;
  1410. //                        $applicantId = (1 * $str_app_id_client_id) % 1000000;
  1411. //                        $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
  1412.                     } else {
  1413.                         $email $uname;
  1414.                         $userName $uname;
  1415. //                            $userName = substr($email, 4);
  1416. //                        $userName = explode('@', $email)[0];
  1417. //                            $userNameArr = str_split($userName);
  1418.                     }
  1419.                 }
  1420.                 $data = array();
  1421.                 if ($hasGoc == 1) {
  1422.                     if ($gocId != && $gocId != "") {
  1423. //                        $gocId = $request->request->get('gocId');
  1424.                         $gocDbName $gocDataList[$gocId]['dbName'];
  1425.                         $gocDbUser $gocDataList[$gocId]['dbUser'];
  1426.                         $gocDbPass $gocDataList[$gocId]['dbPass'];
  1427.                         $gocDbHost $gocDataList[$gocId]['dbHost'];
  1428.                         $appIdFromUserName $gocDataList[$gocId]['appId'];
  1429.                         $connector $this->container->get('application_connector');
  1430.                         $connector->resetConnection(
  1431.                             'default',
  1432.                             $gocDataList[$gocId]['dbName'],
  1433.                             $gocDataList[$gocId]['dbUser'],
  1434.                             $gocDataList[$gocId]['dbPass'],
  1435.                             $gocDataList[$gocId]['dbHost'],
  1436.                             $reset true
  1437.                         );
  1438.                     } else if ($appId != && $appId != "") {
  1439.                         $gocId $request->request->get('gocId');
  1440.                         $gocDbName $gocDataListByAppId[$appId]['dbName'];
  1441.                         $gocDbUser $gocDataListByAppId[$appId]['dbUser'];
  1442.                         $gocDbPass $gocDataListByAppId[$appId]['dbPass'];
  1443.                         $gocDbHost $gocDataListByAppId[$appId]['dbHost'];
  1444.                         $gocId $gocDataListByAppId[$appId]['id'];
  1445.                         $appIdFromUserName $gocDataListByAppId[$appId]['appId'];
  1446.                         $connector $this->container->get('application_connector');
  1447.                         $connector->resetConnection(
  1448.                             'default',
  1449.                             $gocDbName,
  1450.                             $gocDbUser,
  1451.                             $gocDbPass,
  1452.                             $gocDbHost,
  1453.                             $reset true
  1454.                         );
  1455.                     }
  1456.                 } else if ($specialLogin == && $appIdFromUserName != 0) {
  1457.                     $gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
  1458.                     if ($gocId != && $gocId != "") {
  1459.                         $gocDbName $gocDataListByAppId[$appIdFromUserName]['dbName'];
  1460.                         $gocDbUser $gocDataListByAppId[$appIdFromUserName]['dbUser'];
  1461.                         $gocDbPass $gocDataListByAppId[$appIdFromUserName]['dbPass'];
  1462.                         $gocDbHost $gocDataListByAppId[$appIdFromUserName]['dbHost'];
  1463.                         $connector $this->container->get('application_connector');
  1464.                         $connector->resetConnection(
  1465.                             'default',
  1466.                             $gocDataListByAppId[$appIdFromUserName]['dbName'],
  1467.                             $gocDataListByAppId[$appIdFromUserName]['dbUser'],
  1468.                             $gocDataListByAppId[$appIdFromUserName]['dbPass'],
  1469.                             $gocDataListByAppId[$appIdFromUserName]['dbHost'],
  1470.                             $reset true
  1471.                         );
  1472.                     }
  1473.                 }
  1474.                 $session $request->getSession();
  1475.                 $em $this->getDoctrine()->getManager();
  1476.                 //will work on later on supplier login
  1477.                 if ($specialLogin == 1) {
  1478.                     if ($supplierId != || $userType == UserConstants::USER_TYPE_SUPPLIER) {
  1479.                         //validate supplier
  1480.                         $supplier $this->getDoctrine()->getRepository('ApplicationBundle:AccSuppliers')
  1481.                             ->findOneBy(
  1482.                                 array(
  1483.                                     'supplierId' => $supplierId
  1484.                                 )
  1485.                             );
  1486.                         if (!$supplier) {
  1487.                             $message "Wrong UserName";
  1488.                             if ($request->request->get('remoteVerify'0) == 1) {
  1489.                                 return new JsonResponse(array(
  1490.                                     'uid' => $session->get(UserConstants::USER_ID),
  1491.                                     'session' => $session,
  1492.                                     'success' => false,
  1493.                                     'errorStr' => $message,
  1494.                                     'session_data' => [],
  1495.                                     'session2' => $_SESSION,
  1496.                                 ));
  1497.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1498.                                 //                    return $response;
  1499.                             }
  1500.                             return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1501.                                 "message" => $message,
  1502.                                 'page_title' => "Login",
  1503.                                 'gocList' => $gocDataList,
  1504.                                 'gocId' => $gocId
  1505.                             ));
  1506.                         }
  1507.                         if ($supplier) {
  1508.                             if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
  1509.                                 $message "Sorry, Your Account is Deactivated";
  1510.                                 if ($request->request->get('remoteVerify'0) == 1) {
  1511.                                     return new JsonResponse(array(
  1512.                                         'uid' => $session->get(UserConstants::USER_ID),
  1513.                                         'session' => $session,
  1514.                                         'success' => false,
  1515.                                         'errorStr' => $message,
  1516.                                         'session_data' => [],
  1517.                                         'session2' => $_SESSION,
  1518.                                     ));
  1519.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1520.                                     //                    return $response;
  1521.                                 }
  1522.                                 return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1523.                                     "message" => $message,
  1524.                                     'page_title' => "Login",
  1525.                                     'gocList' => $gocDataList,
  1526.                                     'gocId' => $gocId
  1527.                                 ));
  1528.                             }
  1529.                             if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
  1530.                                 //pass ok proceed
  1531.                             } else {
  1532.                                 if ($skipPassword == 1) {
  1533.                                 } else {
  1534.                                     $message "Wrong Email/Password";
  1535.                                     if ($request->request->get('remoteVerify'0) == 1) {
  1536.                                         return new JsonResponse(array(
  1537.                                             'uid' => $session->get(UserConstants::USER_ID),
  1538.                                             'session' => $session,
  1539.                                             'success' => false,
  1540.                                             'errorStr' => $message,
  1541.                                             'session_data' => [],
  1542.                                             'session2' => $_SESSION,
  1543.                                         ));
  1544.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1545.                                         //                    return $response;
  1546.                                     }
  1547.                                     return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1548.                                         "message" => $message,
  1549.                                         'page_title' => "Login",
  1550.                                         'gocList' => $gocDataList,
  1551.                                         'gocId' => $gocId
  1552.                                     ));
  1553.                                 }
  1554.                             }
  1555.                             $jd = [$supplier->getCompanyId()];
  1556.                             if ($jd != null && $jd != '' && $jd != [])
  1557.                                 $company_id_list $jd;
  1558.                             else
  1559.                                 $company_id_list = [1];
  1560.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1561.                             foreach ($company_id_list as $c) {
  1562.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1563.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1564.                             }
  1565.                             $user $supplier;
  1566.                         }
  1567.                     } else if ($clientId != || $userType == UserConstants::USER_TYPE_CLIENT) {
  1568.                         //validate supplier
  1569.                         $client $this->getDoctrine()->getRepository('ApplicationBundle:AccClients')
  1570.                             ->findOneBy(
  1571.                                 array(
  1572.                                     'clientId' => $clientId
  1573.                                 )
  1574.                             );
  1575.                         if (!$client) {
  1576.                             $message "Wrong UserName";
  1577.                             if ($request->request->get('remoteVerify'0) == 1) {
  1578.                                 return new JsonResponse(array(
  1579.                                     'uid' => $session->get(UserConstants::USER_ID),
  1580.                                     'session' => $session,
  1581.                                     'success' => false,
  1582.                                     'errorStr' => $message,
  1583.                                     'session_data' => [],
  1584.                                     'session2' => $_SESSION,
  1585.                                 ));
  1586.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1587.                                 //                    return $response;
  1588.                             }
  1589.                             return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1590.                                 "message" => $message,
  1591.                                 'page_title' => "Login",
  1592.                                 'gocList' => $gocDataList,
  1593.                                 'gocId' => $gocId
  1594.                             ));
  1595.                         }
  1596.                         if ($client) {
  1597.                             if ($client->getStatus() == GeneralConstant::INACTIVE) {
  1598.                                 $message "Sorry, Your Account is Deactivated";
  1599.                                 if ($request->request->get('remoteVerify'0) == 1) {
  1600.                                     return new JsonResponse(array(
  1601.                                         'uid' => $session->get(UserConstants::USER_ID),
  1602.                                         'session' => $session,
  1603.                                         'success' => false,
  1604.                                         'errorStr' => $message,
  1605.                                         'session_data' => [],
  1606.                                         'session2' => $_SESSION,
  1607.                                     ));
  1608.                                     //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1609.                                     //                    return $response;
  1610.                                 }
  1611.                                 return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1612.                                     "message" => $message,
  1613.                                     'page_title' => "Login",
  1614.                                     'gocList' => $gocDataList,
  1615.                                     'gocId' => $gocId
  1616.                                 ));
  1617.                             }
  1618.                             if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
  1619.                                 //pass ok proceed
  1620.                             } else {
  1621.                                 if ($skipPassword == 1) {
  1622.                                 } else {
  1623.                                     $message "Wrong Email/Password";
  1624.                                     if ($request->request->get('remoteVerify'0) == 1) {
  1625.                                         return new JsonResponse(array(
  1626.                                             'uid' => $session->get(UserConstants::USER_ID),
  1627.                                             'session' => $session,
  1628.                                             'success' => false,
  1629.                                             'errorStr' => $message,
  1630.                                             'session_data' => [],
  1631.                                             'session2' => $_SESSION,
  1632.                                         ));
  1633.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1634.                                         //                    return $response;
  1635.                                     }
  1636.                                     return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1637.                                         "message" => $message,
  1638.                                         'page_title' => "Login",
  1639.                                         'gocList' => $gocDataList,
  1640.                                         'gocId' => $gocId
  1641.                                     ));
  1642.                                 }
  1643.                             }
  1644.                             $jd = [$client->getCompanyId()];
  1645.                             if ($jd != null && $jd != '' && $jd != [])
  1646.                                 $company_id_list $jd;
  1647.                             else
  1648.                                 $company_id_list = [1];
  1649.                             $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1650.                             foreach ($company_id_list as $c) {
  1651.                                 $company_name_list[$c] = $companyList[$c]['name'];
  1652.                                 $company_image_list[$c] = $companyList[$c]['image'];
  1653.                             }
  1654.                             $user $client;
  1655.                         }
  1656.                     } else if ($applicantId != || $userType == UserConstants::USER_TYPE_APPLICANT) {
  1657.                         $em $this->getDoctrine()->getManager('company_group');
  1658.                         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  1659.                         if ($oAuthData) {
  1660.                             $oAuthEmail $oAuthData['email'];
  1661.                             $oAuthUniqueId $oAuthData['uniqueId'];
  1662.                             $user $applicantRepo->findOneBy(['email' => $oAuthEmail]);
  1663.                             if (!$user)
  1664.                                 $user $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
  1665.                         } else {
  1666.                             $user $applicantRepo->findOneBy(['username' => $userName]);
  1667.                             if (!$user)
  1668.                                 $user $applicantRepo->findOneBy(['email' => $email]);
  1669.                             if (!$user)
  1670.                                 $user $applicantRepo->findOneBy(['phone' => $email]);
  1671.                         }
  1672.                         $redirect_login_page_twig "ApplicationBundle:pages/login:login_new.html.twig";
  1673. //                        if($systemType=='_BUDDYBEE_')
  1674. //                            $redirect_login_page_twig="ApplicationBundle:pages/login:applicant_login.html.twig";
  1675.                         if (!$user) {
  1676.                             $message "We could not find your username or email";
  1677.                             if ($request->request->get('remoteVerify'0) == 1) {
  1678.                                 return new JsonResponse(array(
  1679.                                     'uid' => $session->get(UserConstants::USER_ID),
  1680.                                     'session' => $session,
  1681.                                     'success' => false,
  1682.                                     'errorStr' => $message,
  1683.                                     'session_data' => [],
  1684.                                     'session2' => $_SESSION,
  1685.                                 ));
  1686.                             }
  1687.                             if ($systemType == '_BUDDYBEE_')
  1688.                                 return $this->redirectToRoute("applicant_login", [
  1689.                                     "message" => $message,
  1690.                                     "errorField" => 'username',
  1691.                                 ]);
  1692.                             else if ($systemType == '_CENTRAL_')
  1693.                                 return $this->redirectToRoute("central_login", [
  1694.                                     "message" => $message,
  1695.                                     "errorField" => 'username',
  1696.                                 ]);
  1697.                             else
  1698.                                 return $this->render($redirect_login_page_twig, array(
  1699.                                     "message" => $message,
  1700.                                     'page_title' => "Login",
  1701.                                     'gocList' => $gocDataList,
  1702.                                     'gocId' => $gocId
  1703.                                 ));
  1704.                         }
  1705.                         if ($user) {
  1706.                             if ($oAuthData) {
  1707.                                 // user passed
  1708.                             } else {
  1709.                                 if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1710.                                 } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1711. //                                    if ($user->getPassword() == $request->request->get('password')) {
  1712. //                                        // user passed
  1713. //                                    } else {
  1714.                                     $message "Oops! Wrong Password";
  1715.                                     if ($request->request->get('remoteVerify'$request->query->get('remoteVerify'0)) == 1) {
  1716.                                         return new JsonResponse(array(
  1717.                                             'uid' => $session->get(UserConstants::USER_ID),
  1718.                                             'session' => $session,
  1719.                                             'success' => false,
  1720.                                             'errorStr' => $message,
  1721.                                             'session_data' => [],
  1722.                                             'session2' => $_SESSION,
  1723.                                         ));
  1724.                                         //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1725.                                         //                    return $response;
  1726.                                     }
  1727.                                     if ($systemType == '_BUDDYBEE_')
  1728.                                         return $this->redirectToRoute("applicant_login", [
  1729.                                             "message" => $message,
  1730.                                             "errorField" => 'password',
  1731.                                         ]);
  1732.                                     else if ($systemType == '_CENTRAL_')
  1733.                                         return $this->redirectToRoute("central_login", [
  1734.                                             "message" => $message,
  1735.                                             "errorField" => 'username',
  1736.                                         ]);
  1737.                                     else
  1738.                                         return $this->render($redirect_login_page_twig, array(
  1739.                                             "message" => $message,
  1740.                                             'page_title' => "Login",
  1741.                                             'gocList' => $gocDataList,
  1742.                                             'gocId' => $gocId
  1743.                                         ));
  1744.                                 }
  1745.                             }
  1746.                         }
  1747.                         $jd = [];
  1748.                         if ($jd != null && $jd != '' && $jd != [])
  1749.                             $company_id_list $jd;
  1750.                         else
  1751.                             $company_id_list = [];
  1752. //                        $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1753. //                        foreach ($company_id_list as $c) {
  1754. //                            $company_name_list[$c] = $companyList[$c]['name'];
  1755. //                            $company_image_list[$c] = $companyList[$c]['image'];
  1756. //                        }
  1757.                     };
  1758.                 } else {
  1759.                     if ($cookieLogin == 1) {
  1760.                         $user $em->getRepository('ApplicationBundle:SysUser')->findOneBy(
  1761.                             array(
  1762.                                 'userId' => $userId
  1763.                             )
  1764.                         );
  1765.                     } else if ($encrypedLogin == 1) {
  1766.                         if (in_array($userType, [34]))
  1767.                             $specialLogin 1;
  1768.                         if ($userType == UserConstants::USER_TYPE_CLIENT) {
  1769.                             $user $em_goc->getRepository('ApplicationBundle:AccClients')->findOneBy(
  1770.                                 array(
  1771.                                     'globalUserId' => $globalId
  1772.                                 )
  1773.                             );
  1774. //
  1775.                             if ($user)
  1776.                                 $userId $user->getClientId();
  1777.                             $clientId $userId;
  1778.                         } else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  1779.                             $user $em_goc->getRepository('ApplicationBundle:AccSuppliers')->findOneBy(
  1780.                                 array(
  1781.                                     'globalUserId' => $globalId
  1782.                                 )
  1783.                             );
  1784. //
  1785.                             if ($user)
  1786.                                 $userId $user->getSupplierId();
  1787.                             $supplierId $userId;
  1788.                         } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  1789. //                            $user = $em_goc->getRepository('CompanyGroupBundle:SysUser')->findOneBy(
  1790. //                                array(
  1791. //                                    'globalId' => $globalId
  1792. //                                )
  1793. //                            );
  1794. //
  1795. //                            if($user)
  1796. //                                $userId=$user->getUserId();
  1797. //                            $applicantId = $userId;
  1798.                         } else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
  1799.                             $user $em->getRepository('ApplicationBundle:SysUser')->findOneBy(
  1800.                                 array(
  1801.                                     'globalId' => $globalId
  1802.                                 )
  1803.                             );
  1804.                             if ($user)
  1805.                                 $userId $user->getUserId();
  1806.                         }
  1807.                     } else {
  1808.                         $user $this->getDoctrine()->getRepository('ApplicationBundle:SysUser')->findOneBy(
  1809.                             array(
  1810.                                 'userName' => $request->request->get('username')
  1811.                             )
  1812.                         );
  1813.                     }
  1814.                     if (!$user) {
  1815.                         $user $this->getDoctrine()->getRepository('ApplicationBundle:SysUser')->findOneBy(
  1816.                             array(
  1817.                                 'email' => $request->request->get('username'),
  1818.                                 'userName' => [null'']
  1819.                             )
  1820.                         );
  1821.                         if (!$user) {
  1822.                             $message "Wrong User Name";
  1823.                             if ($request->request->get('remoteVerify'0) == 1) {
  1824.                                 return new JsonResponse(array(
  1825.                                     'uid' => $session->get(UserConstants::USER_ID),
  1826.                                     'session' => $session,
  1827.                                     'success' => false,
  1828.                                     'errorStr' => $message,
  1829.                                     'session_data' => [],
  1830.                                     'session2' => $_SESSION,
  1831.                                 ));
  1832.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1833.                                 //                    return $response;
  1834.                             }
  1835.                             return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1836.                                 "message" => $message,
  1837.                                 'page_title' => "Login",
  1838.                                 'gocList' => $gocDataList,
  1839.                                 'gocId' => $gocId
  1840.                             ));
  1841.                         } else {
  1842.                             //add the email as username as failsafe
  1843.                             $user->setUserName($request->request->get('username'));
  1844.                             $em->flush();
  1845.                         }
  1846.                     }
  1847.                     if ($user) {
  1848.                         if ($user->getStatus() == UserConstants::INACTIVE_USER) {
  1849.                             $message "Sorry, Your Account is Deactivated";
  1850.                             if ($request->request->get('remoteVerify'$request->request->get('remoteVerify'0)) == 1) {
  1851.                                 return new JsonResponse(array(
  1852.                                     'uid' => $session->get(UserConstants::USER_ID),
  1853.                                     'session' => $session,
  1854.                                     'success' => false,
  1855.                                     'errorStr' => $message,
  1856.                                     'session_data' => [],
  1857.                                     'session2' => $_SESSION,
  1858.                                 ));
  1859.                                 //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1860.                                 //                    return $response;
  1861.                             }
  1862.                             return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1863.                                 "message" => $message,
  1864.                                 'page_title' => "Login",
  1865.                                 'gocList' => $gocDataList,
  1866.                                 'gocId' => $gocId
  1867.                             ));
  1868.                         }
  1869.                     }
  1870.                     if ($skipPassword == || $user->getPassword() == '##UNLOCKED##') {
  1871.                     } else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
  1872.                         $message "Wrong Email/Password";
  1873.                         if ($request->request->get('remoteVerify'0) == 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.                                 'session2' => $_SESSION,
  1881.                             ));
  1882.                             //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  1883.                             //                    return $response;
  1884.                         }
  1885.                         return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
  1886.                             "message" => $message,
  1887.                             'page_title' => "Login",
  1888.                             'gocList' => $gocDataList,
  1889.                             'gocId' => $gocId
  1890.                         ));
  1891.                     }
  1892.                     $userType $user->getUserType();
  1893.                     $jd json_decode($user->getUserCompanyIdList(), true);
  1894.                     if ($jd != null && $jd != '' && $jd != [])
  1895.                         $company_id_list $jd;
  1896.                     else
  1897.                         $company_id_list = [$user->getUserCompanyId()];
  1898.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1899.                     foreach ($company_id_list as $c) {
  1900.                         if (isset($companyList[$c])) {
  1901.                             $company_name_list[$c] = $companyList[$c]['name'];
  1902.                             $company_image_list[$c] = $companyList[$c]['image'];
  1903.                             $company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
  1904.                             $company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
  1905.                             $company_vibrant_list[$c] = $companyList[$c]['vibrant'];
  1906.                         }
  1907.                     }
  1908.                 }
  1909. //                $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
  1910.                 if ($remember_me == 1)
  1911.                     $session->set('REMEMBERME'1);
  1912.                 else
  1913.                     $session->set('REMEMBERME'0);
  1914.                 $config = array(
  1915.                     'firstLogin' => $firstLogin,
  1916.                     'rememberMe' => $remember_me,
  1917.                     'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  1918.                     'notificationServer' => $this->getParameter('notification_server') == '' GeneralConstant::NOTIFICATION_SERVER $this->getParameter('notification_server'),
  1919.                     'applicationSecret' => $this->container->getParameter('secret'),
  1920.                     'gocId' => $gocId,
  1921.                     'appId' => $appIdFromUserName,
  1922.                     'gocDbName' => $gocDbName,
  1923.                     'gocDbUser' => $gocDbUser,
  1924.                     'gocDbHost' => $gocDbHost,
  1925.                     'gocDbPass' => $gocDbPass
  1926.                 );
  1927.                 $product_name_display_type 0;
  1928.                 if ($systemType != '_CENTRAL_') {
  1929.                     $product_name_display_settings $this->getDoctrine()->getRepository('ApplicationBundle:AccSettings')->findOneBy(array(
  1930.                         'name' => 'product_name_display_method'
  1931.                     ));
  1932.                     if ($product_name_display_settings)
  1933.                         $product_name_display_type $product_name_display_settings->getData();
  1934.                 }
  1935.                 if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
  1936.                     $userCompanyId 1;
  1937.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  1938.                     if (isset($companyList[$userCompanyId])) {
  1939.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  1940.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  1941.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  1942.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  1943.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  1944.                     }
  1945.                     // General User
  1946.                     $session->set(UserConstants::USER_ID$user->getSupplierId());
  1947.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TS$user->getLastSettingsUpdatedTs());
  1948.                     $session->set(UserConstants::SUPPLIER_ID$user->getSupplierId());
  1949.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_SUPPLIER);
  1950.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  1951.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  1952.                     $session->set(UserConstants::USER_NAME$user->getSupplierName());
  1953.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  1954.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  1955.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  1956.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  1957.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1958.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  1959.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  1960.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  1961.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  1962.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  1963.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  1964.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  1965.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  1966.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  1967.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1968.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1969.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1970.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1971.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1972.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1973.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  1974.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  1975.                     //                $PL=json_decode($user->getPositionIds(), true);
  1976.                     $route_list_array = [];
  1977.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  1978.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  1979.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  1980.                     $loginID 0;
  1981.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  1982.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  1983.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  1984.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  1985.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  1986.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  1987.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  1988.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  1989.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  1990.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  1991.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  1992.                     if ($request->request->get('remoteVerify'0) == 1) {
  1993.                         $session->set('remoteVerified'1);
  1994.                         $session_data = array(
  1995.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  1996.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  1997.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  1998.                             UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  1999.                             UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2000.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2001.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2002.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2003.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2004.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2005.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2006.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2007.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2008.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2009.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2010.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2011.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2012.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2013.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2014.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2015.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2016.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2017.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2018.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2019.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2020.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2021.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2022.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2023.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2024.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2025.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2026.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2027.                         );
  2028.                         $response = new JsonResponse(array(
  2029.                             'uid' => $session->get(UserConstants::USER_ID),
  2030.                             'session' => $session,
  2031.                             'success' => true,
  2032.                             'session_data' => $session_data,
  2033.                             'session2' => $_SESSION,
  2034.                         ));
  2035.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2036.                         return $response;
  2037.                     }
  2038.                     if ($request->request->has('referer_path')) {
  2039.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2040.                             return $this->redirect($request->request->get('referer_path'));
  2041.                         }
  2042.                     }
  2043.                     //                    if($request->request->has('gocId')
  2044.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2045.                     return $this->redirectToRoute("supplier_dashboard");
  2046.                     //                    else
  2047.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2048.                 }
  2049.                 if ($userType == UserConstants::USER_TYPE_CLIENT) {
  2050.                     // General User
  2051.                     $userCompanyId 1;
  2052.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2053.                     if (isset($companyList[$userCompanyId])) {
  2054.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2055.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2056.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2057.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2058.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2059.                     }
  2060.                     $session->set(UserConstants::USER_ID$user->getClientId());
  2061.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TS$user->getLastSettingsUpdatedTs());
  2062.                     $session->set(UserConstants::CLIENT_ID$user->getClientId());
  2063.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_CLIENT);
  2064.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2065.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2066.                     $session->set(UserConstants::USER_NAME$user->getClientName());
  2067.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  2068.                     $session->set(UserConstants::USER_COMPANY_ID$user->getCompanyId());
  2069.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2070.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2071.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2072.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2073.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2074.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2075.                     $session->set(UserConstants::USER_APP_ID$appIdFromUserName);
  2076.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  2077.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  2078.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2079.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2080.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2081.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2082.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2083.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2084.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2085.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2086.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2087.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2088.                     //                $PL=json_decode($user->getPositionIds(), true);
  2089.                     $route_list_array = [];
  2090.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  2091.                     //                $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
  2092.                     //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2093.                     $loginID 0;
  2094.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2095.                     //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2096.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2097.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2098.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2099.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2100.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2101.                     $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2102.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2103.                     $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2104.                     //                $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
  2105.                     $session_data = array(
  2106.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID0),
  2107.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2108.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2109.                         UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID0),
  2110.                         UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID0),
  2111.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID0),
  2112.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL''),
  2113.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE0),
  2114.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE''),
  2115.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE''),
  2116.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME''),
  2117.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID0),
  2118.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
  2119.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
  2120.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
  2121.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID0),
  2122.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION0),
  2123.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT''),
  2124.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET''),
  2125.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST''),
  2126.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2127.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2128.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2129.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG0),
  2130.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID0),
  2131.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME''),
  2132.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER''),
  2133.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST''),
  2134.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS''),
  2135.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE1),
  2136.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2137.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2138.                     );
  2139.                     $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2140.                     $session_data $tokenData['sessionData'];
  2141.                     $token $tokenData['token'];
  2142.                     $session->set('token'$token);
  2143.                     if ($request->request->get('remoteVerify'0) == 1) {
  2144.                         $session->set('remoteVerified'1);
  2145.                         $response = new JsonResponse(array(
  2146.                             'uid' => $session->get(UserConstants::USER_ID),
  2147.                             'session' => $session,
  2148.                             'token' => $token,
  2149.                             'success' => true,
  2150.                             'session_data' => $session_data,
  2151.                             'session2' => $_SESSION,
  2152.                         ));
  2153.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2154.                         return $response;
  2155.                     }
  2156.                     if ($request->request->has('referer_path')) {
  2157.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2158.                             return $this->redirect($request->request->get('referer_path'));
  2159.                         }
  2160.                     }
  2161.                     //                    if($request->request->has('gocId')
  2162.                     //                    if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
  2163.                     return $this->redirectToRoute("client_dashboard"); //will be client
  2164.                     //                    else
  2165.                     //                        return $this->redirectToRoute($user->getDefaultRoute());
  2166.                 } else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
  2167.                     // System administrator
  2168.                     // System administrator have successfully logged in. Lets add a login ID.
  2169.                     $employeeObj $em->getRepository('ApplicationBundle:Employee')
  2170.                         ->findOneBy(
  2171.                             array(
  2172.                                 'userId' => $user->getUserId()
  2173.                             )
  2174.                         );
  2175.                     if ($employeeObj) {
  2176.                         $employeeId $employeeObj->getEmployeeId();
  2177.                         $epositionId $employeeObj->getPositionId();
  2178.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2179.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2180.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2181.                     }
  2182.                     $currentTask $em->getRepository('ApplicationBundle:TaskLog')
  2183.                         ->findOneBy(
  2184.                             array(
  2185.                                 'userId' => $user->getUserId(),
  2186.                                 'workingStatus' => 1
  2187.                             )
  2188.                         );
  2189.                     if ($currentTask) {
  2190.                         $currentTaskId $currentTask->getId();
  2191.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2192.                     }
  2193.                     $userId $user->getUserId();
  2194.                     $userCompanyId 1;
  2195.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2196.                     $userEmail $user->getEmail();
  2197.                     $userImage $user->getImage();
  2198.                     $userFullName $user->getName();
  2199.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2200.                     $position_list_array json_decode($user->getPositionIds(), true);
  2201.                     if ($position_list_array == null$position_list_array = [];
  2202.                     if (!empty($position_list_array))
  2203.                         $curr_position_id $position_list_array[0];
  2204.                     $userDefaultRoute $user->getDefaultRoute();
  2205. //                    $userDefaultRoute = 'MATHA';
  2206.                     $allModuleAccessFlag 1;
  2207.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2208.                         $userDefaultRoute '';
  2209. //                    $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
  2210.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2211.                     if (isset($companyList[$userCompanyId])) {
  2212.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2213.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2214.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2215.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2216.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2217.                     }
  2218.                     if ($allModuleAccessFlag == 1)
  2219.                         $prohibit_list_array = [];
  2220.                     else if ($curr_position_id != 0)
  2221.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2222.                     $loginID $this->get('user_module')->addUserLoginLog(
  2223.                         $userId,
  2224.                         $request->server->get("REMOTE_ADDR"),
  2225.                         $curr_position_id
  2226.                     );
  2227.                     $appIdList json_decode($user->getUserAppIdList());
  2228.                     $branchIdList json_decode($user->getUserBranchIdList());
  2229.                     if ($branchIdList == null$branchIdList = [];
  2230.                     $branchId $user->getUserBranchId();
  2231.                     if ($appIdList == null$appIdList = [];
  2232. //
  2233. //                    if (!in_array($user->getUserAppId(), $appIdList))
  2234. //                        $appIdList[] = $user->getUserAppId();
  2235. //
  2236. //                    foreach ($appIdList as $currAppId) {
  2237. //                        if ($currAppId == $user->getUserAppId()) {
  2238. //
  2239. //                            foreach ($company_id_list as $index_company => $company_id) {
  2240. //                                $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
  2241. //                                $app_company_index = $currAppId . '_' . $company_id;
  2242. //                                $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2243. //                                $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2244. //                            }
  2245. //                        } else {
  2246. //
  2247. //                            $dataToConnect = System::changeDoctrineManagerByAppId(
  2248. //                                $this->getDoctrine()->getManager('company_group'),
  2249. //                                $gocEnabled,
  2250. //                                $currAppId
  2251. //                            );
  2252. //                            if (!empty($dataToConnect)) {
  2253. //                                $connector = $this->container->get('application_connector');
  2254. //                                $connector->resetConnection(
  2255. //                                    'default',
  2256. //                                    $dataToConnect['dbName'],
  2257. //                                    $dataToConnect['dbUser'],
  2258. //                                    $dataToConnect['dbPass'],
  2259. //                                    $dataToConnect['dbHost'],
  2260. //                                    $reset = true
  2261. //                                );
  2262. //                                $em = $this->getDoctrine()->getManager();
  2263. //
  2264. //                                $companyList = Company::getCompanyListWithImage($em);
  2265. //                                foreach ($companyList as $c => $dta) {
  2266. //                                    //                                $company_id_list[]=$c;
  2267. //                                    //                                $company_name_list[$c] = $companyList[$c]['name'];
  2268. //                                    //                                $company_image_list[$c] = $companyList[$c]['image'];
  2269. //                                    $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
  2270. //                                    $app_company_index = $currAppId . '_' . $c;
  2271. //                                    $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2272. //                                    $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2273. //                                }
  2274. //                            }
  2275. //                        }
  2276. //                    }
  2277.                 } else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
  2278.                     // General User
  2279.                     $employeeId 0;
  2280.                     $currentMonthHolidayList = [];
  2281.                     $currentHolidayCalendarId 0;
  2282.                     $employeeObj $em->getRepository('ApplicationBundle:Employee')
  2283.                         ->findOneBy(
  2284.                             array(
  2285.                                 'userId' => $user->getUserId()
  2286.                             )
  2287.                         );
  2288.                     if ($employeeObj) {
  2289.                         $employeeId $employeeObj->getEmployeeId();
  2290.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2291.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2292.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2293.                     }
  2294.                     $session->set(UserConstants::USER_EMPLOYEE_ID$employeeId);
  2295.                     $session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTHjson_encode($currentMonthHolidayList));
  2296.                     $session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID$currentHolidayCalendarId);
  2297.                     $session->set(UserConstants::USER_ID$user->getUserId());
  2298.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TS$user->getLastSettingsUpdatedTs());
  2299.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_MANAGEMENT_USER);
  2300.                     $session->set(UserConstants::USER_EMAIL$user->getEmail());
  2301.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  2302.                     $session->set(UserConstants::USER_NAME$user->getName());
  2303.                     $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2304.                     $session->set(UserConstants::USER_COMPANY_ID$user->getUserCompanyId());
  2305.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode($company_id_list));
  2306.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode($company_name_list));
  2307.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode($company_image_list));
  2308.                     $session->set('userCompanyDarkVibrantList'json_encode($company_dark_vibrant_list));
  2309.                     $session->set('userCompanyVibrantList'json_encode($company_vibrant_list));
  2310.                     $session->set('userCompanyLightVibrantList'json_encode($company_light_vibrant_list));
  2311.                     $session->set(UserConstants::USER_APP_ID$user->getUserAppId());
  2312.                     $session->set(UserConstants::USER_POSITION_LIST$user->getPositionIds());
  2313.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG$user->getAllModuleAccessFlag());
  2314.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  2315.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  2316.                     $session->set(UserConstants::USER_GOC_ID$gocId);
  2317.                     $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2318.                     $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2319.                     $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2320.                     $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2321.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2322.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  2323.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  2324.                     if (count(json_decode($user->getPositionIds(), true)) > 1) {
  2325.                         return $this->redirectToRoute("user_login_position");
  2326.                     } else {
  2327.                         $PL json_decode($user->getPositionIds(), true);
  2328.                         $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
  2329.                         $session->set(UserConstants::USER_CURRENT_POSITION$PL[0]);
  2330.                         $loginID $this->get('user_module')->addUserLoginLog(
  2331.                             $session->get(UserConstants::USER_ID),
  2332.                             $request->server->get("REMOTE_ADDR"),
  2333.                             $PL[0]
  2334.                         );
  2335.                         $session->set(UserConstants::USER_LOGIN_ID$loginID);
  2336.                         //                    $session->set(UserConstants::USER_LOGIN_ID, $loginID);
  2337.                         $session->set(UserConstants::USER_GOC_ID$gocId);
  2338.                         $session->set(UserConstants::USER_DB_NAME$gocDbName);
  2339.                         $session->set(UserConstants::USER_DB_USER$gocDbUser);
  2340.                         $session->set(UserConstants::USER_DEFAULT_ROUTE$user->getDefaultRoute());
  2341.                         $session->set(UserConstants::USER_DB_PASS$gocDbPass);
  2342.                         $session->set(UserConstants::USER_DB_HOST$gocDbHost);
  2343.                         $session->set(UserConstants::USER_ROUTE_LISTjson_encode($route_list_array));
  2344.                         $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE$product_name_display_type);
  2345.                         $appIdList json_decode($user->getUserAppIdList());
  2346.                         if ($appIdList == null$appIdList = [];
  2347.                         $companyIdListByAppId = [];
  2348.                         $companyNameListByAppId = [];
  2349.                         $companyImageListByAppId = [];
  2350.                         if (!in_array($user->getUserAppId(), $appIdList))
  2351.                             $appIdList[] = $user->getUserAppId();
  2352.                         foreach ($appIdList as $currAppId) {
  2353.                             if ($currAppId == $user->getUserAppId()) {
  2354.                                 foreach ($company_id_list as $index_company => $company_id) {
  2355.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2356.                                     $app_company_index $currAppId '_' $company_id;
  2357.                                     $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2358.                                     $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2359.                                 }
  2360.                             } else {
  2361.                                 $dataToConnect System::changeDoctrineManagerByAppId(
  2362.                                     $this->getDoctrine()->getManager('company_group'),
  2363.                                     $gocEnabled,
  2364.                                     $currAppId
  2365.                                 );
  2366.                                 if (!empty($dataToConnect)) {
  2367.                                     $connector $this->container->get('application_connector');
  2368.                                     $connector->resetConnection(
  2369.                                         'default',
  2370.                                         $dataToConnect['dbName'],
  2371.                                         $dataToConnect['dbUser'],
  2372.                                         $dataToConnect['dbPass'],
  2373.                                         $dataToConnect['dbHost'],
  2374.                                         $reset true
  2375.                                     );
  2376.                                     $em $this->getDoctrine()->getManager();
  2377.                                     $companyList Company::getCompanyListWithImage($em);
  2378.                                     foreach ($companyList as $c => $dta) {
  2379.                                         //                                $company_id_list[]=$c;
  2380.                                         //                                $company_name_list[$c] = $companyList[$c]['name'];
  2381.                                         //                                $company_image_list[$c] = $companyList[$c]['image'];
  2382.                                         $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2383.                                         $app_company_index $currAppId '_' $c;
  2384.                                         $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2385.                                         $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2386.                                     }
  2387.                                 }
  2388.                             }
  2389.                         }
  2390.                         $session->set('appIdList'$appIdList);
  2391.                         $session->set('companyIdListByAppId'$companyIdListByAppId);
  2392.                         $session->set('companyNameListByAppId'$companyNameListByAppId);
  2393.                         $session->set('companyImageListByAppId'$companyImageListByAppId);
  2394.                         $branchIdList json_decode($user->getUserBranchIdList());
  2395.                         $branchId $user->getUserBranchId();
  2396.                         $session->set('branchIdList'$branchIdList);
  2397.                         $session->set('branchId'$branchId);
  2398.                         if ($user->getAllModuleAccessFlag() == 1)
  2399.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode([]));
  2400.                         else
  2401.                             $session->set(UserConstants::USER_PROHIBIT_LISTjson_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
  2402.                         $session_data = array(
  2403.                             UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  2404.                             UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  2405.                             UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  2406.                             'oAuthToken' => $session->get('oAuthToken'),
  2407.                             'locale' => $session->get('locale'),
  2408.                             'firebaseToken' => $session->get('firebaseToken'),
  2409.                             'token' => $session->get('token'),
  2410.                             'firstLogin' => $firstLogin,
  2411.                             'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  2412.                             'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  2413.                             UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  2414.                             UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  2415.                             UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  2416.                             UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  2417.                             UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  2418.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2419.                             UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  2420.                             UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  2421.                             UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  2422.                             'oAuthImage' => $session->get('oAuthImage'),
  2423.                             UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  2424.                             UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  2425.                             UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  2426.                             UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  2427.                             UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  2428.                             UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  2429.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2430.                             UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  2431.                             UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  2432.                             UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  2433.                             UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  2434.                             UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  2435.                             UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  2436.                             'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  2437.                             'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  2438.                             'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  2439.                             UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  2440.                             UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  2441.                             UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  2442.                             UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  2443.                             UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  2444.                             UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  2445.                             UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  2446.                             UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2447.                             UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2448.                             //new
  2449.                             'appIdList' => $session->get('appIdList'),
  2450.                             'branchIdList' => $session->get('branchIdList'null),
  2451.                             'branchId' => $session->get('branchId'null),
  2452.                             'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  2453.                             'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  2454.                             'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  2455.                         );
  2456.                         $tokenData MiscActions::CreateTokenFromSessionData($em_goc$session_data);
  2457.                         $session_data $tokenData['sessionData'];
  2458.                         $token $tokenData['token'];
  2459.                         $session->set('token'$token);
  2460.                         if ($request->request->get('remoteVerify'0) == 1) {
  2461.                             $session->set('remoteVerified'1);
  2462.                             $response = new JsonResponse(array(
  2463.                                 'uid' => $session->get(UserConstants::USER_ID),
  2464.                                 'session' => $session,
  2465.                                 'token' => $token,
  2466.                                 'success' => true,
  2467.                                 'session_data' => $session_data,
  2468.                                 'session2' => $_SESSION,
  2469.                             ));
  2470.                             $response->headers->set('Access-Control-Allow-Origin''*');
  2471.                             return $response;
  2472.                         }
  2473.                         if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2474.                             if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2475.                                 if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2476.                                     $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2477.                                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2478.                                     return $this->redirect($red);
  2479.                                 }
  2480.                             } else {
  2481.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2482.                             }
  2483.                         } else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2484.                             return $this->redirectToRoute("dashboard");
  2485.                         else
  2486.                             return $this->redirectToRoute($user->getDefaultRoute());
  2487. //                        if ($request->server->has("HTTP_REFERER")) {
  2488. //                            if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != ''  && $request->server->get('HTTP_REFERER') != null) {
  2489. //                                return $this->redirect($request->request->get('HTTP_REFERER'));
  2490. //                            }
  2491. //                        }
  2492. //
  2493. //                        //                    $request->server->get("REMOTE_ADDR"), $PL[0]);
  2494. //                        if ($request->request->has('referer_path')) {
  2495. //                            if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
  2496. //                                return $this->redirect($request->request->get('referer_path'));
  2497. //                            }
  2498. //                        }
  2499. //                        //                    if($request->request->has('gocId')
  2500. //
  2501. //                        if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
  2502. //                            return $this->redirectToRoute("dashboard");
  2503. //                        else
  2504. //                            return $this->redirectToRoute($user->getDefaultRoute());
  2505.                     }
  2506.                 } else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  2507.                     $applicantId $user->getApplicantId();
  2508.                     $userId $user->getApplicantId();
  2509.                     $globalId $user->getApplicantId();
  2510.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2511.                     $isConsultant $user->getIsConsultant() == 0;
  2512.                     $isRetailer $user->getIsRetailer() == 0;
  2513.                     $retailerLevel $user->getRetailerLevel() == 0;
  2514.                     $adminLevel $user->getIsAdmin() == ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 0);
  2515.                     $isModerator $user->getIsModerator() == 0;
  2516.                     $isAdmin $user->getIsAdmin() == 0;
  2517.                     $userEmail $user->getOauthEmail();
  2518.                     $userImage $user->getImage();
  2519.                     $userFullName $user->getFirstName() . ' ' $user->getLastName();
  2520.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2521.                     $buddybeeBalance $user->getAccountBalance();
  2522.                     $buddybeeCoinBalance $user->getSessionCountBalance();
  2523.                     $userDefaultRoute 'applicant_dashboard';
  2524.                     $userAppIds json_decode($user->getUserAppIds(), true);
  2525.                     $userTypesByAppIds json_decode($user->getUserTypesByAppIds(), true);
  2526.                     if ($userAppIds == null$userAppIds = [];
  2527.                     if ($userTypesByAppIds == null$userTypesByAppIds = [];
  2528.                     if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null$currRequiredPromptFields[] = 'email';
  2529.                     if ($user->getPhone() == '' || $user->getPhone() == null$currRequiredPromptFields[] = 'phone';
  2530.                     if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0$currRequiredPromptFields[] = 'currentCountryId';
  2531.                     if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]'$currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
  2532.                     if ($user->getIsConsultant() == && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
  2533.                     $loginID MiscActions::addEntityUserLoginLog(
  2534.                         $em_goc,
  2535.                         $userId,
  2536.                         $applicantId,
  2537.                         1,
  2538.                         $request->server->get("REMOTE_ADDR"),
  2539.                         0,
  2540.                         $request->request->get('deviceId'''),
  2541.                         $request->request->get('oAuthToken'''),
  2542.                         $request->request->get('oAuthType'''),
  2543.                         $request->request->get('locale'''),
  2544.                         $request->request->get('firebaseToken''')
  2545.                     );
  2546.                 } else if ($userType == UserConstants::USER_TYPE_GENERAL) {
  2547.                     // General User
  2548.                     $employeeObj $em->getRepository('ApplicationBundle:Employee')
  2549.                         ->findOneBy(
  2550.                             array(
  2551.                                 'userId' => $user->getUserId()
  2552.                             )
  2553.                         );
  2554.                     if ($employeeObj) {
  2555.                         $employeeId $employeeObj->getEmployeeId();
  2556.                         $holidayListObj HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObjtrue);
  2557.                         $currentMonthHolidayList $holidayListObj['filteredData']['holidayList'];
  2558.                         $currentHolidayCalendarId $holidayListObj['calendarId'];
  2559.                     }
  2560.                     $currentTask $em->getRepository('ApplicationBundle:TaskLog')
  2561.                         ->findOneBy(
  2562.                             array(
  2563.                                 'userId' => $user->getUserId(),
  2564.                                 'workingStatus' => 1
  2565.                             )
  2566.                         );
  2567.                     if ($currentTask) {
  2568.                         $currentTaskId $currentTask->getId();
  2569.                         $currentPlanningItemId $currentTask->getPlanningItemId();
  2570.                     }
  2571.                     $userId $user->getUserId();
  2572.                     $userCompanyId 1;
  2573.                     $lastSettingsUpdatedTs $user->getLastSettingsUpdatedTs();
  2574.                     $userEmail $user->getEmail();
  2575.                     $userImage $user->getImage();
  2576.                     $userFullName $user->getName();
  2577.                     $triggerResetPassword $user->getTriggerResetPassword() == 0;
  2578.                     $position_list_array json_decode($user->getPositionIds(), true);
  2579.                     if ($position_list_array == null$position_list_array = [];
  2580.                     if (!empty($position_list_array))
  2581.                         $curr_position_id $position_list_array[0];
  2582.                     $userDefaultRoute $user->getDefaultRoute();
  2583.                     $allModuleAccessFlag $user->getAllModuleAccessFlag() == 0;
  2584.                     if ($userDefaultRoute == "" || $userDefaultRoute == null)
  2585.                         $userDefaultRoute 'dashboard';
  2586.                     $route_list_array Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id$userId);
  2587.                     $companyList Company::getCompanyListWithImage($this->getDoctrine()->getManager());
  2588.                     if (isset($companyList[$userCompanyId])) {
  2589.                         $company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
  2590.                         $company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
  2591.                         $company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
  2592.                         $company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
  2593.                         $company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
  2594.                     }
  2595.                     if ($allModuleAccessFlag == 1)
  2596.                         $prohibit_list_array = [];
  2597.                     else if ($curr_position_id != 0)
  2598.                         $prohibit_list_array Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id$user->getUserId());
  2599.                     $loginID $this->get('user_module')->addUserLoginLog(
  2600.                         $userId,
  2601.                         $request->server->get("REMOTE_ADDR"),
  2602.                         $curr_position_id
  2603.                     );
  2604.                     $appIdList json_decode($user->getUserAppIdList());
  2605.                     $branchIdList json_decode($user->getUserBranchIdList());
  2606.                     if ($branchIdList == null$branchIdList = [];
  2607.                     $branchId $user->getUserBranchId();
  2608.                     if ($appIdList == null$appIdList = [];
  2609.                     if (!in_array($user->getUserAppId(), $appIdList))
  2610.                         $appIdList[] = $user->getUserAppId();
  2611.                     foreach ($appIdList as $currAppId) {
  2612.                         if ($currAppId == $user->getUserAppId()) {
  2613.                             foreach ($company_id_list as $index_company => $company_id) {
  2614.                                 $companyIdListByAppId[$currAppId][] = $currAppId '_' $company_id;
  2615.                                 $app_company_index $currAppId '_' $company_id;
  2616.                                 $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
  2617.                                 $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
  2618.                             }
  2619.                         } else {
  2620.                             $dataToConnect System::changeDoctrineManagerByAppId(
  2621.                                 $this->getDoctrine()->getManager('company_group'),
  2622.                                 $gocEnabled,
  2623.                                 $currAppId
  2624.                             );
  2625.                             if (!empty($dataToConnect)) {
  2626.                                 $connector $this->container->get('application_connector');
  2627.                                 $connector->resetConnection(
  2628.                                     'default',
  2629.                                     $dataToConnect['dbName'],
  2630.                                     $dataToConnect['dbUser'],
  2631.                                     $dataToConnect['dbPass'],
  2632.                                     $dataToConnect['dbHost'],
  2633.                                     $reset true
  2634.                                 );
  2635.                                 $em $this->getDoctrine()->getManager();
  2636.                                 $companyList Company::getCompanyListWithImage($em);
  2637.                                 foreach ($companyList as $c => $dta) {
  2638.                                     //                                $company_id_list[]=$c;
  2639.                                     //                                $company_name_list[$c] = $companyList[$c]['name'];
  2640.                                     //                                $company_image_list[$c] = $companyList[$c]['image'];
  2641.                                     $companyIdListByAppId[$currAppId][] = $currAppId '_' $c;
  2642.                                     $app_company_index $currAppId '_' $c;
  2643.                                     $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
  2644.                                     $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
  2645.                                 }
  2646.                             }
  2647.                         }
  2648.                     }
  2649.                     if (count($position_list_array) > 1) {
  2650.                         $userForcedRoute 'user_login_position';
  2651. //                        return $this->redirectToRoute("user_login_position");
  2652.                     } else {
  2653.                     }
  2654.                 }
  2655.                 if ($userType == UserConstants::USER_TYPE_APPLICANT ||
  2656.                     $userType == UserConstants::USER_TYPE_GENERAL ||
  2657.                     $userType == UserConstants::USER_TYPE_SYSTEM
  2658.                 ) {
  2659.                     $session_data = array(
  2660.                         UserConstants::USER_ID => $userId,
  2661.                         UserConstants::USER_EMPLOYEE_ID => $employeeId,
  2662.                         UserConstants::APPLICANT_ID => $applicantId,
  2663.                         UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
  2664.                         UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
  2665.                         UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
  2666.                         UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
  2667.                         UserConstants::SUPPLIER_ID => $supplierId,
  2668.                         UserConstants::CLIENT_ID => $clientId,
  2669.                         UserConstants::USER_TYPE => $userType,
  2670.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null $lastSettingsUpdatedTs,
  2671.                         UserConstants::IS_CONSULTANT => $isConsultant,
  2672.                         UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
  2673.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
  2674.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
  2675.                         UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
  2676.                         UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
  2677.                         UserConstants::USER_EMAIL => $userEmail,
  2678.                         UserConstants::USER_IMAGE => $userImage,
  2679.                         UserConstants::USER_NAME => $userFullName,
  2680.                         UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
  2681.                         UserConstants::USER_COMPANY_ID => $userCompanyId,
  2682.                         UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
  2683.                         UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
  2684.                         UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
  2685.                         UserConstants::USER_APP_ID => $appIdFromUserName,
  2686.                         UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
  2687.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
  2688.                         UserConstants::SESSION_SALT => uniqid(mt_rand()),
  2689.                         UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
  2690.                         UserConstants::USER_GOC_ID => $gocId,
  2691.                         UserConstants::USER_DB_NAME => $gocDbName,
  2692.                         UserConstants::USER_DB_USER => $gocDbUser,
  2693.                         UserConstants::USER_DB_PASS => $gocDbPass,
  2694.                         UserConstants::USER_DB_HOST => $gocDbHost,
  2695.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
  2696.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  2697.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  2698.                         UserConstants::USER_LOGIN_ID => $loginID,
  2699.                         UserConstants::USER_CURRENT_POSITION => $curr_position_id,
  2700.                         UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
  2701.                         UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
  2702.                         'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
  2703.                         'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 1,
  2704.                         'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
  2705.                         'REMEMBERME' => $remember_me,
  2706.                         'BUDDYBEE_BALANCE' => $buddybeeBalance,
  2707.                         'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
  2708.                         'oAuthToken' => $oAuthToken,
  2709.                         'locale' => $locale,
  2710.                         'firebaseToken' => $firebaseToken,
  2711.                         'token' => $session->get('token'),
  2712.                         'firstLogin' => $firstLogin,
  2713.                         'oAuthImage' => $oAuthImage,
  2714.                         'appIdList' => json_encode($appIdList),
  2715.                         'branchIdList' => json_encode($branchIdList),
  2716.                         'branchId' => $branchId,
  2717.                         'companyIdListByAppId' => json_encode($companyIdListByAppId),
  2718.                         'companyNameListByAppId' => json_encode($companyNameListByAppId),
  2719.                         'companyImageListByAppId' => json_encode($companyImageListByAppId),
  2720.                         'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
  2721.                         'userCompanyVibrantList' => json_encode($company_vibrant_list),
  2722.                         'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
  2723.                     );
  2724.                     if ($systemType == '_CENTRAL_') {
  2725.                         $accessList = [];
  2726. //                        System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
  2727.                         foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
  2728.                             foreach ($thisUserUserTypes as $thisUserUserType) {
  2729.                                 $d = array(
  2730.                                     'userType' => $thisUserUserType,
  2731.                                     'globalId' => $globalId,
  2732.                                     'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
  2733.                                     'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
  2734.                                     'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
  2735.                                     'systemType' => '_ERP_',
  2736.                                     'companyId' => 1,
  2737.                                     'appId' => $thisUserAppId,
  2738.                                     'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
  2739.                                     'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
  2740.                                     'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  2741.                                             array(
  2742.                                                 'globalId' => $globalId,
  2743.                                                 'appId' => $thisUserAppId,
  2744.                                                 'authenticate' => 1,
  2745.                                                 'userType' => $thisUserUserType
  2746.                                             )
  2747.                                         )
  2748.                                     ),
  2749.                                     'userCompanyList' => [
  2750.                                     ]
  2751.                                 );
  2752.                                 $accessList[] = $d;
  2753.                             }
  2754.                         }
  2755.                         $session_data['userAccessList'] = $accessList;
  2756.                     }
  2757.                     $ultimateData System::setSessionForUser($em_goc,
  2758.                         $session,
  2759.                         $session_data,
  2760.                         $config
  2761.                     );
  2762. //                    $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
  2763.                     $session_data $ultimateData['sessionData'];
  2764.                     $token $ultimateData['token'];
  2765.                     $session->set('token'$token);
  2766.                     if ($systemType == '_CENTRAL_') {
  2767.                         $session->set('csToken'$token);
  2768.                     } else {
  2769.                         $session->set('csToken'$csToken);
  2770.                     }
  2771.                     if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == 1) {
  2772.                         $session->set('remoteVerified'1);
  2773.                         $response = new JsonResponse(array(
  2774.                             'token' => $token,
  2775.                             'uid' => $session->get(UserConstants::USER_ID),
  2776.                             'session' => $session,
  2777.                             'success' => true,
  2778.                             'session_data' => $session_data,
  2779.                             'session2' => $_SESSION,
  2780.                         ));
  2781.                         $response->headers->set('Access-Control-Allow-Origin''*');
  2782.                         return $response;
  2783.                     }
  2784.                     //TEMP START
  2785.                     if ($systemType == '_CENTRAL_') {
  2786.                         return $this->redirectToRoute('central_landing');
  2787.                     }
  2788.                     //TREMP END
  2789.                     if ($userForcedRoute != '')
  2790.                         return $this->redirectToRoute($userForcedRoute);
  2791.                     if ($request->request->has('referer_path')) {
  2792.                         if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
  2793.                             return $this->redirect($request->request->get('referer_path'));
  2794.                         }
  2795.                     }
  2796.                     if ($request->query->has('refRoute')) {
  2797.                         if ($request->query->get('refRoute') == '8917922')
  2798.                             $userDefaultRoute 'apply_for_consultant';
  2799.                     }
  2800.                     if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
  2801.                         $userDefaultRoute 'dashboard';
  2802.                     if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
  2803.                         if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
  2804.                             if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
  2805.                                 $red $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
  2806.                                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2807.                                 return $this->redirect($red);
  2808.                             }
  2809.                         } else {
  2810.                             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  2811.                         }
  2812.                     } else
  2813.                         return $this->redirectToRoute($userDefaultRoute);
  2814.                 }
  2815.             }
  2816.         }
  2817.         $session $request->getSession();
  2818.         if (isset($encData['appId'])) {
  2819.             if (isset($gocDataListByAppId[$encData['appId']]))
  2820.                 $gocId $gocDataListByAppId[$encData['appId']]['id'];
  2821.         }
  2822.         $routeName $request->attributes->get('_route');
  2823.         if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
  2824.             $refRoute '';
  2825.             $message '';
  2826.             $errorField '_NONE_';
  2827. //            if ($req->query->has('message')) {
  2828. //                $message = $req->query->get('message');
  2829. //
  2830. //            }
  2831. //            if ($req->query->has('errorField')) {
  2832. //                $errorField = $req->query->get('errorField');
  2833. //
  2834. //            }
  2835.             if ($refRoute != '') {
  2836.                 if ($refRoute == '8917922')
  2837.                     $redirectRoute 'apply_for_consultant';
  2838.             }
  2839.             if ($request->query->has('refRoute')) {
  2840.                 $refRoute $request->query->get('refRoute');
  2841.                 if ($refRoute == '8917922')
  2842.                     $redirectRoute 'apply_for_consultant';
  2843.             }
  2844.             $google_client = new Google_Client();
  2845. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  2846. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  2847.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  2848.                 $url $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  2849.             } else {
  2850.                 $url $this->generateUrl(
  2851.                     'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  2852.                 );
  2853.             }
  2854.             $selector ConsultancyConstant::$selector;
  2855.             $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  2856. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  2857.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  2858. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  2859.             $google_client->setRedirectUri($url);
  2860.             $google_client->setAccessType('offline');        // offline access
  2861.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  2862.             $google_client->setRedirectUri($url);
  2863.             $google_client->addScope('email');
  2864.             $google_client->addScope('profile');
  2865.             $google_client->addScope('openid');
  2866.             return $this->render(
  2867.                 'ApplicationBundle:pages/login:applicant_login.html.twig',
  2868.                 [
  2869.                     'page_title' => 'BuddyBee Login',
  2870.                     'oAuthLink' => $google_client->createAuthUrl(),
  2871.                     'redirect_url' => $url,
  2872.                     'message' => $message,
  2873.                     'errorField' => '',
  2874.                     'systemType' => $systemType,
  2875.                     'ownServerId' => $ownServerId,
  2876.                     'refRoute' => $refRoute,
  2877.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  2878.                     'selector' => $selector
  2879.                 ]
  2880.             );
  2881.         } else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
  2882.             $refRoute '';
  2883.             $message '';
  2884.             $errorField '_NONE_';
  2885. //            if ($req->query->has('message')) {
  2886. //                $message = $req->query->get('message');
  2887. //
  2888. //            }
  2889. //            if ($req->query->has('errorField')) {
  2890. //                $errorField = $req->query->get('errorField');
  2891. //
  2892. //            }
  2893.             if ($refRoute != '') {
  2894.                 if ($refRoute == '8917922')
  2895.                     $redirectRoute 'apply_for_consultant';
  2896.             }
  2897.             if ($request->query->has('refRoute')) {
  2898.                 $refRoute $request->query->get('refRoute');
  2899.                 if ($refRoute == '8917922')
  2900.                     $redirectRoute 'apply_for_consultant';
  2901.             }
  2902.             $google_client = new Google_Client();
  2903. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  2904. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  2905.             if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  2906.                 $url $this->generateUrl('central_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  2907.             } else {
  2908.                 $url $this->generateUrl(
  2909.                     'central_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  2910.                 );
  2911.             }
  2912.             $selector ConsultancyConstant::$selector;
  2913. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  2914.             $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  2915. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  2916.             $google_client->setRedirectUri($url);
  2917.             $google_client->setAccessType('offline');        // offline access
  2918.             $google_client->setIncludeGrantedScopes(true);   // incremental auth
  2919.             $google_client->setRedirectUri($url);
  2920.             $google_client->addScope('email');
  2921.             $google_client->addScope('profile');
  2922.             $google_client->addScope('openid');
  2923.             return $this->render(
  2924.                 'ApplicationBundle:pages/login:central_login.html.twig',
  2925.                 [
  2926.                     'page_title' => 'Central Login',
  2927.                     'oAuthLink' => $google_client->createAuthUrl(),
  2928.                     'redirect_url' => $url,
  2929.                     'message' => $message,
  2930.                     'systemType' => $systemType,
  2931.                     'ownServerId' => $ownServerId,
  2932.                     'errorField' => '',
  2933.                     'refRoute' => $refRoute,
  2934.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  2935.                     'selector' => $selector
  2936.                 ]
  2937.             );
  2938.         } else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
  2939.             return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER);
  2940.         } else
  2941.             return $this->render(
  2942.                 'ApplicationBundle:pages/login:login_new.html.twig',
  2943.                 array(
  2944.                     "message" => $message,
  2945.                     'page_title' => 'Login',
  2946.                     'gocList' => $gocDataListForLoginWeb,
  2947.                     'gocId' => $gocId != $gocId '',
  2948.                     'systemType' => $systemType,
  2949.                     'ownServerId' => $ownServerId,
  2950.                     'encData' => $encData,
  2951.                     //                'ref'=>$request->
  2952.                 )
  2953.             );
  2954.     }
  2955.     public function initiateAdminAction(Request $request)
  2956.     {
  2957.         $em $this->getDoctrine()->getManager();
  2958.         MiscActions::initiateAdminUser($em);
  2959.         $this->addFlash(
  2960.             'success',
  2961.             'The Action was Successful.'
  2962.         );
  2963.         return $this->redirectToRoute('user_login');
  2964.     }
  2965.     public function LogoutAction(Request $request)
  2966.     {
  2967.         $session $request->getSession();
  2968.         $em_goc $this->getDoctrine()->getManager('company_group');
  2969.         $session $request->getSession();
  2970.         $currentTime = new \Datetime();
  2971.         $currTs $currentTime->format('U');
  2972.         $currentTaskId $session->get(UserConstants::USER_CURRENT_TASK_ID0);
  2973.         $currentPlanningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  2974.         if($request->query->get('endCurrentTask'0) == 1)
  2975.         {
  2976.         if (
  2977.             ($currentTaskId != && $currentTaskId != null && $currentTaskId != '') &&
  2978.             ($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
  2979.                 $session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
  2980.         ) {
  2981.             $gocId $session->get(UserConstants::USER_GOC_ID);
  2982.             if ($gocId != && $gocId != "") {
  2983.                 $gocDbName $session->get(UserConstants::USER_DB_NAME);
  2984.                 $gocDbUser $session->get(UserConstants::USER_DB_USER);
  2985.                 $gocDbPass $session->get(UserConstants::USER_DB_PASS);
  2986.                 $gocDbHost $session->get(UserConstants::USER_DB_HOST);
  2987. //                $connector = $this->container->get('application_connector');
  2988.                 $connector $this->container->get('application_connector');
  2989.                 $connector->resetConnection(
  2990.                     'default',
  2991.                     $gocDbName,
  2992.                     $gocDbUser,
  2993.                     $gocDbPass,
  2994.                     $gocDbHost,
  2995.                     $reset false);
  2996.             }
  2997.             $em $this->getDoctrine()->getManager();
  2998.             $stmt $em->getConnection()->prepare('UPDATE task_log set working_status=2, actual_end_ts=' $currTs ' where working_status=1 and user_id= ' $session->get(UserConstants::USER_ID) . ' ;');
  2999.             $stmt->execute();
  3000.             $stmt->closeCursor();
  3001.             if (1) {
  3002.                 $session->set(UserConstants::USER_CURRENT_TASK_ID0);
  3003.                 $session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID0);
  3004.                 $empId $session->get(UserConstants::USER_EMPLOYEE_ID0);
  3005.                 $currTime = new \DateTime();
  3006.                 $options = array(
  3007.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  3008.                     'notification_server' => $this->container->getParameter('notification_server'),
  3009.                 );
  3010.                 $positionsArray = [
  3011.                     array(
  3012.                         'employeeId' => $empId,
  3013.                         'userId' => $session->get(UserConstants::USER_ID0),
  3014.                         'sysUserId' => $session->get(UserConstants::USER_ID0),
  3015.                         'timeStamp' => $currTime->format(DATE_ISO8601),
  3016.                         'lat' => 23.8623834,
  3017.                         'lng' => 90.3979294,
  3018.                         'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
  3019. //                            'userId'=>$session->get(UserConstants::USER_ID, 0),
  3020.                     )
  3021.                 ];
  3022.                 if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  3023.                 if ($positionsArray == null$positionsArray = [];
  3024.                 $dataByAttId = [];
  3025.                 $workPlaceType '_UNSET_';
  3026.                 foreach ($positionsArray as $findex => $d) {
  3027.                     $sysUserId 0;
  3028.                     $userId 0;
  3029.                     $empId 0;
  3030.                     $dtTs 0;
  3031.                     $timeZoneStr '+0000';
  3032.                     if (isset($d['employeeId'])) $empId $d['employeeId'];
  3033.                     if (isset($d['userId'])) $userId $d['userId'];
  3034.                     if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  3035.                     if (isset($d['tsMilSec'])) {
  3036.                         $dtTs ceil(($d['tsMilSec']) / 1000);
  3037.                     }
  3038.                     if ($dtTs == 0) {
  3039.                         $currTsTime = new \DateTime();
  3040.                         $dtTs $currTsTime->format('U');
  3041.                     } else {
  3042.                         $currTsTime = new \DateTime('@' $dtTs);
  3043.                     }
  3044.                     $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  3045.                     $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  3046.                     $EmployeeAttendance $this->getDoctrine()
  3047.                         ->getRepository(EmployeeAttendance::class)
  3048.                         ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  3049.                     if (!$EmployeeAttendance) {
  3050.                         continue;
  3051.                     } else {
  3052.                     }
  3053.                     $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$request$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  3054.                     if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
  3055.                         $workPlaceType '_STATIC_';
  3056.                     }
  3057.                     if (!isset($dataByAttId[$attendanceInfo->getId()]))
  3058.                         $dataByAttId[$attendanceInfo->getId()] = array(
  3059.                             'attendanceInfo' => $attendanceInfo,
  3060.                             'empId' => $empId,
  3061.                             'lat' => 0,
  3062.                             'lng' => 0,
  3063.                             'address' => 0,
  3064.                             'sysUserId' => $sysUserId,
  3065.                             'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  3066.                             'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  3067.                             'positionArray' => []
  3068.                         );
  3069.                     $posData = array(
  3070.                         'ts' => $dtTs,
  3071.                         'lat' => $d['lat'],
  3072.                         'lng' => $d['lng'],
  3073.                         'marker' => $d['markerId'],
  3074.                         'src' => 2,
  3075.                     );
  3076.                     $posDataArray = array(
  3077.                         $dtTs,
  3078.                         $d['lat'],
  3079.                         $d['lng'],
  3080.                         $d['markerId'],
  3081.                         2
  3082.                     );
  3083.                     $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  3084.                     //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  3085.                     $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  3086.                     $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  3087.                     $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  3088.                     $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  3089.                     if (isset($d['address']))
  3090.                         $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  3091. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  3092.                 }
  3093.                 $response = array(
  3094.                     'success' => true,
  3095.                 );
  3096.                 foreach ($dataByAttId as $attInfoId => $d) {
  3097.                     $response HumanResource::setAttendanceLogFlutterApp($em,
  3098.                         $d['empId'],
  3099.                         $d['sysUserId'],
  3100.                         $d['companyId'],
  3101.                         $d['appId'],
  3102.                         $request,
  3103.                         $d['attendanceInfo'],
  3104.                         $options,
  3105.                         $d['positionArray'],
  3106.                         $d['lat'],
  3107.                         $d['lng'],
  3108.                         $d['address'],
  3109.                         $d['markerId']
  3110.                     );
  3111.                 }
  3112.             }
  3113.         }
  3114.     }
  3115.         $token $request->request->get('token''');
  3116.         if ($token != '')
  3117.             MiscActions::DeleteToken($em_goc$token);
  3118.         $session->clear();
  3119.         $session->set('CLEARLOGIN'1);
  3120.         if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
  3121.             if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
  3122.                 $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$request->server->get('HTTP_REFERER'));
  3123.             }
  3124.         } else {
  3125.             $session->set('LAST_REQUEST_URI_BEFORE_LOGIN''');
  3126.         }
  3127. //        $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
  3128. //            )
  3129. //
  3130. //        );
  3131.         if ($request->request->get('remoteVerify'0) == || $request->query->get('remoteVerify'0) == || $request->get('returnJson'0) == 1) {
  3132.             return new JsonResponse(array(
  3133.                 "success" => empty($session->get(UserConstants::USER_ID)) ? true false,
  3134.                 //            'session'=>$request->getSession(),
  3135.                 'session_data' => [],
  3136.                 //            'session2'=>$_SESSION,
  3137.             ));
  3138.         }
  3139.         return $this->redirectToRoute("dashboard");
  3140.     }
  3141.     public function applicantLoginAction(Request $req$refRoute '')
  3142.     {
  3143.         $session $req->getSession();
  3144.         $email $req->getSession()->get('userEmail');
  3145.         $sessionUserId $req->getSession()->get('userId');
  3146.         $oAuthData = [];
  3147. //    $refRoute='';
  3148.         $em $this->getDoctrine()->getManager('company_group');
  3149.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  3150.         $redirectRoute 'dashboard';
  3151.         if ($refRoute != '') {
  3152.             if ($refRoute == '8917922')
  3153.                 $redirectRoute 'apply_for_consultant';
  3154.         }
  3155.         if ($req->query->has('refRoute')) {
  3156.             $refRoute $req->query->get('refRoute');
  3157.             if ($refRoute == '8917922')
  3158.                 $redirectRoute 'apply_for_consultant';
  3159.         }
  3160.         $message '';
  3161.         $errorField '_NONE_';
  3162.         if ($req->query->has('message')) {
  3163.             $message $req->query->get('message');
  3164.         }
  3165.         if ($req->query->has('errorField')) {
  3166.             $errorField $req->query->get('errorField');
  3167.         }
  3168.         if ($req->request->has('oAuthData')) {
  3169.             $oAuthData $req->request->get('oAuthData', []);
  3170.         } else {
  3171.             $oAuthData = [
  3172.                 'email' => $req->request->get('email'''),
  3173.                 'uniqueId' => $req->request->get('uniqueId'''),
  3174.                 'oAuthHash' => '_NONE_',
  3175.                 'image' => $req->request->get('image'''),
  3176.                 'emailVerified' => $req->request->get('emailVerified'''),
  3177.                 'name' => $req->request->get('name'''),
  3178.                 'firstName' => $req->request->get('firstName'''),
  3179.                 'lastName' => $req->request->get('lastName'''),
  3180.                 'type' => 1,
  3181.                 'token' => $req->request->get('oAuthtoken'''),
  3182.             ];
  3183.         }
  3184.         $isApplicantExist null;
  3185.         if ($email) {
  3186.             if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  3187.                 $isApplicantExist $applicantRepo->findOneBy([
  3188.                     'applicantId' => $sessionUserId
  3189.                 ]);
  3190.             } else
  3191.                 return $this->redirectToRoute($redirectRoute);
  3192.         }
  3193.         $google_client = new Google_Client();
  3194. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3195. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3196.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3197.             $url $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3198.         } else {
  3199.             $url $this->generateUrl(
  3200.                 'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3201.             );
  3202.         }
  3203.         $selector ConsultancyConstant::$selector;
  3204.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3205.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3206. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3207.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
  3208. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3209.         $google_client->setRedirectUri($url);
  3210.         $google_client->setAccessType('offline');        // offline access
  3211.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3212.         $google_client->addScope('email');
  3213.         $google_client->addScope('profile');
  3214.         $google_client->addScope('openid');
  3215. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  3216.         //linked in 1st
  3217.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  3218.             $curl curl_init();
  3219.             curl_setopt_array($curl, array(
  3220.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  3221.                 CURLOPT_HEADER => false,  // don't return headers
  3222.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  3223.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  3224.                 CURLOPT_ENCODING => "",     // handle compressed
  3225.                 CURLOPT_USERAGENT => "test"// name of client
  3226.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  3227.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  3228.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  3229.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  3230.                 CURLOPT_USERAGENT => 'InnoPM',
  3231.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  3232.                 CURLOPT_POST => 1,
  3233.                 CURLOPT_HTTPHEADER => array(
  3234.                     'Content-Type: application/x-www-form-urlencoded'
  3235.                 )
  3236.             ));
  3237.             $content curl_exec($curl);
  3238.             $contentArray = [];
  3239.             curl_close($curl);
  3240.             $token false;
  3241. //      return new JsonResponse(array(
  3242. //          'content'=>$content,
  3243. //          'contentArray'=>json_decode($content,true),
  3244. //
  3245. //      ));
  3246.             if ($content) {
  3247.                 $contentArray json_decode($contenttrue);
  3248.                 $token $contentArray['access_token'];
  3249.             }
  3250.             if ($token) {
  3251.                 $applicantInfo = [];
  3252.                 $curl curl_init();
  3253.                 curl_setopt_array($curl, array(
  3254.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  3255.                     CURLOPT_HEADER => false,  // don't return headers
  3256.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  3257.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  3258.                     CURLOPT_ENCODING => "",     // handle compressed
  3259.                     CURLOPT_USERAGENT => "test"// name of client
  3260.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  3261.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  3262.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  3263.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  3264.                     CURLOPT_USERAGENT => 'InnoPM',
  3265.                     CURLOPT_HTTPGET => 1,
  3266.                     CURLOPT_HTTPHEADER => array(
  3267.                         'Authorization: Bearer ' $token,
  3268.                         'Header-Key-2: Header-Value-2'
  3269.                     )
  3270.                 ));
  3271.                 $userGeneralcontent curl_exec($curl);
  3272.                 curl_close($curl);
  3273.                 if ($userGeneralcontent) {
  3274.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  3275.                 }
  3276.                 $curl curl_init();
  3277.                 curl_setopt_array($curl, array(
  3278.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  3279.                     CURLOPT_HEADER => false,  // don't return headers
  3280.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  3281.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  3282.                     CURLOPT_ENCODING => "",     // handle compressed
  3283.                     CURLOPT_USERAGENT => "test"// name of client
  3284.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  3285.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  3286.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  3287.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  3288. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  3289.                     CURLOPT_USERAGENT => 'InnoPM',
  3290.                     CURLOPT_HTTPGET => 1,
  3291.                     CURLOPT_HTTPHEADER => array(
  3292.                         'Authorization: Bearer ' $token,
  3293.                         'Header-Key-2: Header-Value-2'
  3294.                     )
  3295.                 ));
  3296.                 $userEmailcontent curl_exec($curl);
  3297.                 curl_close($curl);
  3298.                 $token false;
  3299.                 if ($userEmailcontent) {
  3300.                     $userEmailcontent json_decode($userEmailcontenttrue);
  3301.                 }
  3302. //        $oAuthEmail = $applicantInfo['email'];
  3303. //        return new JsonResponse(array(
  3304. //          'userEmailcontent'=>$userEmailcontent,
  3305. //          'userGeneralcontent'=>$userGeneralcontent,
  3306. //        ));
  3307. //        return new response($userGeneralcontent);
  3308.                 $oAuthData = [
  3309.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  3310.                     'uniqueId' => $userGeneralcontent['id'],
  3311.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  3312.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  3313.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  3314.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  3315.                     'lastName' => $userGeneralcontent['localizedLastName'],
  3316.                     'type' => 1,
  3317.                     'token' => $token,
  3318.                 ];
  3319.             }
  3320.         } else if (isset($_GET["code"])) {
  3321.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  3322.             if (!isset($token['error'])) {
  3323.                 $google_client->setAccessToken($token['access_token']);
  3324.                 $google_service = new Google_Service_Oauth2($google_client);
  3325.                 $applicantInfo $google_service->userinfo->get();
  3326.                 $oAuthEmail $applicantInfo['email'];
  3327.                 $oAuthData = [
  3328.                     'email' => $applicantInfo['email'],
  3329.                     'uniqueId' => $applicantInfo['id'],
  3330.                     'image' => $applicantInfo['picture'],
  3331.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  3332.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  3333.                     'firstName' => $applicantInfo['givenName'],
  3334.                     'lastName' => $applicantInfo['familyName'],
  3335.                     'type' => $token['token_type'],
  3336.                     'token' => $token['access_token'],
  3337.                 ];
  3338.             }
  3339.         }
  3340.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  3341.             $isApplicantExist $applicantRepo->findOneBy([
  3342.                 'email' => $oAuthData['email']
  3343.             ]);
  3344.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  3345.                 $isApplicantExist $applicantRepo->findOneBy([
  3346.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  3347.                 ]);
  3348.             }
  3349.             if ($isApplicantExist) {
  3350.                 if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  3351.                 } else
  3352.                     return $this->redirectToRoute("user_login", [
  3353.                         'id' => $isApplicantExist->getApplicantId(),
  3354.                         'oAuthData' => $oAuthData,
  3355.                         'refRoute' => $refRoute,
  3356.                         'locale' => $req->request->get('locale''en'),
  3357.                         'remoteVerify' => $req->request->get('remoteVerify'0),
  3358.                         'firebaseToken' => $req->request->get('firebaseToken'''),
  3359.                     ]);
  3360.             } else {
  3361.                 $fname $oAuthData['firstName'];
  3362.                 $lname $oAuthData['lastName'];
  3363.                 $img $oAuthData['image'];
  3364.                 $email $oAuthData['email'];
  3365.                 $oAuthEmail $oAuthData['email'];
  3366.                 $userName explode('@'$email)[0];
  3367.                 //now check if same username exists
  3368.                 $username_already_exist 1;
  3369.                 $initial_user_name $userName;
  3370.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  3371.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  3372.                     $isUsernameExist $applicantRepo->findOneBy([
  3373.                         'username' => $userName
  3374.                     ]);
  3375.                     if ($isUsernameExist) {
  3376.                         $username_already_exist 1;
  3377.                         $userName $initial_user_name '' rand(3009987);
  3378.                     } else {
  3379.                         $username_already_exist 0;
  3380.                     }
  3381.                     $timeoutSafeCount--;
  3382.                 }
  3383.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  3384.                     $currentUnixTimeStamp '';
  3385.                     $currentUnixTime = new \DateTime();
  3386.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  3387.                     $userName $userName '' $currentUnixTimeStamp;
  3388.                 }
  3389.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  3390.                 $charactersLength strlen($characters);
  3391.                 $length 8;
  3392.                 $password 0;
  3393.                 for ($i 0$i $length$i++) {
  3394.                     $password .= $characters[rand(0$charactersLength 1)];
  3395.                 }
  3396.                 $newApplicant = new EntityApplicantDetails();
  3397.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  3398.                 $newApplicant->setEmail($email);
  3399.                 $newApplicant->setUserName($userName);
  3400.                 $newApplicant->setFirstname($fname);
  3401.                 $newApplicant->setLastname($lname);
  3402.                 $newApplicant->setOAuthEmail($oAuthEmail);
  3403.                 $newApplicant->setIsEmailVerified(1);
  3404.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  3405.                 $newApplicant->setAccountStatus(1);
  3406.                 //salt will be username
  3407. //                $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
  3408.                 $salt uniqid(mt_rand());
  3409.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  3410.                 $newApplicant->setPassword($encodedPassword);
  3411.                 $newApplicant->setSalt($salt);
  3412.                 $newApplicant->setTempPassword($password);
  3413. //                $newApplicant->setPassword($password);
  3414.                 $marker $userName '-' time();
  3415. //                $extension_here=$uploadedFile->guessExtension();
  3416. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  3417. //                $path = $fileName;
  3418.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  3419.                 if (!file_exists($upl_dir)) {
  3420.                     mkdir($upl_dir0777true);
  3421.                 }
  3422.                 $ch curl_init($img);
  3423.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  3424.                 curl_setopt($chCURLOPT_FILE$fp);
  3425.                 curl_setopt($chCURLOPT_HEADER0);
  3426.                 curl_exec($ch);
  3427.                 curl_close($ch);
  3428.                 fclose($fp);
  3429.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  3430. //                $newApplicant->setImage($img);
  3431.                 $newApplicant->setIsConsultant(0);
  3432.                 $newApplicant->setIsTemporaryEntry(0);
  3433.                 $newApplicant->setApplyForConsultant(0);
  3434.                 $newApplicant->setTriggerResetPassword(0);
  3435.                 $em->persist($newApplicant);
  3436.                 $em->flush();
  3437.                 $isApplicantExist $newApplicant;
  3438.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  3439.                     if ($systemType == '_BUDDYBEE_') {
  3440.                         $bodyHtml '';
  3441.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  3442.                         $bodyData = array(
  3443.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  3444.                             'email' => $userName,
  3445.                             'showPassword' => $newApplicant->getTempPassword() != '' 0,
  3446.                             'password' => $newApplicant->getTempPassword(),
  3447.                         );
  3448.                         $attachments = [];
  3449.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  3450. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  3451.                         $new_mail $this->get('mail_module');
  3452.                         $new_mail->sendMyMail(array(
  3453.                             'senderHash' => '_CUSTOM_',
  3454.                             //                        'senderHash'=>'_CUSTOM_',
  3455.                             'forwardToMailAddress' => $forwardToMailAddress,
  3456.                             'subject' => 'Welcome to BuddyBee ',
  3457. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  3458.                             'attachments' => $attachments,
  3459.                             'toAddress' => $forwardToMailAddress,
  3460.                             'fromAddress' => 'registration@buddybee.eu',
  3461.                             'userName' => 'registration@buddybee.eu',
  3462.                             'password' => 'Y41dh8g0112',
  3463.                             'smtpServer' => 'smtp.hostinger.com',
  3464.                             'smtpPort' => 465,
  3465.                             'encryptionMethod' => 'ssl',
  3466. //                            'emailBody' => $bodyHtml,
  3467.                             'mailTemplate' => $bodyTemplate,
  3468.                             'templateData' => $bodyData,
  3469. //                        'embedCompanyImage' => 1,
  3470. //                        'companyId' => $companyId,
  3471. //                        'companyImagePath' => $company_data->getImage()
  3472.                         ));
  3473.                     } else {
  3474.                         $bodyHtml '';
  3475.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  3476.                         $bodyData = array(
  3477.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  3478.                             'email' => 'APP-' $userName,
  3479.                             'password' => $newApplicant->getPassword(),
  3480.                         );
  3481.                         $attachments = [];
  3482.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  3483. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  3484.                         $new_mail $this->get('mail_module');
  3485.                         $new_mail->sendMyMail(array(
  3486.                             'senderHash' => '_CUSTOM_',
  3487.                             //                        'senderHash'=>'_CUSTOM_',
  3488.                             'forwardToMailAddress' => $forwardToMailAddress,
  3489.                             'subject' => 'Applicant Registration on Honeybee',
  3490. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  3491.                             'attachments' => $attachments,
  3492.                             'toAddress' => $forwardToMailAddress,
  3493.                             'fromAddress' => 'support@ourhoneybee.eu',
  3494.                             'userName' => 'support@ourhoneybee.eu',
  3495.                             'password' => 'Y41dh8g0112',
  3496.                             'smtpServer' => 'smtp.hostinger.com',
  3497.                             'smtpPort' => 465,
  3498.                             'encryptionMethod' => 'ssl',
  3499. //                            'emailBody' => $bodyHtml,
  3500.                             'mailTemplate' => $bodyTemplate,
  3501.                             'templateData' => $bodyData,
  3502. //                        'embedCompanyImage' => 1,
  3503. //                        'companyId' => $companyId,
  3504. //                        'companyImagePath' => $company_data->getImage()
  3505.                         ));
  3506.                     }
  3507.                 }
  3508.                 if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  3509.                 } else {
  3510.                     return $this->redirectToRoute("user_login", [
  3511.                         'id' => $newApplicant->getApplicantId(),
  3512.                         'oAuthData' => $oAuthData,
  3513.                         'refRoute' => $refRoute,
  3514.                         'remoteVerify' => $req->request->get('remoteVerify'0),
  3515.                         'locale' => $req->request->get('locale''en'),
  3516.                         'firebaseToken' => $req->request->get('firebaseToken'''),
  3517.                     ]);
  3518.                 }
  3519.             }
  3520.         }
  3521.         if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  3522.             if ($isApplicantExist) {
  3523.                 $user $isApplicantExist;
  3524.                 $userType UserConstants::USER_TYPE_APPLICANT;
  3525.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  3526.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  3527.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TS$user->getLastSettingsUpdatedTs());
  3528.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  3529.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  3530.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  3531.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  3532.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  3533.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  3534.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  3535.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  3536.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  3537.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  3538.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  3539.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  3540.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  3541.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  3542.                     $session->set(UserConstants::USER_COMPANY_ID1);
  3543.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  3544.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  3545.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  3546.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  3547.                     $session->set('userCompanyVibrantList'json_encode([]));
  3548.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  3549.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  3550.                     $session->set(UserConstants::USER_APP_ID0);
  3551.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  3552.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  3553.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  3554.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  3555.                     $session->set(UserConstants::USER_GOC_ID0);
  3556.                     $session->set(UserConstants::USER_DB_NAME'');
  3557.                     $session->set(UserConstants::USER_DB_USER'');
  3558.                     $session->set(UserConstants::USER_DB_PASS'');
  3559.                     $session->set(UserConstants::USER_DB_HOST'');
  3560.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  3561.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  3562.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  3563.                     $session->set('oAuthToken'$req->request->get('oAuthToken'''));
  3564.                     $session->set('locale'$req->request->get('locale'''));
  3565.                     $session->set('firebaseToken'$req->request->get('firebaseToken'''));
  3566.                     $route_list_array = [];
  3567.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  3568.                     $loginID 0;
  3569.                     $loginID MiscActions::addEntityUserLoginLog(
  3570.                         $em,
  3571.                         $session->get(UserConstants::USER_ID),
  3572.                         $session->get(UserConstants::USER_ID),
  3573.                         1,
  3574.                         $req->server->get("REMOTE_ADDR"),
  3575.                         0,
  3576.                         $req->request->get('deviceId'''),
  3577.                         $req->request->get('oAuthToken'''),
  3578.                         $req->request->get('oAuthType'''),
  3579.                         $req->request->get('locale'''),
  3580.                         $req->request->get('firebaseToken''')
  3581.                     );
  3582.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  3583.                     $session_data = array(
  3584.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  3585.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  3586.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  3587.                         'oAuthToken' => $session->get('oAuthToken'),
  3588.                         'locale' => $session->get('locale'),
  3589.                         'firebaseToken' => $session->get('firebaseToken'),
  3590.                         'token' => $session->get('token'),
  3591.                         'firstLogin' => 0,
  3592.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  3593.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  3594.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  3595.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  3596.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  3597.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  3598.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  3599.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3600.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  3601.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  3602.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  3603.                         'oAuthImage' => $session->get('oAuthImage'),
  3604.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  3605.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  3606.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  3607.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  3608.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  3609.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  3610.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3611.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  3612.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  3613.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  3614.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  3615.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  3616.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  3617.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  3618.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  3619.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  3620.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  3621.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  3622.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  3623.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  3624.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  3625.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  3626.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  3627.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  3628.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  3629.                         //new
  3630.                         'appIdList' => $session->get('appIdList'),
  3631.                         'branchIdList' => $session->get('branchIdList'null),
  3632.                         'branchId' => $session->get('branchId'null),
  3633.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  3634.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  3635.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  3636.                     );
  3637.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  3638.                     $session_data $tokenData['sessionData'];
  3639.                     $token $tokenData['token'];
  3640.                     $session->set('token'$token);
  3641.                     if ($req->request->get('remoteVerify'0) == || $req->query->get('remoteVerify'0) == 1) {
  3642.                         $session->set('remoteVerified'1);
  3643.                         $response = new JsonResponse(array(
  3644.                             'token' => $token,
  3645.                             'uid' => $session->get(UserConstants::USER_ID),
  3646.                             'session' => $session,
  3647.                             'success' => true,
  3648.                             'session_data' => $session_data,
  3649.                             'session2' => $_SESSION,
  3650.                         ));
  3651.                         $response->headers->set('Access-Control-Allow-Origin''*');
  3652.                         return $response;
  3653.                     }
  3654.                     if ($req->request->has('referer_path')) {
  3655.                         if ($req->request->get('referer_path') != '/' && $req->request->get('referer_path') != '') {
  3656.                             return $this->redirect($req->request->get('referer_path'));
  3657.                         }
  3658.                     }
  3659.                     $redirectRoute 'applicant_dashboard';
  3660.                     if ($req->query->has('refRoute')) {
  3661.                         if ($req->query->get('refRoute') == '8917922')
  3662.                             $redirectRoute 'apply_for_consultant';
  3663.                     }
  3664.                     return $this->redirectToRoute($redirectRoute);
  3665.                 }
  3666. //                    $response = new JsonResponse(array(
  3667. //                        'token' => $token,
  3668. //                        'uid' => $session->get(UserConstants::USER_ID),
  3669. //                        'session' => $session,
  3670. //
  3671. //                        'success' => true,
  3672. //                        'session_data' => $session_data,
  3673. //                        'session2' => $_SESSION,
  3674. //                    ));
  3675. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  3676. //                    return $response;
  3677. //                    return $this->redirectToRoute("user_login", [
  3678. //                        'id' => $isApplicantExist->getApplicantId(),
  3679. //                        'oAuthData' => $oAuthData,
  3680. //                        'refRoute' => $refRoute,
  3681. //                        'locale' => $req->request->get('locale', 'en'),
  3682. //                        'remoteVerify' => $req->request->get('remoteVerify', 0),
  3683. //                        'firebaseToken' => $req->request->get('firebaseToken', ''),
  3684. //                    ]);
  3685.             }
  3686.         }
  3687. //        if ($req->isMethod('POST')){
  3688. //            $new = new EntityApplicantDetails();
  3689. //
  3690. //            $new-> setUsername->$req->request->get('userName');
  3691. //            $new-> setEmail()->$req->request->get('email');
  3692. //            $new-> setPassword()->$req->request->get('password');
  3693. //            $new-> setSelector()->$req->request->get('selector');
  3694. //
  3695. //
  3696. //            $em->persist($new);
  3697. //            $em->flush();
  3698. //        }
  3699.         $selector ConsultancyConstant::$selector;
  3700.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3701.         $twig_file 'ApplicationBundle:pages/login:applicant_login.html.twig';
  3702.         if ($systemType == '_ERP_') {
  3703.         } else if ($systemType == '_BUDDYBEE_') {
  3704.             return $this->render(
  3705.                 'ApplicationBundle:pages/login:applicant_login.html.twig',
  3706.                 [
  3707.                     'page_title' => 'BuddyBee Login',
  3708.                     'oAuthLink' => $google_client->createAuthUrl(),
  3709.                     'redirect_url' => $url,
  3710.                     'message' => $message,
  3711.                     'errorField' => $errorField,
  3712.                     'refRoute' => $refRoute,
  3713.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  3714.                     'selector' => $selector
  3715.                 ]
  3716.             );
  3717.         }
  3718.         return $this->render(
  3719.             'ApplicationBundle:pages/login:applicant_login.html.twig',
  3720.             [
  3721.                 'page_title' => 'Applicant Registration',
  3722.                 'oAuthLink' => $google_client->createAuthUrl(),
  3723.                 'redirect_url' => $url,
  3724.                 'refRoute' => $refRoute,
  3725.                 'message' => $message,
  3726.                 'errorField' => $errorField,
  3727.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  3728.                 'selector' => $selector
  3729.             ]
  3730.         );
  3731.     }
  3732.     public function centralLoginAction(Request $req$refRoute '')
  3733.     {
  3734.         $session $req->getSession();
  3735.         $email $req->getSession()->get('userEmail');
  3736.         $sessionUserId $req->getSession()->get('userId');
  3737.         $oAuthData = [];
  3738. //    $refRoute='';
  3739.         $em $this->getDoctrine()->getManager('company_group');
  3740.         $applicantRepo $em->getRepository(EntityApplicantDetails::class);
  3741.         $redirectRoute 'dashboard';
  3742.         if ($refRoute != '') {
  3743.             if ($refRoute == '8917922')
  3744.                 $redirectRoute 'apply_for_consultant';
  3745.         }
  3746.         if ($req->query->has('refRoute')) {
  3747.             $refRoute $req->query->get('refRoute');
  3748.             if ($refRoute == '8917922')
  3749.                 $redirectRoute 'apply_for_consultant';
  3750.         }
  3751.         $message '';
  3752.         $errorField '_NONE_';
  3753.         if ($req->query->has('message')) {
  3754.             $message $req->query->get('message');
  3755.         }
  3756.         if ($req->query->has('errorField')) {
  3757.             $errorField $req->query->get('errorField');
  3758.         }
  3759.         if ($req->request->has('oAuthData')) {
  3760.             $oAuthData $req->request->get('oAuthData', []);
  3761.         } else {
  3762.             $oAuthData = [
  3763.                 'email' => $req->request->get('email'''),
  3764.                 'uniqueId' => $req->request->get('uniqueId'''),
  3765.                 'oAuthHash' => '_NONE_',
  3766.                 'image' => $req->request->get('image'''),
  3767.                 'emailVerified' => $req->request->get('emailVerified'''),
  3768.                 'name' => $req->request->get('name'''),
  3769.                 'firstName' => $req->request->get('firstName'''),
  3770.                 'lastName' => $req->request->get('lastName'''),
  3771.                 'type' => 1,
  3772.                 'token' => $req->request->get('oAuthtoken'''),
  3773.             ];
  3774.         }
  3775.         $isApplicantExist null;
  3776.         if ($email) {
  3777.             if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  3778.                 $isApplicantExist $applicantRepo->findOneBy([
  3779.                     'applicantId' => $sessionUserId
  3780.                 ]);
  3781.             } else
  3782.                 return $this->redirectToRoute($redirectRoute);
  3783.         }
  3784.         $google_client = new Google_Client();
  3785. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  3786. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  3787.         if (version_compare(PHP_VERSION'5.4.0''>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE 4)) {
  3788.             $url $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
  3789.         } else {
  3790.             $url $this->generateUrl(
  3791.                 'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
  3792.             );
  3793.         }
  3794.         $selector ConsultancyConstant::$selector;
  3795.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  3796.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  3797. //        $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
  3798.         $google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
  3799. //        $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
  3800.         $google_client->setRedirectUri($url);
  3801.         $google_client->setAccessType('offline');        // offline access
  3802.         $google_client->setIncludeGrantedScopes(true);   // incremental auth
  3803.         $google_client->addScope('email');
  3804.         $google_client->addScope('profile');
  3805.         $google_client->addScope('openid');
  3806. //    $google_client->setRedirectUri('http://localhost/applicant_login');
  3807.         //linked in 1st
  3808.         if (isset($_GET["code"]) && isset($_GET["state"])) {
  3809.             $curl curl_init();
  3810.             curl_setopt_array($curl, array(
  3811.                 CURLOPT_RETURNTRANSFER => true,   // return web page
  3812.                 CURLOPT_HEADER => false,  // don't return headers
  3813.                 CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  3814.                 CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  3815.                 CURLOPT_ENCODING => "",     // handle compressed
  3816.                 CURLOPT_USERAGENT => "test"// name of client
  3817.                 CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  3818.                 CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  3819.                 CURLOPT_TIMEOUT => 120,    // time-out on response
  3820.                 CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
  3821.                 CURLOPT_USERAGENT => 'InnoPM',
  3822.                 CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
  3823.                 CURLOPT_POST => 1,
  3824.                 CURLOPT_HTTPHEADER => array(
  3825.                     'Content-Type: application/x-www-form-urlencoded'
  3826.                 )
  3827.             ));
  3828.             $content curl_exec($curl);
  3829.             $contentArray = [];
  3830.             curl_close($curl);
  3831.             $token false;
  3832. //      return new JsonResponse(array(
  3833. //          'content'=>$content,
  3834. //          'contentArray'=>json_decode($content,true),
  3835. //
  3836. //      ));
  3837.             if ($content) {
  3838.                 $contentArray json_decode($contenttrue);
  3839.                 $token $contentArray['access_token'];
  3840.             }
  3841.             if ($token) {
  3842.                 $applicantInfo = [];
  3843.                 $curl curl_init();
  3844.                 curl_setopt_array($curl, array(
  3845.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  3846.                     CURLOPT_HEADER => false,  // don't return headers
  3847.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  3848.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  3849.                     CURLOPT_ENCODING => "",     // handle compressed
  3850.                     CURLOPT_USERAGENT => "test"// name of client
  3851.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  3852.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  3853.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  3854.                     CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
  3855.                     CURLOPT_USERAGENT => 'InnoPM',
  3856.                     CURLOPT_HTTPGET => 1,
  3857.                     CURLOPT_HTTPHEADER => array(
  3858.                         'Authorization: Bearer ' $token,
  3859.                         'Header-Key-2: Header-Value-2'
  3860.                     )
  3861.                 ));
  3862.                 $userGeneralcontent curl_exec($curl);
  3863.                 curl_close($curl);
  3864.                 if ($userGeneralcontent) {
  3865.                     $userGeneralcontent json_decode($userGeneralcontenttrue);
  3866.                 }
  3867.                 $curl curl_init();
  3868.                 curl_setopt_array($curl, array(
  3869.                     CURLOPT_RETURNTRANSFER => true,   // return web page
  3870.                     CURLOPT_HEADER => false,  // don't return headers
  3871.                     CURLOPT_FOLLOWLOCATION => true,   // follow redirects
  3872.                     CURLOPT_MAXREDIRS => 10,     // stop after 10 redirects
  3873.                     CURLOPT_ENCODING => "",     // handle compressed
  3874.                     CURLOPT_USERAGENT => "test"// name of client
  3875.                     CURLOPT_AUTOREFERER => true,   // set referrer on redirect
  3876.                     CURLOPT_CONNECTTIMEOUT => 120,    // time-out on connect
  3877.                     CURLOPT_TIMEOUT => 120,    // time-out on response
  3878.                     CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
  3879. //            CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
  3880.                     CURLOPT_USERAGENT => 'InnoPM',
  3881.                     CURLOPT_HTTPGET => 1,
  3882.                     CURLOPT_HTTPHEADER => array(
  3883.                         'Authorization: Bearer ' $token,
  3884.                         'Header-Key-2: Header-Value-2'
  3885.                     )
  3886.                 ));
  3887.                 $userEmailcontent curl_exec($curl);
  3888.                 curl_close($curl);
  3889.                 $token false;
  3890.                 if ($userEmailcontent) {
  3891.                     $userEmailcontent json_decode($userEmailcontenttrue);
  3892.                 }
  3893. //        $oAuthEmail = $applicantInfo['email'];
  3894. //        return new JsonResponse(array(
  3895. //          'userEmailcontent'=>$userEmailcontent,
  3896. //          'userGeneralcontent'=>$userGeneralcontent,
  3897. //        ));
  3898. //        return new response($userGeneralcontent);
  3899.                 $oAuthData = [
  3900.                     'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  3901.                     'uniqueId' => $userGeneralcontent['id'],
  3902.                     'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
  3903.                     'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
  3904.                     'name' => $userGeneralcontent['localizedFirstName'] . ' ' $userGeneralcontent['localizedLastName'],
  3905.                     'firstName' => $userGeneralcontent['localizedFirstName'],
  3906.                     'lastName' => $userGeneralcontent['localizedLastName'],
  3907.                     'type' => 1,
  3908.                     'token' => $token,
  3909.                 ];
  3910.             }
  3911.         } else if (isset($_GET["code"])) {
  3912.             $token $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
  3913.             if (!isset($token['error'])) {
  3914.                 $google_client->setAccessToken($token['access_token']);
  3915.                 $google_service = new Google_Service_Oauth2($google_client);
  3916.                 $applicantInfo $google_service->userinfo->get();
  3917.                 $oAuthEmail $applicantInfo['email'];
  3918.                 $oAuthData = [
  3919.                     'email' => $applicantInfo['email'],
  3920.                     'uniqueId' => $applicantInfo['id'],
  3921.                     'image' => $applicantInfo['picture'],
  3922.                     'emailVerified' => $applicantInfo['verifiedEmail'],
  3923.                     'name' => $applicantInfo['givenName'] . ' ' $applicantInfo['familyName'],
  3924.                     'firstName' => $applicantInfo['givenName'],
  3925.                     'lastName' => $applicantInfo['familyName'],
  3926.                     'type' => $token['token_type'],
  3927.                     'token' => $token['access_token'],
  3928.                 ];
  3929.             }
  3930.         }
  3931.         if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
  3932.             $isApplicantExist $applicantRepo->findOneBy([
  3933.                 'email' => $oAuthData['email']
  3934.             ]);
  3935.             if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
  3936.                 $isApplicantExist $applicantRepo->findOneBy([
  3937.                     'oAuthUniqueId' => $oAuthData['uniqueId']
  3938.                 ]);
  3939.             }
  3940.             if ($isApplicantExist) {
  3941.                 if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  3942.                 } else
  3943.                     return $this->redirectToRoute("user_login", [
  3944.                         'id' => $isApplicantExist->getApplicantId(),
  3945.                         'oAuthData' => $oAuthData,
  3946.                         'refRoute' => $refRoute,
  3947.                         'locale' => $req->request->get('locale''en'),
  3948.                         'remoteVerify' => $req->request->get('remoteVerify'0),
  3949.                         'firebaseToken' => $req->request->get('firebaseToken'''),
  3950.                     ]);
  3951.             } else {
  3952.                 $fname $oAuthData['firstName'];
  3953.                 $lname $oAuthData['lastName'];
  3954.                 $img $oAuthData['image'];
  3955.                 $email $oAuthData['email'];
  3956.                 $oAuthEmail $oAuthData['email'];
  3957.                 $userName explode('@'$email)[0];
  3958.                 //now check if same username exists
  3959.                 $username_already_exist 1;
  3960.                 $initial_user_name $userName;
  3961.                 $timeoutSafeCount 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
  3962.                 while ($username_already_exist == && $timeoutSafeCount 0) {
  3963.                     $isUsernameExist $applicantRepo->findOneBy([
  3964.                         'username' => $userName
  3965.                     ]);
  3966.                     if ($isUsernameExist) {
  3967.                         $username_already_exist 1;
  3968.                         $userName $initial_user_name '' rand(3009987);
  3969.                     } else {
  3970.                         $username_already_exist 0;
  3971.                     }
  3972.                     $timeoutSafeCount--;
  3973.                 }
  3974.                 if ($timeoutSafeCount == && $username_already_exist == 1) {
  3975.                     $currentUnixTimeStamp '';
  3976.                     $currentUnixTime = new \DateTime();
  3977.                     $currentUnixTimeStamp $currentUnixTime->format('U');
  3978.                     $userName $userName '' $currentUnixTimeStamp;
  3979.                 }
  3980.                 $characters '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  3981.                 $charactersLength strlen($characters);
  3982.                 $length 8;
  3983.                 $password 0;
  3984.                 for ($i 0$i $length$i++) {
  3985.                     $password .= $characters[rand(0$charactersLength 1)];
  3986.                 }
  3987.                 $newApplicant = new EntityApplicantDetails();
  3988.                 $newApplicant->setActualRegistrationAt(new \DateTime());
  3989.                 $newApplicant->setEmail($email);
  3990.                 $newApplicant->setUserName($userName);
  3991.                 $newApplicant->setFirstname($fname);
  3992.                 $newApplicant->setLastname($lname);
  3993.                 $newApplicant->setOAuthEmail($oAuthEmail);
  3994.                 $newApplicant->setIsEmailVerified(1);
  3995.                 $newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
  3996.                 $newApplicant->setAccountStatus(1);
  3997.                 $salt uniqid(mt_rand());
  3998.                 $encodedPassword $this->container->get('sha256salted_encoder')->encodePassword($password$salt);
  3999.                 $newApplicant->setPassword($encodedPassword);
  4000.                 $newApplicant->setSalt($salt);
  4001.                 $newApplicant->setTempPassword($password);;
  4002. //                $newApplicant->setPassword($password);
  4003.                 $marker $userName '-' time();
  4004. //                $extension_here=$uploadedFile->guessExtension();
  4005. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  4006. //                $path = $fileName;
  4007.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
  4008.                 if (!file_exists($upl_dir)) {
  4009.                     mkdir($upl_dir0777true);
  4010.                 }
  4011.                 $ch curl_init($img);
  4012.                 $fp fopen($upl_dir '/' $marker '.jiff''wb');
  4013.                 curl_setopt($chCURLOPT_FILE$fp);
  4014.                 curl_setopt($chCURLOPT_HEADER0);
  4015.                 curl_exec($ch);
  4016.                 curl_close($ch);
  4017.                 fclose($fp);
  4018.                 $newApplicant->setImage('/uploads/applicants/' $marker '.jiff');
  4019. //                $newApplicant->setImage($img);
  4020.                 $newApplicant->setIsConsultant(0);
  4021.                 $newApplicant->setIsTemporaryEntry(0);
  4022.                 $newApplicant->setApplyForConsultant(0);
  4023.                 $em->persist($newApplicant);
  4024.                 $em->flush();
  4025.                 $isApplicantExist $newApplicant;
  4026.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  4027.                     if ($systemType == '_BUDDYBEE_') {
  4028.                         $bodyHtml '';
  4029.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
  4030.                         $bodyData = array(
  4031.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  4032.                             'email' => $userName,
  4033.                             'password' => $newApplicant->getPassword(),
  4034.                         );
  4035.                         $attachments = [];
  4036.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  4037. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  4038.                         $new_mail $this->get('mail_module');
  4039.                         $new_mail->sendMyMail(array(
  4040.                             'senderHash' => '_CUSTOM_',
  4041.                             //                        'senderHash'=>'_CUSTOM_',
  4042.                             'forwardToMailAddress' => $forwardToMailAddress,
  4043.                             'subject' => 'Welcome to BuddyBee ',
  4044. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  4045.                             'attachments' => $attachments,
  4046.                             'toAddress' => $forwardToMailAddress,
  4047.                             'fromAddress' => 'registration@buddybee.eu',
  4048.                             'userName' => 'registration@buddybee.eu',
  4049.                             'password' => 'Y41dh8g0112',
  4050.                             'smtpServer' => 'smtp.hostinger.com',
  4051.                             'smtpPort' => 465,
  4052.                             'encryptionMethod' => 'ssl',
  4053. //                            'emailBody' => $bodyHtml,
  4054.                             'mailTemplate' => $bodyTemplate,
  4055.                             'templateData' => $bodyData,
  4056. //                        'embedCompanyImage' => 1,
  4057. //                        'companyId' => $companyId,
  4058. //                        'companyImagePath' => $company_data->getImage()
  4059.                         ));
  4060.                     } else {
  4061.                         $bodyHtml '';
  4062.                         $bodyTemplate 'ApplicationBundle:email/user:applicant_login.html.twig';
  4063.                         $bodyData = array(
  4064.                             'name' => $newApplicant->getFirstname() . ' ' $newApplicant->getLastname(),
  4065.                             'email' => 'APP-' $userName,
  4066.                             'password' => $newApplicant->getPassword(),
  4067.                         );
  4068.                         $attachments = [];
  4069.                         $forwardToMailAddress $newApplicant->getOAuthEmail();
  4070. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  4071.                         $new_mail $this->get('mail_module');
  4072.                         $new_mail->sendMyMail(array(
  4073.                             'senderHash' => '_CUSTOM_',
  4074.                             //                        'senderHash'=>'_CUSTOM_',
  4075.                             'forwardToMailAddress' => $forwardToMailAddress,
  4076.                             'subject' => 'Applicant Registration on Honeybee',
  4077. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  4078.                             'attachments' => $attachments,
  4079.                             'toAddress' => $forwardToMailAddress,
  4080.                             'fromAddress' => 'support@ourhoneybee.eu',
  4081.                             'userName' => 'support@ourhoneybee.eu',
  4082.                             'password' => 'Y41dh8g0112',
  4083.                             'smtpServer' => 'smtp.hostinger.com',
  4084.                             'smtpPort' => 465,
  4085.                             'encryptionMethod' => 'ssl',
  4086. //                            'emailBody' => $bodyHtml,
  4087.                             'mailTemplate' => $bodyTemplate,
  4088.                             'templateData' => $bodyData,
  4089. //                        'embedCompanyImage' => 1,
  4090. //                        'companyId' => $companyId,
  4091. //                        'companyImagePath' => $company_data->getImage()
  4092.                         ));
  4093.                     }
  4094.                 }
  4095.                 if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  4096.                 } else {
  4097.                     return $this->redirectToRoute("user_login", [
  4098.                         'id' => $newApplicant->getApplicantId(),
  4099.                         'oAuthData' => $oAuthData,
  4100.                         'refRoute' => $refRoute,
  4101.                         'remoteVerify' => $req->request->get('remoteVerify'0),
  4102.                         'locale' => $req->request->get('locale''en'),
  4103.                         'firebaseToken' => $req->request->get('firebaseToken'''),
  4104.                     ]);
  4105.                 }
  4106.             }
  4107.         }
  4108.         if ($req->request->get('remoteVerify'$req->query->get('remoteVerify'0)) == 1) {
  4109.             if ($isApplicantExist) {
  4110.                 $user $isApplicantExist;
  4111.                 $userType UserConstants::USER_TYPE_APPLICANT;
  4112.                 if ($userType == UserConstants::USER_TYPE_APPLICANT) {
  4113.                     $session->set(UserConstants::USER_ID$user->getApplicantId());
  4114.                     $session->set(UserConstants::LAST_SETTINGS_UPDATED_TS$user->getLastSettingsUpdatedTs());
  4115.                     $session->set(UserConstants::IS_CONSULTANT$user->getIsConsultant() == 0);
  4116.                     $session->set('BUDDYBEE_BALANCE'$user->getAccountBalance());
  4117.                     $session->set('BUDDYBEE_COIN_BALANCE'$user->getSessionCountBalance());
  4118.                     $session->set(UserConstants::IS_BUDDYBEE_RETAILER$user->getIsRetailer() == 0);
  4119.                     $session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL$user->getRetailerLevel() == 0);
  4120.                     $session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL$user->getIsAdmin() == : ($user->getIsModerator() == 0));
  4121.                     $session->set(UserConstants::IS_BUDDYBEE_MODERATOR$user->getIsModerator() == 0);
  4122.                     $session->set(UserConstants::IS_BUDDYBEE_ADMIN$user->getIsAdmin() == 0);
  4123.                     // $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
  4124.                     $session->set(UserConstants::USER_TYPEUserConstants::USER_TYPE_APPLICANT);
  4125.                     $session->set(UserConstants::USER_EMAIL$user->getOauthEmail());
  4126.                     $session->set(UserConstants::USER_IMAGE$user->getImage());
  4127.                     $session->set(UserConstants::USER_NAME$user->getFirstName() . ' ' $user->getLastName());
  4128.                     $session->set(UserConstants::USER_DEFAULT_ROUTE'');
  4129.                     $session->set(UserConstants::USER_COMPANY_ID1);
  4130.                     $session->set(UserConstants::USER_COMPANY_ID_LISTjson_encode([]));
  4131.                     $session->set(UserConstants::USER_COMPANY_NAME_LISTjson_encode([]));
  4132.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  4133.                     $session->set('userCompanyDarkVibrantList'json_encode([]));
  4134.                     $session->set('userCompanyVibrantList'json_encode([]));
  4135.                     $session->set('userCompanyLightVibrantList'json_encode([]));
  4136.                     $session->set(UserConstants::USER_COMPANY_IMAGE_LISTjson_encode([]));
  4137.                     $session->set(UserConstants::USER_APP_ID0);
  4138.                     $session->set(UserConstants::USER_POSITION_LIST'[]');
  4139.                     $session->set(UserConstants::ALL_MODULE_ACCESS_FLAG0);
  4140.                     $session->set(UserConstants::SESSION_SALTuniqid(mt_rand()));
  4141.                     $session->set(UserConstants::APPLICATION_SECRET$this->container->getParameter('secret'));
  4142.                     $session->set(UserConstants::USER_GOC_ID0);
  4143.                     $session->set(UserConstants::USER_DB_NAME'');
  4144.                     $session->set(UserConstants::USER_DB_USER'');
  4145.                     $session->set(UserConstants::USER_DB_PASS'');
  4146.                     $session->set(UserConstants::USER_DB_HOST'');
  4147.                     $session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE'');
  4148.                     $session->set(UserConstants::USER_NOTIFICATION_ENABLEDGeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0);
  4149.                     $session->set(UserConstants::USER_NOTIFICATION_SERVER$this->getParameter('notification_server'));
  4150.                     $session->set('oAuthToken'$req->request->get('oAuthToken'''));
  4151.                     $session->set('locale'$req->request->get('locale'''));
  4152.                     $session->set('firebaseToken'$req->request->get('firebaseToken'''));
  4153.                     $route_list_array = [];
  4154.                     $session->set(UserConstants::USER_CURRENT_POSITION0);
  4155.                     $loginID 0;
  4156.                     $loginID MiscActions::addEntityUserLoginLog(
  4157.                         $em,
  4158.                         $session->get(UserConstants::USER_ID),
  4159.                         $session->get(UserConstants::USER_ID),
  4160.                         1,
  4161.                         $req->server->get("REMOTE_ADDR"),
  4162.                         0,
  4163.                         $req->request->get('deviceId'''),
  4164.                         $req->request->get('oAuthToken'''),
  4165.                         $req->request->get('oAuthType'''),
  4166.                         $req->request->get('locale'''),
  4167.                         $req->request->get('firebaseToken''')
  4168.                     );
  4169.                     $session->set(UserConstants::USER_LOGIN_ID$loginID);
  4170.                     $session_data = array(
  4171.                         UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
  4172.                         UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
  4173.                         UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
  4174.                         'oAuthToken' => $session->get('oAuthToken'),
  4175.                         'locale' => $session->get('locale'),
  4176.                         'firebaseToken' => $session->get('firebaseToken'),
  4177.                         'token' => $session->get('token'),
  4178.                         'firstLogin' => 0,
  4179.                         'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
  4180.                         'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
  4181.                         UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
  4182.                         UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
  4183.                         UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
  4184.                         UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
  4185.                         UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
  4186.                         UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
  4187.                         UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
  4188.                         UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
  4189.                         UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
  4190.                         'oAuthImage' => $session->get('oAuthImage'),
  4191.                         UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
  4192.                         UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
  4193.                         UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
  4194.                         UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
  4195.                         UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
  4196.                         UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
  4197.                         UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
  4198.                         UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
  4199.                         UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
  4200.                         UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
  4201.                         UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
  4202.                         'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
  4203.                         'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
  4204.                         'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
  4205.                         UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
  4206.                         UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
  4207.                         UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
  4208.                         UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
  4209.                         UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
  4210.                         UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
  4211.                         UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
  4212.                         UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == ? ($this->getParameter('notification_enabled') == 0) : 0,
  4213.                         UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
  4214.                         //new
  4215.                         'appIdList' => $session->get('appIdList'),
  4216.                         'branchIdList' => $session->get('branchIdList'null),
  4217.                         'branchId' => $session->get('branchId'null),
  4218.                         'companyIdListByAppId' => $session->get('companyIdListByAppId'),
  4219.                         'companyNameListByAppId' => $session->get('companyNameListByAppId'),
  4220.                         'companyImageListByAppId' => $session->get('companyImageListByAppId'),
  4221.                     );
  4222.                     $tokenData MiscActions::CreateTokenFromSessionData($em$session_data);
  4223.                     $session_data $tokenData['sessionData'];
  4224.                     $token $tokenData['token'];
  4225.                     $session->set('token'$token);
  4226.                     if ($req->request->get('remoteVerify'0) == || $req->query->get('remoteVerify'0) == 1) {
  4227.                         $session->set('remoteVerified'1);
  4228.                         $response = new JsonResponse(array(
  4229.                             'token' => $token,
  4230.                             'uid' => $session->get(UserConstants::USER_ID),
  4231.                             'session' => $session,
  4232.                             'success' => true,
  4233.                             'session_data' => $session_data,
  4234.                             'session2' => $_SESSION,
  4235.                         ));
  4236.                         $response->headers->set('Access-Control-Allow-Origin''*');
  4237.                         return $response;
  4238.                     }
  4239.                     if ($req->request->has('referer_path')) {
  4240.                         if ($req->request->get('referer_path') != '/' && $req->request->get('referer_path') != '') {
  4241.                             return $this->redirect($req->request->get('referer_path'));
  4242.                         }
  4243.                     }
  4244.                     $redirectRoute 'applicant_dashboard';
  4245.                     if ($req->query->has('refRoute')) {
  4246.                         if ($req->query->get('refRoute') == '8917922')
  4247.                             $redirectRoute 'apply_for_consultant';
  4248.                     }
  4249.                     return $this->redirectToRoute($redirectRoute);
  4250.                 }
  4251. //                    $response = new JsonResponse(array(
  4252. //                        'token' => $token,
  4253. //                        'uid' => $session->get(UserConstants::USER_ID),
  4254. //                        'session' => $session,
  4255. //
  4256. //                        'success' => true,
  4257. //                        'session_data' => $session_data,
  4258. //                        'session2' => $_SESSION,
  4259. //                    ));
  4260. //                    $response->headers->set('Access-Control-Allow-Origin', '*');
  4261. //                    return $response;
  4262. //                    return $this->redirectToRoute("user_login", [
  4263. //                        'id' => $isApplicantExist->getApplicantId(),
  4264. //                        'oAuthData' => $oAuthData,
  4265. //                        'refRoute' => $refRoute,
  4266. //                        'locale' => $req->request->get('locale', 'en'),
  4267. //                        'remoteVerify' => $req->request->get('remoteVerify', 0),
  4268. //                        'firebaseToken' => $req->request->get('firebaseToken', ''),
  4269. //                    ]);
  4270.             }
  4271.         }
  4272.         $selector ConsultancyConstant::$selector;
  4273.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  4274.         $twig_file 'ApplicationBundle:pages/login:applicant_login.html.twig';
  4275.         if ($systemType == '_ERP_') {
  4276.         } else if ($systemType == '_CENTRAL_') {
  4277.             return $this->render(
  4278.                 'ApplicationBundle:pages/login:central_login.html.twig',
  4279.                 [
  4280.                     'page_title' => 'Central Login',
  4281.                     'oAuthLink' => $google_client->createAuthUrl(),
  4282.                     'redirect_url' => $url,
  4283.                     'message' => $message,
  4284.                     'systemType' => $systemType,
  4285.                     'ownServerId' => $ownServerId,
  4286.                     'errorField' => '',
  4287.                     'refRoute' => $refRoute,
  4288.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  4289.                     'selector' => $selector,
  4290.                 ]
  4291.             );
  4292.         }  else if ($systemType == '_BUDDYBEE_') {
  4293.             return $this->render(
  4294.                 'ApplicationBundle:pages/login:applicant_login.html.twig',
  4295.                 [
  4296.                     'page_title' => 'BuddyBee Login',
  4297.                     'oAuthLink' => $google_client->createAuthUrl(),
  4298.                     'redirect_url' => $url,
  4299.                     'message' => $message,
  4300.                     'errorField' => $errorField,
  4301.                     'refRoute' => $refRoute,
  4302.                     'state' => 'DCEeFWf45A53sdfKeSS424',
  4303.                     'selector' => $selector
  4304.                 ]
  4305.             );
  4306.         }
  4307.         return $this->render(
  4308.             'ApplicationBundle:pages/login:applicant_login.html.twig',
  4309.             [
  4310.                 'page_title' => 'Applicant Registration',
  4311.                 'oAuthLink' => $google_client->createAuthUrl(),
  4312.                 'redirect_url' => $url,
  4313.                 'refRoute' => $refRoute,
  4314.                 'message' => $message,
  4315.                 'errorField' => $errorField,
  4316.                 'state' => 'DCEeFWf45A53sdfKeSS424',
  4317.                 'selector' => $selector
  4318.             ]
  4319.         );
  4320.     }
  4321.     public function FindAccountAction(Request $request$encData '')
  4322.     {
  4323. //        $userCategory=$request->request->has('userCategory');
  4324.         $encryptedData = [];
  4325.         $errorField '';
  4326.         $message '';
  4327.         $userType '';
  4328.         $otpExpireSecond 180;
  4329.         $otpExpireTs 0;
  4330.         $otp '';
  4331.         if ($encData != '')
  4332.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  4333. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  4334.         $userCategory '_BUDDYBEE_USER_';
  4335.         if (isset($encryptedData['userCategory']))
  4336.             $userCategory $encryptedData['userCategory'];
  4337.         else
  4338.             $userCategory $request->request->get('userCategory''_BUDDYBEE_USER_');
  4339.         $em $this->getDoctrine()->getManager('company_group');
  4340.         $em_goc $this->getDoctrine()->getManager('company_group');
  4341.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  4342.         $ownServerId $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
  4343.         $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4344.         $twigData = [];
  4345.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  4346.         $email_address $request->request->get('email''');
  4347.         $email_twig_data = [];
  4348.         $appendCode $request->request->get('appendCode'$request->query->get('appendCode'''));
  4349.         if ($request->isMethod('POST')) {
  4350.             //set an otp and its expire and send mail
  4351.             $email_address $request->request->get('email');
  4352.             $userObj null;
  4353.             $userData = [];
  4354.             if ($systemType == '_ERP_') {
  4355.                 if ($userCategory == '_APPLICANT_') {
  4356.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4357.                     $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4358.                         array(
  4359.                             'email' => $email_address
  4360.                         )
  4361.                     );
  4362.                     if ($userObj) {
  4363.                     } else {
  4364.                         $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4365.                             array(
  4366.                                 'oAuthEmail' => $email_address
  4367.                             )
  4368.                         );
  4369.                         if ($userObj) {
  4370.                         } else {
  4371.                             $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4372.                                 array(
  4373.                                     'username' => $email_address
  4374.                                 )
  4375.                             );
  4376.                         }
  4377.                     }
  4378.                     if ($userObj) {
  4379.                         $email_address $userObj->getEmail();
  4380.                         if ($email_address == null || $email_address == '')
  4381.                             $email_address $userObj->getOAuthEmail();
  4382.                     }
  4383. //                    triggerResetPassword:
  4384. //                    type: integer
  4385. //                          nullable: true
  4386.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  4387.                     $otp $otpData['otp'];
  4388.                     $otpExpireTs $otpData['expireTs'];
  4389.                     $userObj->setOtp($otpData['otp']);
  4390.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  4391.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  4392.                     $em_goc->flush();
  4393.                     $userData = array(
  4394.                         'id' => $userObj->getApplicantId(),
  4395.                         'email' => $email_address,
  4396.                         'appId' => 0,
  4397. //                        'appId'=>$userObj->getUserAppId(),
  4398.                     );
  4399.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  4400.                     $email_twig_data = [
  4401.                         'page_title' => 'Find Account',
  4402.                         'encryptedData' => $encryptedData,
  4403.                         'message' => $message,
  4404.                         'userType' => $userType,
  4405.                         'errorField' => $errorField,
  4406.                         'otp' => $otpData['otp'],
  4407.                         'otpExpireSecond' => $otpExpireSecond,
  4408.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  4409.                         'otpExpireTs' => $otpData['expireTs'],
  4410.                         'systemType' => $systemType,
  4411.                         'userData' => $userData
  4412.                     ];
  4413.                     if ($userObj)
  4414.                         $email_twig_data['success'] = true;
  4415.                 } else {
  4416.                     $userType UserConstants::USER_TYPE_GENERAL;
  4417.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  4418.                     $email_twig_data = [
  4419.                         'page_title' => 'Find Account',
  4420.                         'encryptedData' => $encryptedData,
  4421.                         'message' => $message,
  4422.                         'userType' => $userType,
  4423.                         'errorField' => $errorField,
  4424.                     ];
  4425.                 }
  4426.             } else if ($systemType == '_CENTRAL_') {
  4427.                 $userType UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER;
  4428.                 $userObj $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
  4429.                     array(
  4430.                         'email' => $email_address
  4431.                     )
  4432.                 );
  4433.                 if ($userObj) {
  4434.                 } else {
  4435.                     $userObj $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
  4436.                         array(
  4437.                             'oAuthEmail' => $email_address
  4438.                         )
  4439.                     );
  4440.                     if ($userObj) {
  4441.                     } else {
  4442.                         $userObj $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
  4443.                             array(
  4444.                                 'username' => $email_address
  4445.                             )
  4446.                         );
  4447.                     }
  4448.                 }
  4449.                 if ($userObj) {
  4450.                     $email_address $userObj->getEmail();
  4451.                     if ($email_address == null || $email_address == '')
  4452.                         $email_address $userObj->getOAuthEmail();
  4453.                     //                    triggerResetPassword:
  4454. //                    type: integer
  4455. //                          nullable: true
  4456.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  4457.                     $otp $otpData['otp'];
  4458.                     $otpExpireTs $otpData['expireTs'];
  4459.                     $userObj->setOtp($otpData['otp']);
  4460.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  4461.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  4462.                     $em_goc->flush();
  4463.                     $userData = array(
  4464.                         'id' => $userObj->getApplicantId(),
  4465.                         'email' => $email_address,
  4466.                         'appId' => 0,
  4467.                         'image' => $userObj->getImage(),
  4468.                         'firstName' => $userObj->getFirstname(),
  4469.                         'lastName' => $userObj->getLastname(),
  4470.                         'phone' => $userObj->getPhone(),
  4471. //                        'appId'=>$userObj->getUserAppId(),
  4472.                     );
  4473.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  4474.                     $email_twig_data = [
  4475.                         'page_title' => 'Find Account',
  4476.                         'encryptedData' => $encryptedData,
  4477.                         'message' => $message,
  4478.                         'userType' => $userType,
  4479.                         'errorField' => $errorField,
  4480.                         'otp' => $otpData['otp'],
  4481.                         'otpExpireSecond' => $otpExpireSecond,
  4482.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  4483.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  4484.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  4485.                         'otpExpireTs' => $otpData['expireTs'],
  4486.                         'systemType' => $systemType,
  4487.                         'userCategory' => $userCategory,
  4488.                         'userData' => $userData
  4489.                     ];
  4490.                     $email_twig_data['success'] = true;
  4491.                 } else {
  4492.                     $message "Oops! Could not find your account";
  4493.                     $email_twig_data['success'] = false;
  4494.                 }
  4495.             } else if ($systemType == '_BUDDYBEE_') {
  4496.                 $userType UserConstants::USER_TYPE_APPLICANT;
  4497.                 $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4498.                     array(
  4499.                         'email' => $email_address
  4500.                     )
  4501.                 );
  4502.                 if ($userObj) {
  4503.                 } else {
  4504.                     $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4505.                         array(
  4506.                             'oAuthEmail' => $email_address
  4507.                         )
  4508.                     );
  4509.                     if ($userObj) {
  4510.                     } else {
  4511.                         $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4512.                             array(
  4513.                                 'username' => $email_address
  4514.                             )
  4515.                         );
  4516.                     }
  4517.                 }
  4518.                 if ($userObj) {
  4519.                     $email_address $userObj->getEmail();
  4520.                     if ($email_address == null || $email_address == '')
  4521.                         $email_address $userObj->getOAuthEmail();
  4522.                     //                    triggerResetPassword:
  4523. //                    type: integer
  4524. //                          nullable: true
  4525.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  4526.                     $otp $otpData['otp'];
  4527.                     $otpExpireTs $otpData['expireTs'];
  4528.                     $userObj->setOtp($otpData['otp']);
  4529.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  4530.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  4531.                     $em_goc->flush();
  4532.                     $userData = array(
  4533.                         'id' => $userObj->getApplicantId(),
  4534.                         'email' => $email_address,
  4535.                         'appId' => 0,
  4536.                         'image' => $userObj->getImage(),
  4537.                         'firstName' => $userObj->getFirstname(),
  4538.                         'lastName' => $userObj->getLastname(),
  4539.                         'phone' => $userObj->getPhone(),
  4540. //                        'appId'=>$userObj->getUserAppId(),
  4541.                     );
  4542.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  4543.                     $email_twig_data = [
  4544.                         'page_title' => 'Find Account',
  4545.                         'encryptedData' => $encryptedData,
  4546.                         'message' => $message,
  4547.                         'userType' => $userType,
  4548.                         'errorField' => $errorField,
  4549.                         'otp' => $otpData['otp'],
  4550.                         'otpExpireSecond' => $otpExpireSecond,
  4551.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  4552.                         'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
  4553.                         'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
  4554.                         'otpExpireTs' => $otpData['expireTs'],
  4555.                         'systemType' => $systemType,
  4556.                         'userCategory' => $userCategory,
  4557.                         'userData' => $userData
  4558.                     ];
  4559.                     $email_twig_data['success'] = true;
  4560.                 } else {
  4561.                     $message "Oops! Could not find your account";
  4562.                     $email_twig_data['success'] = false;
  4563.                 }
  4564.             }
  4565.             if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
  4566.                 if ($systemType == '_BUDDYBEE_') {
  4567.                     $bodyHtml '';
  4568.                     $bodyTemplate $email_twig_file;
  4569.                     $bodyData $email_twig_data;
  4570.                     $attachments = [];
  4571.                     $forwardToMailAddress $email_address;
  4572. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  4573.                     $new_mail $this->get('mail_module');
  4574.                     $new_mail->sendMyMail(array(
  4575.                         'senderHash' => '_CUSTOM_',
  4576.                         //                        'senderHash'=>'_CUSTOM_',
  4577.                         'forwardToMailAddress' => $forwardToMailAddress,
  4578.                         'subject' => 'Account Verification',
  4579. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  4580.                         'attachments' => $attachments,
  4581.                         'toAddress' => $forwardToMailAddress,
  4582.                         'fromAddress' => 'no-reply@buddybee.eu',
  4583.                         'userName' => 'no-reply@buddybee.eu',
  4584.                         'password' => 'Honeybee@0112',
  4585.                         'smtpServer' => 'smtp.hostinger.com',
  4586.                         'smtpPort' => 465,
  4587. //                            'emailBody' => $bodyHtml,
  4588.                         'mailTemplate' => $bodyTemplate,
  4589.                         'templateData' => $bodyData,
  4590. //                        'embedCompanyImage' => 1,
  4591. //                        'companyId' => $companyId,
  4592. //                        'companyImagePath' => $company_data->getImage()
  4593.                     ));
  4594.                 } else if ($systemType == '_CENTRAL_') {
  4595.                     $bodyHtml '';
  4596.                     $bodyTemplate $email_twig_file;
  4597.                     $bodyData $email_twig_data;
  4598.                     $attachments = [];
  4599.                     $forwardToMailAddress $email_address;
  4600. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  4601.                     $new_mail $this->get('mail_module');
  4602.                     $new_mail->sendMyMail(array(
  4603.                         'senderHash' => '_CUSTOM_',
  4604.                         //                        'senderHash'=>'_CUSTOM_',
  4605.                         'forwardToMailAddress' => $forwardToMailAddress,
  4606.                         'subject' => 'Account Verification',
  4607. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  4608.                         'attachments' => $attachments,
  4609.                         'toAddress' => $forwardToMailAddress,
  4610.                         'fromAddress' => 'no-reply@ourhoneybee.eu',
  4611.                         'userName' => 'no-reply@ourhoneybee.eu',
  4612.                         'password' => 'Honeybee@0112',
  4613.                         'smtpServer' => 'smtp.hostinger.com',
  4614.                         'smtpPort' => 465,
  4615. //                            'emailBody' => $bodyHtml,
  4616.                         'mailTemplate' => $bodyTemplate,
  4617.                         'templateData' => $bodyData,
  4618. //                        'embedCompanyImage' => 1,
  4619. //                        'companyId' => $companyId,
  4620. //                        'companyImagePath' => $company_data->getImage()
  4621.                     ));
  4622.                 } else {
  4623.                     $bodyHtml '';
  4624.                     $bodyTemplate $email_twig_file;
  4625.                     $bodyData $email_twig_data;
  4626.                     $attachments = [];
  4627.                     $forwardToMailAddress $email_address;
  4628. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  4629.                     $new_mail $this->get('mail_module');
  4630.                     $new_mail->sendMyMail(array(
  4631.                         'senderHash' => '_CUSTOM_',
  4632.                         //                        'senderHash'=>'_CUSTOM_',
  4633.                         'forwardToMailAddress' => $forwardToMailAddress,
  4634.                         'subject' => 'Applicant Registration on Honeybee',
  4635. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  4636.                         'attachments' => $attachments,
  4637.                         'toAddress' => $forwardToMailAddress,
  4638.                         'fromAddress' => 'support@ourhoneybee.eu',
  4639.                         'userName' => 'support@ourhoneybee.eu',
  4640.                         'password' => 'Y41dh8g0112',
  4641.                         'smtpServer' => 'smtp.hostinger.com',
  4642.                         'smtpPort' => 465,
  4643.                         'emailBody' => $bodyHtml,
  4644.                         'mailTemplate' => $bodyTemplate,
  4645.                         'templateData' => $bodyData,
  4646. //                        'embedCompanyImage' => 1,
  4647. //                        'companyId' => $companyId,
  4648. //                        'companyImagePath' => $company_data->getImage()
  4649.                     ));
  4650.                 }
  4651.             }
  4652.             if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == && $userData['phone'] != '' && $userData['phone'] != null) {
  4653.                 if ($systemType == '_BUDDYBEE_') {
  4654.                     $searchVal = ['_OTP_''_EXPIRE_MINUTES_''_APPEND_CODE_'];
  4655.                     $replaceVal = [$otpfloor($otpExpireSecond 60), $appendCode];
  4656.                     $msg 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
  4657.                      _APPEND_CODE_';
  4658.                     $msg str_replace($searchVal$replaceVal$msg);
  4659.                     $emitMarker '_SEND_TEXT_TO_MOBILE_';
  4660.                     $sendType 'all';
  4661.                     $socketUserIds = [];
  4662.                     System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg$userData['phone'], $emitMarker$sendType$socketUserIds);
  4663.                 } else {
  4664.                 }
  4665.             }
  4666.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  4667.                 $response = new JsonResponse(array(
  4668.                         'templateData' => $twigData,
  4669.                         'message' => $message,
  4670. //                        "otp"=>'',
  4671.                         "otp" => $otp,
  4672.                         "otpExpireTs" => $otpExpireTs,
  4673.                         'actionData' => $email_twig_data,
  4674.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  4675.                     )
  4676.                 );
  4677.                 $response->headers->set('Access-Control-Allow-Origin''*');
  4678.                 return $response;
  4679.             } else if ($email_twig_data['success'] == true) {
  4680.                 $encData = array(
  4681.                     "userType" => $userType,
  4682.                     "otp" => '',
  4683. //                "otp"=>$otp,
  4684.                     "otpExpireTs" => $otpExpireTs,
  4685.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  4686.                     "userCategory" => $userCategory,
  4687.                     "userId" => $userData['id'],
  4688.                     "systemType" => $systemType,
  4689.                     "email" => $email_address,
  4690.                 );
  4691.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  4692.                 $url $this->generateUrl(
  4693.                     'verify_otp'
  4694.                 );
  4695.                 return $this->redirect($url "/" $encDataStr);
  4696. //                return $this->redirectToRoute("verify_otp_forgot_password",[
  4697. ////                    'encData'
  4698. ////                'id' => $isApplicantExist->getApplicantId(),
  4699. ////                'oAuthData' => $oAuthData,
  4700. ////                'refRoute' => $refRoute,
  4701. //                ]);
  4702.             }
  4703.         }
  4704.         if ($systemType == '_ERP_') {
  4705.             if ($userCategory == '_APPLICANT_') {
  4706.                 $userType UserConstants::USER_TYPE_APPLICANT;
  4707.                 $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4708.                 $twigData = [
  4709.                     'page_title' => 'Find Account',
  4710.                     'encryptedData' => $encryptedData,
  4711.                     'message' => $message,
  4712.                     'systemType' => $systemType,
  4713.                     'ownServerId' => $ownServerId,
  4714.                     'userType' => $userType,
  4715.                     'errorField' => $errorField,
  4716.                 ];
  4717.             } else {
  4718.                 $userType UserConstants::USER_TYPE_GENERAL;
  4719.                 $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4720.                 $twigData = [
  4721.                     'page_title' => 'Find Account',
  4722.                     'encryptedData' => $encryptedData,
  4723.                     'systemType' => $systemType,
  4724.                     'ownServerId' => $ownServerId,
  4725.                     'message' => $message,
  4726.                     'userType' => $userType,
  4727.                     'errorField' => $errorField,
  4728.                 ];
  4729.             }
  4730.         } else if ($systemType == '_CENTRAL_') {
  4731.             $userType UserConstants::USER_TYPE_APPLICANT;
  4732.             $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4733.             $twigData = [
  4734.                 'page_title' => 'Find Account',
  4735.                 'encryptedData' => $encryptedData,
  4736.                 'systemType' => $systemType,
  4737.                 'ownServerId' => $ownServerId,
  4738.                 "otp" => '',
  4739. //                "otp"=>$otp,
  4740.                 "otpExpireTs" => $otpExpireTs,
  4741.                 'message' => $message,
  4742.                 'userType' => $userType,
  4743.                 'errorField' => $errorField,
  4744.             ];
  4745.         } else if ($systemType == '_BUDDYBEE_') {
  4746.             $userType UserConstants::USER_TYPE_APPLICANT;
  4747.             $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4748.             $twigData = [
  4749.                 'page_title' => 'Find Account',
  4750.                 'encryptedData' => $encryptedData,
  4751.                 "otp" => '',
  4752.                 'systemType' => $systemType,
  4753.                 'ownServerId' => $ownServerId,
  4754. //                "otp"=>$otp,
  4755.                 "otpExpireTs" => $otpExpireTs,
  4756.                 'message' => $message,
  4757.                 'userType' => $userType,
  4758.                 'errorField' => $errorField,
  4759.             ];
  4760.         }
  4761.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  4762.             $response = new JsonResponse(array(
  4763.                     'templateData' => $twigData,
  4764.                     'message' => $message,
  4765.                     "otp" => '',
  4766. //                "otp"=>$otp,
  4767.                     "otpExpireTs" => $otpExpireTs,
  4768.                     'actionData' => $email_twig_data,
  4769.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  4770.                 )
  4771.             );
  4772.             $response->headers->set('Access-Control-Allow-Origin''*');
  4773.             return $response;
  4774.         } else {
  4775.             return $this->render(
  4776.                 $twig_file,
  4777.                 $twigData
  4778.             );
  4779.         }
  4780.     }
  4781.     public function VerifyOtpAction(Request $request$encData '')
  4782.     {
  4783. //        $userCategory=$request->request->has('userCategory');
  4784.         $encryptedData = [];
  4785.         $errorField '';
  4786.         $message '';
  4787.         $userType '';
  4788.         $otpExpireSecond 180;
  4789.         $otpExpireTs 0;
  4790.         if ($encData != '')
  4791.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  4792. //        $encryptedData = $this->get('url_encryptor')->decrypt($encData);
  4793.         $otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
  4794.         $email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
  4795.         $otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
  4796.         $otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
  4797.         $userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
  4798.         $userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
  4799.         $em $this->getDoctrine()->getManager('company_group');
  4800.         $em_goc $this->getDoctrine()->getManager('company_group');
  4801.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  4802.         $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4803.         $twigData = [];
  4804.         $email_twig_file 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
  4805.         $email_twig_data = [];
  4806.         $userData = [];
  4807.         if ($request->isMethod('POST') || $otp != '') {
  4808.             $otp $request->request->get('otp'$otp);
  4809.             $otpActionId $request->request->get('otpActionId'$otpActionId);
  4810.             $userId $request->request->get('userId'$userId);
  4811.             $userCategory $request->request->get('userCategory'$userCategory);
  4812.             $email_address $request->request->get('email'$email);
  4813.             if ($systemType == '_ERP_') {
  4814.                 if ($userCategory == '_APPLICANT_') {
  4815.                     $userType UserConstants::USER_TYPE_APPLICANT;
  4816.                     $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4817.                         array(
  4818.                             'email' => $email_address
  4819.                         )
  4820.                     );
  4821.                     if ($userObj) {
  4822.                     } else {
  4823.                         $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4824.                             array(
  4825.                                 'oAuthEmail' => $email_address
  4826.                             )
  4827.                         );
  4828.                         if ($userObj) {
  4829.                         } else {
  4830.                             $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4831.                                 array(
  4832.                                     'userName' => $email_address
  4833.                                 )
  4834.                             );
  4835.                         }
  4836.                     }
  4837.                     if ($userObj) {
  4838.                         $email_address $userObj->getEmail();
  4839.                         if ($email_address == null || $email_address == '')
  4840.                             $email_address $userObj->getOAuthEmail();
  4841.                     }
  4842. //                    triggerResetPassword:
  4843. //                    type: integer
  4844. //                          nullable: true
  4845.                     $otpData MiscActions::GenerateOtp($otpExpireSecond);
  4846.                     $userObj->setOtp($otpData['otp']);
  4847.                     $userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
  4848.                     $userObj->setOtpExpireTs($otpData['expireTs']);
  4849.                     $em_goc->flush();
  4850.                     $userData = array(
  4851.                         'id' => $userObj->getApplicantId(),
  4852.                         'email' => $email_address,
  4853.                         'appId' => 0,
  4854. //                        'appId'=>$userObj->getUserAppId(),
  4855.                     );
  4856.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  4857.                     $email_twig_data = [
  4858.                         'page_title' => 'Find Account',
  4859.                         'encryptedData' => $encryptedData,
  4860.                         'message' => $message,
  4861.                         'userType' => $userType,
  4862.                         'errorField' => $errorField,
  4863.                         'otp' => $otpData['otp'],
  4864.                         'otpExpireSecond' => $otpExpireSecond,
  4865.                         'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  4866.                         'otpExpireTs' => $otpData['expireTs'],
  4867.                         'systemType' => $systemType,
  4868.                         'userData' => $userData
  4869.                     ];
  4870.                     if ($userObj)
  4871.                         $email_twig_data['success'] = true;
  4872.                 } else {
  4873.                     $userType UserConstants::USER_TYPE_GENERAL;
  4874.                     $email_twig_file 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
  4875.                     $email_twig_data = [
  4876.                         'page_title' => 'Find Account',
  4877.                         'encryptedData' => $encryptedData,
  4878.                         'message' => $message,
  4879.                         'userType' => $userType,
  4880.                         'errorField' => $errorField,
  4881.                     ];
  4882.                 }
  4883.             } else if ($systemType == '_BUDDYBEE_') {
  4884.                 $userType UserConstants::USER_TYPE_APPLICANT;
  4885.                 $userObj $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
  4886.                     array(
  4887.                         'applicantId' => $userId
  4888.                     )
  4889.                 );
  4890.                 if ($userObj) {
  4891.                     $userOtp $userObj->getOtp();
  4892.                     $userOtpActionId $userObj->getOtpActionId();
  4893.                     $userOtpExpireTs $userObj->getOtpExpireTs();
  4894.                     $otpExpireTs $userObj->getOtpExpireTs();
  4895.                     $currentTime = new \DateTime();
  4896.                     $currentTimeTs $currentTime->format('U');
  4897.                     if ($userOtp != $otp) {
  4898.                         $message "Invalid OTP!";
  4899.                         $email_twig_data['success'] = false;
  4900.                     } else if ($userOtpActionId != $otpActionId) {
  4901.                         $message "Invalid OTP Action!";
  4902.                         $email_twig_data['success'] = false;
  4903.                     } else if ($currentTimeTs $userOtpExpireTs) {
  4904.                         $message "OTP Expired!";
  4905.                         $email_twig_data['success'] = false;
  4906.                     } else {
  4907.                         $userObj->setOtp(0);
  4908.                         $userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
  4909.                         $userObj->setOtpExpireTs(0);
  4910.                         $userObj->setTriggerResetPassword(1);
  4911.                         $em_goc->flush();
  4912.                         $email_twig_data['success'] = true;
  4913.                         $message "";
  4914.                     }
  4915.                     $userData = array(
  4916.                         'id' => $userObj->getApplicantId(),
  4917.                         'email' => $email_address,
  4918.                         'appId' => 0,
  4919.                         'image' => $userObj->getImage(),
  4920.                         'firstName' => $userObj->getFirstname(),
  4921.                         'lastName' => $userObj->getLastname(),
  4922. //                        'appId'=>$userObj->getUserAppId(),
  4923.                     );
  4924.                     $email_twig_data['userData'] = $userData;
  4925.                 } else {
  4926.                     $message "Account not found!";
  4927.                     $email_twig_data['success'] = false;
  4928.                 }
  4929.             }
  4930.             if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  4931.                 $response = new JsonResponse(array(
  4932.                         'templateData' => $twigData,
  4933.                         'message' => $message,
  4934.                         'actionData' => $email_twig_data,
  4935.                         'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  4936.                     )
  4937.                 );
  4938.                 $response->headers->set('Access-Control-Allow-Origin''*');
  4939.                 return $response;
  4940.             } else if ($email_twig_data['success'] == true) {
  4941.                 $encData = array(
  4942.                     "userType" => $userType,
  4943.                     "otp" => '',
  4944.                     "otpExpireTs" => $otpExpireTs,
  4945.                     "otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
  4946.                     "userCategory" => $userCategory,
  4947.                     "userId" => $userData['id'],
  4948.                     "systemType" => $systemType,
  4949.                 );
  4950.                 $encDataStr $this->get('url_encryptor')->encrypt(json_encode($encData));
  4951.                 $url $this->generateUrl(
  4952.                     'reset_password_new_password'
  4953.                 );
  4954.                 return $this->redirect($url "/" $encDataStr);
  4955. //                return $this->redirectToRoute("reset_password_new_password", [
  4956. ////                'id' => $isApplicantExist->getApplicantId(),
  4957. ////                'oAuthData' => $oAuthData,
  4958. ////                'refRoute' => $refRoute,
  4959. //                ]);
  4960.             }
  4961.         }
  4962.         if ($systemType == '_ERP_') {
  4963.             if ($userCategory == '_APPLICANT_') {
  4964.                 $userType UserConstants::USER_TYPE_APPLICANT;
  4965.                 $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4966.                 $twigData = [
  4967.                     'page_title' => 'Find Account',
  4968.                     'encryptedData' => $encryptedData,
  4969.                     'message' => $message,
  4970.                     'userType' => $userType,
  4971.                     'errorField' => $errorField,
  4972.                 ];
  4973.             } else {
  4974.                 $userType UserConstants::USER_TYPE_GENERAL;
  4975.                 $twig_file 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
  4976.                 $twigData = [
  4977.                     'page_title' => 'Find Account',
  4978.                     'encryptedData' => $encryptedData,
  4979.                     'message' => $message,
  4980.                     'userType' => $userType,
  4981.                     'errorField' => $errorField,
  4982.                 ];
  4983.             }
  4984.         } else if ($systemType == '_BUDDYBEE_') {
  4985.             $userType UserConstants::USER_TYPE_APPLICANT;
  4986.             $twig_file 'ApplicationBundle:pages/login:verify_otp_buddybee.html.twig';
  4987.             $twigData = [
  4988.                 'page_title' => 'Verify Otp',
  4989.                 'encryptedData' => $encryptedData,
  4990.                 'message' => $message,
  4991.                 'email' => $email,
  4992.                 "otp" => '',
  4993. //                "otp"=>$otp,
  4994.                 "otpExpireTs" => $otpExpireTs,
  4995.                 'userType' => $userType,
  4996.                 'userCategory' => $userCategory,
  4997.                 'errorField' => $errorField,
  4998.             ];
  4999.         }
  5000.         if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
  5001.             $response = new JsonResponse(array(
  5002.                     'templateData' => $twigData,
  5003.                     'message' => $message,
  5004.                     'actionData' => $email_twig_data,
  5005.                     'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
  5006.                 )
  5007.             );
  5008.             $response->headers->set('Access-Control-Allow-Origin''*');
  5009.             return $response;
  5010.         } else {
  5011.             return $this->render(
  5012.                 $twig_file,
  5013.                 $twigData
  5014.             );
  5015.         }
  5016.     }
  5017. }