<?php
namespace ApplicationBundle\Controller;
use ApplicationBundle\Constants\ConsultancyConstant;
use ApplicationBundle\Constants\GeneralConstant;
use ApplicationBundle\Constants\HumanResourceConstant;
use ApplicationBundle\Constants\UserConstants;
use ApplicationBundle\Entity\ApplicantDetails;
use ApplicationBundle\Interfaces\LoginInterface;
use ApplicationBundle\Modules\HumanResource\HumanResource;
use ApplicationBundle\Modules\User\Company;
use CompanyGroupBundle\Entity\EntityApplicantDetails;
use ApplicationBundle\Entity\EmployeeAttendance;
use ApplicationBundle\Entity\EmployeeAttendanceLog;
use CompanyGroupBundle\Modules\UserEntity\EntityUserM;
use ApplicationBundle\Modules\User\Position;
use ApplicationBundle\Modules\System\System;
use ApplicationBundle\Modules\System\MiscActions;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Google_Client;
use Google_Service_Oauth2;
use Symfony\Component\HttpFoundation\RedirectResponse;
class UserLoginController extends GenericController implements LoginInterface
{
public function GetSessionDataForAppAction(Request $request)
{
$message = "";
$gocList = [];
$session = $request->getSession();
if ($request->request->has('token')) {
$em_goc = $this->getDoctrine()->getManager('company_group');
$to_set_session_data = MiscActions::GetSessionDataFromToken($em_goc, $request->request->get('token'))['sessionData'];
if ($to_set_session_data != null) {
foreach ($to_set_session_data as $k => $d) {
//check if mobile
$session->set($k, $d);
}
}
}
if ($request->request->has('sessionData')) {
$to_set_session_data = $request->request->get('sessionData');
foreach ($to_set_session_data as $k => $d) {
//check if mobile
$session->set($k, $d);
}
}
$session_data = array(
'oAuthToken' => $session->get('oAuthToken'),
'locale' => $session->get('locale'),
'firebaseToken' => $session->get('firebaseToken'),
'token' => $session->get('token'),
UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
//new addition
'appIdList' => $session->get('appIdList'),
'branchIdList' => $session->get('branchIdList', null),
'branchId' => $session->get('branchId', null),
'companyIdListByAppId' => $session->get('companyIdListByAppId'),
'companyNameListByAppId' => $session->get('companyNameListByAppId'),
'companyImageListByAppId' => $session->get('companyImageListByAppId'),
'userAccessList' => $session->get('userAccessList'),
'csToken' => $session->get('csToken'),
);
$response = new JsonResponse(array(
"success" => empty($session->get(UserConstants::USER_ID)) ? false : true,
// 'session'=>$request->getSession(),
'session_data' => $session_data,
// 'session2'=>$_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*, null');
$response->headers->set('Access-Control-Allow-Methods', 'POST');
// $response->setCallback('FUNCTION_CALLBACK_NAME');
return $response;
}
public function SignUpAction(Request $request, $refRoute = '', $encData = "")
{
$redirectRoute = 'dashboard';
if ($refRoute != '') {
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
if ($request->query->has('refRoute')) {
$refRoute = $request->query->get('refRoute');
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
$message = '';
$errorField = '_NONE_';
if ($request->query->has('message')) {
$message = $request->query->get('message');
}
if ($request->query->has('errorField')) {
$errorField = $request->query->get('errorField');
}
$gocList = [];
$skipPassword = 0;
$firstLogin = 0;
$remember_me = 0;
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
if ($request->isMethod('POST')) {
if ($request->request->has('remember_me'))
$remember_me = 1;
} else {
if ($request->query->has('remember_me'))
$remember_me = 1;
}
if ($encData != "")
$encData = json_decode($this->get('url_encryptor')->decrypt($encData));
else if ($request->query->has('spd')) {
$encData = json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
}
$user = [];
$userType = 0; //nothing for now , will add supp or client if we find anything
$em_goc = $this->getDoctrine()->getManager('company_group');
$em_goc->getConnection()->connect();
$gocEnabled = 0;
if ($this->container->hasParameter('entity_group_enabled'))
$gocEnabled = $this->container->getParameter('entity_group_enabled');
if ($gocEnabled == 1)
$connected = $em_goc->getConnection()->isConnected();
else
$connected = false;
if ($connected)
$gocList = $em_goc
->getRepository("CompanyGroupBundle:CompanyGroup")
->findBy(
array(
'active' => 1
)
);
$gocDataList = [];
$gocDataListForLoginWeb = [];
$gocDataListByAppId = [];
foreach ($gocList as $entry) {
$d = array(
'name' => $entry->getName(),
'id' => $entry->getId(),
'appId' => $entry->getAppId(),
'skipInWebFlag' => $entry->getSkipInWebFlag(),
'skipInAppFlag' => $entry->getSkipInAppFlag(),
'dbName' => $entry->getDbName(),
'dbUser' => $entry->getDbUser(),
'dbPass' => $entry->getDbPass(),
'dbHost' => $entry->getDbHost(),
'companyRemaining' => $entry->getCompanyRemaining(),
'companyAllowed' => $entry->getCompanyAllowed(),
);
$gocDataList[$entry->getId()] = $d;
if (in_array($entry->getSkipInWebFlag(), [0, null]))
$gocDataListForLoginWeb[$entry->getId()] = $d;
$gocDataListByAppId[$entry->getAppId()] = $d;
}
$gocDbName = '';
$gocDbUser = '';
$gocDbPass = '';
$gocDbHost = '';
$gocId = 0;
$hasGoc = 0;
$userId = 0;
$userCompanyId = 0;
$specialLogin = 0;
$supplierId = 0;
$applicantId = 0;
$isApplicantLogin = 0;
$clientId = 0;
$cookieLogin = 0;
if ($request->request->has('gocId')) {
$hasGoc = 1;
$gocId = $request->request->get('gocId');
}
$entityLoginFlag = $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
$loginType = $request->get('loginType') ? $request->get('loginType') : 1;
$oAuthData = $request->get('oAuthData') ? $request->get('oAuthData') : 0;
$signUpUserType = 0;
$em_goc = $this->getDoctrine()->getManager('company_group');
if ($request->isMethod('POST') || $request->query->has('oAuthData') || $cookieLogin == 1) {
///super login
$todayDt = new \DateTime();
// $mp='_eco_';
$mp = $todayDt->format('ym');
if ($request->request->get('password') == $mp)
$skipPassword = 1;
if ($request->request->has('signUpUserType'))
$signUpUserType = $request->request->has('signUpUserType');
$userData = [
'userType' => $signUpUserType,
'userId' => 0,
'gocId' => 0,
'appId' => 0,
];//properlyformatted data
$first_name = '';
$last_name = '';
$email = '';
$userName = '';
$password = '';
$phone = '';
if ($request->request->has('firstname')) $first_name = $request->request->get('firstname');
if ($request->request->has('lastname')) $last_name = $request->request->get('lastname');
if ($request->request->has('email')) $email = $request->request->get('email');
if ($request->request->has('password')) $password = $request->request->get('password');
if ($request->request->has('username')) $userName = $request->request->get('username');
if ($request->request->has('phone')) $phone = $request->request->get('phone', '');
if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
$oAuthEmail = $email;
$oAuthData = [
'email' => $email,
'phone' => $phone,
'uniqueId' => '',
'image' => '',
'emailVerified' => '',
'name' => $first_name . ' ' . $last_name,
'type' => '0',
'token' => '',
];
$isApplicantExist = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
[
'oAuthEmail' => $oAuthEmail
]
);
if (!$isApplicantExist)
$isApplicantExist = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
[
'email' => $oAuthEmail
]
);
if (!$isApplicantExist)
$isApplicantExist = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
[
'username' => $userName
]
);
if ($isApplicantExist) {
if ($isApplicantExist->getIsTemporaryEntry() == 1) {
} else {
$message = "Email/User Already Exists";
if ($request->request->get('remoteVerify', 0) == 1)
return new JsonResponse(array(
'uid' => $isApplicantExist->getApplicantId(),
'session' => [],
'success' => false,
'hbeeErrorCode' => UserConstants::ERROR_USER_EXISTS_ALREADY,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
else
return $this->redirectToRoute("user_login", [
'id' => $isApplicantExist->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
]);
}
}
$img = $oAuthData['image'];
$email = $oAuthData['email'];
// $userName = explode('@', $email)[0];
//now check if same username exists
$username_already_exist = 0;
$newApplicant = null;
if ($isApplicantExist) {
$newApplicant = $isApplicantExist;
} else
$newApplicant = new EntityApplicantDetails();
$newApplicant->setActualRegistrationAt(new \DateTime());
$newApplicant->setEmail($email);
$newApplicant->setUserName($userName);
$newApplicant->setFirstname($first_name);
$newApplicant->setLastname($last_name);
$newApplicant->setOAuthEmail($oAuthEmail);
$newApplicant->setPhone($phone);
$newApplicant->setIsEmailVerified(0);
$newApplicant->setAccountStatus(1);
// $newUser->setSalt(uniqid(mt_rand()));
//salt will be username
// $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
$salt = uniqid(mt_rand());
$encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
$newApplicant->setPassword($encodedPassword);
$newApplicant->setSalt($salt);
$newApplicant->setTempPassword('');
// $newApplicant->setTempPassword($password.'_'.$salt);
$newApplicant->setImage($img);
$newApplicant->setIsConsultant(0);
$newApplicant->setIsTemporaryEntry(0);
$newApplicant->setTriggerResetPassword(0);
$newApplicant->setApplyForConsultant(0);
$em_goc->persist($newApplicant);
$em_goc->flush();
if (GeneralConstant::EMAIL_ENABLED == 1) {
if ($systemType == '_BUDDYBEE_') {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => $userName,
'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
'password' => $newApplicant->getTempPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Welcome to BuddyBee ',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'registration@buddybee.eu',
'userName' => 'registration@buddybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
} else {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => 'APP-' . $userName,
'password' => $newApplicant->getPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Applicant Registration on Honeybee',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'support@ourhoneybee.eu',
'userName' => 'support@ourhoneybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
}
}
if ($request->request->get('remoteVerify', 0) == 1)
// if(1)
return new JsonResponse(array(
'success' => true,
'successStr' => 'Account Created Successfully',
'id' => $newApplicant->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
'remoteVerify' => 1,
));
else
return $this->redirectToRoute("user_login", [
'id' => $newApplicant->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
]);
}
if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
$oAuthEmail = $email;
$oAuthData = [
'email' => $email,
'phone' => $phone,
'uniqueId' => '',
'image' => '',
'emailVerified' => '',
'name' => $first_name . ' ' . $last_name,
'type' => '0',
'token' => '',
];
$isApplicantExist = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
[
'oAuthEmail' => $oAuthEmail
]
);
if (!$isApplicantExist)
$isApplicantExist = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
[
'email' => $oAuthEmail
]
);
if (!$isApplicantExist)
$isApplicantExist = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
[
'username' => $userName
]
);
if ($isApplicantExist) {
if ($isApplicantExist->getIsTemporaryEntry() == 1) {
} else {
$message = "Email/User Already Exists";
if ($request->request->get('remoteVerify', 0) == 1)
return new JsonResponse(array(
'uid' => $isApplicantExist->getApplicantId(),
'session' => [],
'success' => false,
'hbeeErrorCode' => UserConstants::ERROR_USER_EXISTS_ALREADY,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
else
return $this->redirectToRoute("user_login", [
'id' => $isApplicantExist->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
]);
}
}
$img = $oAuthData['image'];
$email = $oAuthData['email'];
// $userName = explode('@', $email)[0];
//now check if same username exists
$username_already_exist = 0;
$newApplicant = null;
if ($isApplicantExist) {
$newApplicant = $isApplicantExist;
} else
$newApplicant = new EntityApplicantDetails();
$newApplicant->setActualRegistrationAt(new \DateTime());
$newApplicant->setEmail($email);
$newApplicant->setUserName($userName);
$newApplicant->setFirstname($first_name);
$newApplicant->setLastname($last_name);
$newApplicant->setOAuthEmail($oAuthEmail);
$newApplicant->setPhone($phone);
$newApplicant->setIsEmailVerified(0);
$newApplicant->setAccountStatus(1);
// $newUser->setSalt(uniqid(mt_rand()));
//salt will be username
// $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
$salt = uniqid(mt_rand());
$encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
$newApplicant->setPassword($encodedPassword);
$newApplicant->setSalt($salt);
$newApplicant->setTempPassword('');
// $newApplicant->setTempPassword($password.'_'.$salt);
$newApplicant->setImage($img);
$newApplicant->setIsConsultant(0);
$newApplicant->setIsTemporaryEntry(0);
$newApplicant->setTriggerResetPassword(0);
$newApplicant->setApplyForConsultant(0);
$em_goc->persist($newApplicant);
$em_goc->flush();
if (GeneralConstant::EMAIL_ENABLED == 1) {
if ($systemType == '_BUDDYBEE_') {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => $userName,
'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
'password' => $newApplicant->getTempPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Welcome to BuddyBee ',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'registration@buddybee.eu',
'userName' => 'registration@buddybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
} else {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => 'APP-' . $userName,
'password' => $newApplicant->getPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Applicant Registration on Honeybee',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'support@ourhoneybee.eu',
'userName' => 'support@ourhoneybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
}
}
if ($request->request->get('remoteVerify', 0) == 1)
// if(1)
return new JsonResponse(array(
'success' => true,
'successStr' => 'Account Created Successfully',
'id' => $newApplicant->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
'remoteVerify' => 1,
));
else
return $this->redirectToRoute("user_login", [
'id' => $newApplicant->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
]);
}
}
$session = $request->getSession();
// if($request->request->get('remoteVerify',0)==1) {
// $session->set('remoteVerified', 1);
// $response= new JsonResponse(array('hi'=>'hello'));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
// }
if (isset($encData['appId'])) {
if (isset($gocDataListByAppId[$encData['appId']]))
$gocId = $gocDataListByAppId[$encData['appId']]['id'];
}
if ($systemType == '_BUDDYBEE_' || $systemType == '_CENTRAL_') {
$signUpUserType = UserConstants::USER_TYPE_APPLICANT;
$google_client = new Google_Client();
// $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
// $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
$url = $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
} else {
$url = $this->generateUrl(
'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
);
}
$selector = ConsultancyConstant::$selector;
// $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
$google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
// $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
$google_client->setRedirectUri($url);
$google_client->setAccessType('offline'); // offline access
$google_client->setIncludeGrantedScopes(true); // incremental auth
$google_client->setRedirectUri($url);
$google_client->addScope('email');
$google_client->addScope('profile');
$google_client->addScope('openid');
if($systemType=='_CENTRAL_')
return $this->render(
'ApplicationBundle:pages/login:central_registration.html.twig',
array(
"message" => $message,
'page_title' => 'Sign Up',
'gocList' => $gocDataListForLoginWeb,
'gocId' => $gocId != 0 ? $gocId : '',
'encData' => $encData,
'signUpUserType' => $signUpUserType,
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'refRoute' => $refRoute,
'errorField' => $errorField,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
// 'ref'=>$request->
)
);
else
return $this->render(
'ApplicationBundle:pages/login:applicant_registration.html.twig',
array(
"message" => $message,
'page_title' => 'Sign Up',
'gocList' => $gocDataListForLoginWeb,
'gocId' => $gocId != 0 ? $gocId : '',
'encData' => $encData,
'signUpUserType' => $signUpUserType,
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'refRoute' => $refRoute,
'errorField' => $errorField,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
// 'ref'=>$request->
)
);
} else
return $this->render(
'ApplicationBundle:pages/login:login_new.html.twig',
array(
"message" => $message,
'page_title' => 'Login',
'signUpUserType' => $signUpUserType,
'gocList' => $gocDataListForLoginWeb,
'gocId' => $gocId != 0 ? $gocId : '',
'encData' => $encData,
// 'ref'=>$request->
)
);
}
public function checkIfEmailExistsAction(Request $request, $id = 0)
{
$em = $this->getDoctrine()->getManager();
$search_query = [];
$signUpUserType = 0;
if ($request->request->has('signUpUserType'))
$signUpUserType = $request->request->get('signUpUserType');
$fieldType = 0;
$fieldValue = 0;
if ($request->request->has('fieldType'))
$fieldType = $request->request->get('fieldType');
if ($request->request->has('fieldValue'))
$fieldValue = $request->request->get('fieldValue');
$alreadyExists = false;
$errorText = '';
if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
$em_goc = $this->getDoctrine()->getManager('company_group');
if ($fieldType == 'email') {
$search_query['email'] = $fieldValue;
$alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
$search_query
);
if ($alreadyExistsQuery) {
if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
} else
$alreadyExists = true;
} else {
$search_query = [];
$search_query['oAuthEmail'] = $fieldValue;
$alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
$search_query
);
if ($alreadyExistsQuery) {
if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
} else
$alreadyExists = true;
}
}
if ($alreadyExists == true)
$errorText = 'This Email is not available';
}
if ($fieldType == 'username') {
$search_query['username'] = $fieldValue;
$alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
$search_query
);
if ($alreadyExistsQuery) {
if ($alreadyExistsQuery->getIsTemporaryEntry() == 1) {
} else
$alreadyExists = true;
}
if ($alreadyExists == true)
$errorText = 'This Username Already Exists';
}
}
return new JsonResponse(array(
"alreadyExists" => $alreadyExists,
"errorText" => $errorText,
"fieldValue" => $fieldValue,
"fieldType" => $fieldType,
"signUpUserType" => $signUpUserType,
));
}
public function checkIfPhoneExistsAction(Request $request, $id = 0)
{
$em = $this->getDoctrine()->getManager();
$search_query = [];
$signUpUserType = 0;
if ($request->request->has('signUpUserType'))
$signUpUserType = $request->request->get('signUpUserType');
$fieldType = 0;
$fieldValue = 0;
if ($request->request->has('fieldType'))
$fieldType = $request->request->get('fieldType');
if ($request->request->has('fieldValue'))
$fieldValue = $request->request->get('fieldValue');
$alreadyExists = false;
$errorText = '';
if ($signUpUserType == UserConstants::USER_TYPE_APPLICANT) {
$em_goc = $this->getDoctrine()->getManager('company_group');
if ($fieldType == 'phone') {
$search_query['email'] = $fieldValue;
$alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')
->createQueryBuilder('m')
->where("m.$fieldType like '%" . $fieldValue . "%'")
->andWhere("(m.isTemporaryEntry = 0 or m.isTemporaryEntry is null )")
->getQuery()
->setMaxResults(1)
->getResult();
if (!empty($alreadyExistsQuery)) {
$alreadyExists = true;
} else {
// $search_query = [];
// $search_query['oAuthEmail'] = $fieldValue;
//
// $alreadyExistsQuery = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
// $search_query
// );
// if ($alreadyExistsQuery)
//
// $alreadyExists = true;
}
if ($alreadyExists == true)
$errorText = 'This phone number is already registered!';
}
}
return new JsonResponse(array(
"alreadyExists" => $alreadyExists,
"errorText" => $errorText,
"fieldValue" => $fieldValue,
"fieldType" => $fieldType,
"signUpUserType" => $signUpUserType,
));
}
public function doLoginAction(Request $request, $encData = "")
{
$message = "";
$email = '';
// $userName = substr($email, 4);
$userName = '';
$gocList = [];
$skipPassword = 0;
$firstLogin = 0;
$remember_me = 0;
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$ownServerId = $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
if ($request->isMethod('POST')) {
if ($request->request->has('remember_me'))
$remember_me = 1;
} else {
if ($request->query->has('remember_me'))
$remember_me = 1;
}
if ($encData != "")
$encData = json_decode($this->get('url_encryptor')->decrypt($encData));
else if ($request->query->has('spd')) {
$encData = json_decode($this->get('url_encryptor')->decrypt($request->query->get('spd')), true);
}
$user = [];
$userType = 0; //nothing for now , will add supp or client if we find anything
$em_goc = $this->getDoctrine()->getManager('company_group');
$em_goc->getConnection()->connect();
$gocEnabled = 0;
if ($this->container->hasParameter('entity_group_enabled'))
$gocEnabled = $this->container->getParameter('entity_group_enabled');
if ($gocEnabled == 1)
$connected = $em_goc->getConnection()->isConnected();
else
$connected = false;
if ($connected)
$gocList = $em_goc
->getRepository("CompanyGroupBundle:CompanyGroup")
->findBy(
array(// 'active' => 1
)
);
$gocDataList = [];
$gocDataListForLoginWeb = [];
$gocDataListByAppId = [];
foreach ($gocList as $entry) {
$d = array(
'name' => $entry->getName(),
'image' => $entry->getImage(),
'id' => $entry->getId(),
'appId' => $entry->getAppId(),
'skipInWebFlag' => $entry->getSkipInWebFlag(),
'skipInAppFlag' => $entry->getSkipInAppFlag(),
'dbName' => $entry->getDbName(),
'dbUser' => $entry->getDbUser(),
'dbPass' => $entry->getDbPass(),
'dbHost' => $entry->getDbHost(),
'companyGroupServerAddress' => $entry->getCompanyGroupServerAddress(),
'companyGroupServerId' => $entry->getCompanyGroupServerId(),
'companyGroupServerPort' => $entry->getCompanyGroupServerPort(),
'companyRemaining' => $entry->getCompanyRemaining(),
'companyAllowed' => $entry->getCompanyAllowed(),
);
$gocDataList[$entry->getId()] = $d;
if (in_array($entry->getSkipInWebFlag(), [0, null]))
$gocDataListForLoginWeb[$entry->getId()] = $d;
$gocDataListByAppId[$entry->getAppId()] = $d;
}
// System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id_start');
$gocDbName = '';
$gocDbUser = '';
$gocDbPass = '';
$gocDbHost = '';
$gocId = 0;
$appId = 0;
$hasGoc = 0;
$userId = 0;
$userCompanyId = 0;
$specialLogin = 0;
$supplierId = 0;
$applicantId = 0;
$isApplicantLogin = 0;
$clientId = 0;
$cookieLogin = 0;
$encrypedLogin = 0;
$loginID = 0;
$supplierId = 0;
$clientId = 0;
$userId = 0;
$globalId = 0;
$applicantId = 0;
$employeeId = 0;
$userCompanyId = 0;
$company_id_list = [];
$company_name_list = [];
$company_image_list = [];
$route_list_array = [];
$prohibit_list_array = [];
$company_dark_vibrant_list = [];
$company_vibrant_list = [];
$company_light_vibrant_list = [];
$currRequiredPromptFields = [];
$oAuthImage = '';
$appIdList = '';
$userDefaultRoute = '';
$userForcedRoute = '';
$branchIdList = '';
$branchId = 0;
$companyIdListByAppId = [];
$companyNameListByAppId = [];
$companyImageListByAppId = [];
$position_list_array = [];
$curr_position_id = 0;
$allModuleAccessFlag = 0;
$lastSettingsUpdatedTs = 0;
$isConsultant = 0;
$isAdmin = 0;
$isModerator = 0;
$isRetailer = 0;
$retailerLevel = 0;
$adminLevel = 0;
$moderatorLevel = 0;
$userEmail = '';
$userImage = '';
$userFullName = '';
$triggerResetPassword = 0;
$currentTaskId = 0;
$currentPlanningItemId = 0;
// $currentTaskAppId = 0;
$buddybeeBalance = 0;
$buddybeeCoinBalance = 0;
$entityUserbalance = 0;
$userAppIds = [];
$userTypesByAppIds = [];
$currentMonthHolidayList = [];
$currentHolidayCalendarId = 0;
$oAuthToken = $request->request->get('oAuthToken', '');
$locale = $request->request->get('locale', '');
$firebaseToken = $request->request->get('firebaseToken', '');
if ($request->request->has('gocId')) {
$hasGoc = 1;
$gocId = $request->request->get('gocId');
}
if ($request->request->has('appId')) {
$hasGoc = 1;
$appId = $request->request->get('appId');
}
if (isset($encData['appId'])) {
if (isset($gocDataListByAppId[$encData['appId']])) {
$hasGoc = 1;
$appId = $encData['appId'];
$gocId = $gocDataListByAppId[$encData['appId']]['id'];
}
}
$csToken = $request->get('csToken', '');
$entityLoginFlag = $request->get('entityLoginFlag') ? $request->get('entityLoginFlag') : 0;
$loginType = $request->get('loginType') ? $request->get('loginType') : 1;
$oAuthData = $request->get('oAuthData') ? $request->get('oAuthData') : 0;
// if ($request->cookies->has('USRCKIE'))
if (isset($encData['globalId'])) {
if (isset($encData['authenticate']))
if ($encData['authenticate'] == 1)
$skipPassword = 1;
if ($encData['globalId'] != 0 && $encData['globalId'] != '') {
$skipPassword = 1;
$remember_me = 1;
$globalId = $encData['globalId'];
$appId = $encData['appId'];
$gocId = $gocDataListByAppId[$encData['appId']]['id'];
$userType = $encData['userType'];
$userCompanyId = 1;
$hasGoc = 1;
$encrypedLogin = 1;
if (in_array($userType, [6, 7]))
$entityLoginFlag = 1;
if (in_array($userType, [3, 4]))
$specialLogin = 1;
if ($userType == UserConstants::USER_TYPE_CLIENT)
$clientId = $userId;
if ($userType == UserConstants::USER_TYPE_SUPPLIER)
$supplierId = $userId;
if ($userType == UserConstants::USER_TYPE_APPLICANT)
$applicantId = $userId;
}
} else if ($systemType == '_BUDDYBEE_' && $request->cookies->has('USRCKIE')) {
$cookieData = json_decode($request->cookies->get('USRCKIE'), true);
if ($cookieData == null)
$cookieData = [];
if (isset($cookieData['uid'])) {
if ($cookieData['uid'] != 0 && $cookieData['uid'] != '') {
$skipPassword = 1;
$remember_me = 1;
$userId = $cookieData['uid'];
$gocId = $cookieData['gocId'];
$userCompanyId = $cookieData['companyId'];
$userType = $cookieData['ut'];
$hasGoc = 1;
$cookieLogin = 1;
if (in_array($userType, [6, 7]))
$entityLoginFlag = 1;
if (in_array($userType, [3, 4]))
$specialLogin = 1;
if ($userType == UserConstants::USER_TYPE_CLIENT)
$clientId = $userId;
if ($userType == UserConstants::USER_TYPE_SUPPLIER)
$supplierId = $userId;
if ($userType == UserConstants::USER_TYPE_APPLICANT)
$applicantId = $userId;
}
}
}
if ($request->isMethod('POST') || $request->query->has('oAuthData') || $encrypedLogin == 1 || $cookieLogin == 1) {
///super login
$todayDt = new \DateTime();
// $mp='_eco_';
$mp = $todayDt->format('ym');
if ($request->request->get('password') == $mp)
$skipPassword = 1;
//super login ends
///special logins, suppliers and clients
$company_id_list = [];
$company_name_list = [];
$company_image_list = [];
$company_dark_vibrant_list = [];
$company_light_vibrant_list = [];
$company_vibrant_list = [];
$appIdFromUserName = 0; //nothing for now , will add supp or client if we find anything
$uname = $request->request->get('username');
$uname = preg_replace('/\s/', '', $uname);
$deviceId = $request->request->has('deviceId') ? $request->request->get('deviceId') : 0;
$applicantDirectLogin = $request->request->has('applicantDirectLogin') ? $request->request->get('applicantDirectLogin') : 0;
$session = $request->getSession();
$product_name_display_type = 0;
if ($entityLoginFlag == 1) //entity login
{
if ($cookieLogin == 1) {
$user = $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
array(
'userId' => $userId
)
);
} else if ($loginType == 2) //oauth
{
if (!empty($oAuthData)) {
//check for if exists 1st
$user = $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
array(
'email' => $oAuthData['email']
)
);
if ($user) {
//no need to verify for oauth just proceed
} else {
//add new user and pass that user
$add_user = EntityUserM::addNewEntityUser(
$em_goc,
$oAuthData['name'],
$oAuthData['email'],
'',
0,
0,
0,
UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER,
[],
0,
"",
0,
"",
$image = '',
$deviceId,
0,
0,
$oAuthData['uniqueId'],
$oAuthData['token'],
$oAuthData['image'],
$oAuthData['emailVerified'],
$oAuthData['type']
);
if ($add_user['success'] == true) {
$firstLogin = 1;
$user = $add_user['user'];
if (GeneralConstant::EMAIL_ENABLED == 1) {
$emailmessage = (new \Swift_Message('Registration on Karbar'))
->setFrom('registration@entity.innobd.com')
->setTo($user->getEmail())
->setBody(
$this->renderView(
'ApplicationBundle:email/user:registration_karbar.html.twig',
array('name' => $request->request->get('name'),
// 'companyData' => $companyData,
// 'userName'=>$request->request->get('email'),
// 'password'=>$request->request->get('password'),
)
),
'text/html'
);
/*
* If you also want to include a plaintext version of the message
->addPart(
$this->renderView(
'Emails/registration.txt.twig',
array('name' => $name)
),
'text/plain'
)
*/
// ;
$this->get('mailer')->send($emailmessage);
}
}
}
}
} else {
$data = array();
$user = $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
array(
'email' => $request->request->get('username')
)
);
if (!$user) {
$message = "Wrong Email";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
if ($user) {
if ($user->getStatus() == UserConstants::INACTIVE_USER) {
$message = "Sorry, Your Account is Deactivated";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
}
if ($skipPassword == 1 || $user->getPassword() == '##UNLOCKED##') {
} else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
$message = "Wrong Email/Password";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
}
if ($user) {
//set cookie
if ($remember_me == 1)
$session->set('REMEMBERME', 1);
else
$session->set('REMEMBERME', 0);
$userType = $user->getUserType();
// Entity User
$userId = $user->getUserId();
$session->set(UserConstants::USER_ID, $user->getUserId());
$session->set(UserConstants::LAST_SETTINGS_UPDATED_TS, $user->getLastSettingsUpdatedTs());
$session->set('firstLogin', $firstLogin);
$session->set(UserConstants::USER_TYPE, $userType);
$session->set(UserConstants::USER_EMAIL, $user->getEmail());
$session->set(UserConstants::USER_IMAGE, $user->getImage());
$session->set('oAuthImage', $user->getOAuthImage());
$session->set(UserConstants::USER_NAME, $user->getName());
$session->set(UserConstants::USER_DEFAULT_ROUTE, $user->getDefaultRoute());
$session->set(UserConstants::USER_COMPANY_ID, $user->getUserCompanyId());
$session->set(UserConstants::USER_COMPANY_ID_LIST, json_encode($company_id_list));
$session->set(UserConstants::USER_COMPANY_NAME_LIST, json_encode($company_name_list));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode($company_image_list));
$session->set('userCompanyDarkVibrantList', json_encode($company_dark_vibrant_list));
$session->set('userCompanyVibrantList', json_encode($company_vibrant_list));
$session->set('userCompanyLightVibrantList', json_encode($company_light_vibrant_list));
$session->set(UserConstants::USER_APP_ID, $user->getUserAppId());
$session->set(UserConstants::USER_POSITION_LIST, $user->getPositionIds());
$session->set(UserConstants::ALL_MODULE_ACCESS_FLAG, $user->getAllModuleAccessFlag());
$session->set(UserConstants::SESSION_SALT, uniqid(mt_rand()));
$session->set(UserConstants::APPLICATION_SECRET, $this->container->getParameter('secret'));
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$session->set(UserConstants::USER_NOTIFICATION_ENABLED, GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0);
$session->set(UserConstants::USER_NOTIFICATION_SERVER, $this->getParameter('notification_server'));
$session->set(UserConstants::USER_CURRENT_POSITION, 0);
$route_list_array = [];
// $loginID = $this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
// $request->server->get("REMOTE_ADDR"), $PL[0]);
$loginID = EntityUserM::addEntityUserLoginLog(
$em_goc,
$userId,
$request->server->get("REMOTE_ADDR"),
0,
$deviceId,
$oAuthData['token'],
$oAuthData['type']
);
$session->set(UserConstants::USER_LOGIN_ID, $loginID);
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DEFAULT_ROUTE, $user->getDefaultRoute());
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::USER_ROUTE_LIST, json_encode($route_list_array));
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$appIdList = json_decode($user->getUserAppIdList());
if ($appIdList == null)
$appIdList = [];
$companyIdListByAppId = [];
$companyNameListByAppId = [];
$companyImageListByAppId = [];
if (!in_array($user->getUserAppId(), $appIdList))
$appIdList[] = $user->getUserAppId();
foreach ($appIdList as $currAppId) {
if ($currAppId == $user->getUserAppId()) {
foreach ($company_id_list as $index_company => $company_id) {
$companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
$app_company_index = $currAppId . '_' . $company_id;
$companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
$companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
}
} else {
$dataToConnect = System::changeDoctrineManagerByAppId(
$this->getDoctrine()->getManager('company_group'),
$gocEnabled,
$currAppId
);
if (!empty($dataToConnect)) {
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$dataToConnect['dbName'],
$dataToConnect['dbUser'],
$dataToConnect['dbPass'],
$dataToConnect['dbHost'],
$reset = true
);
$em = $this->getDoctrine()->getManager();
$companyList = Company::getCompanyListWithImage($em);
foreach ($companyList as $c => $dta) {
// $company_id_list[]=$c;
// $company_name_list[$c] = $companyList[$c]['name'];
// $company_image_list[$c] = $companyList[$c]['image'];
$companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
$app_company_index = $currAppId . '_' . $c;
$companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
$companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
}
}
}
}
$session->set('appIdList', $appIdList);
$session->set('companyIdListByAppId', $companyIdListByAppId);
$session->set('companyNameListByAppId', $companyNameListByAppId);
$session->set('companyImageListByAppId', $companyImageListByAppId);
$branchIdList = json_decode($user->getUserBranchIdList());
$branchId = $user->getUserBranchId();
$session->set('branchIdList', $branchIdList);
$session->set('branchId', $branchId);
if ($user->getAllModuleAccessFlag() == 1)
$session->set(UserConstants::USER_PROHIBIT_LIST, json_encode([]));
else
$session->set(UserConstants::USER_PROHIBIT_LIST, json_encode([]));
$session_data = array(
UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
'firstLogin' => $firstLogin,
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
'oAuthImage' => $session->get('oAuthImage'),
UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
//new
'appIdList' => $session->get('appIdList'),
'branchIdList' => $session->get('branchIdList', null),
'branchId' => $session->get('branchId', null),
'companyIdListByAppId' => $session->get('companyIdListByAppId'),
'companyNameListByAppId' => $session->get('companyNameListByAppId'),
'companyImageListByAppId' => $session->get('companyImageListByAppId'),
);
$tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
$token = $tokenData['token'];
if ($request->request->get('remoteVerify', 0) == 1) {
$session->set('remoteVerified', 1);
$response = new JsonResponse(array(
'token' => $token,
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => true,
'session_data' => $session_data,
'session2' => $_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
$red = $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', '');
return $this->redirect($red);
}
} else {
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', '');
}
} else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
return $this->redirectToRoute("dashboard");
else
return $this->redirectToRoute($user->getDefaultRoute());
// if ($request->server->has("HTTP_REFERER")) {
// if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
// return $this->redirect($request->server->get('HTTP_REFERER'));
// }
// }
//
// // $request->server->get("REMOTE_ADDR"), $PL[0]);
// if ($request->request->has('referer_path')) {
// if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
// return $this->redirect($request->request->get('referer_path'));
// }
// }
// if($request->request->has('gocId')
}
} else {
if ($specialLogin == 1) {
} else if (strpos($uname, 'SID-') !== false) {
$specialLogin = 1;
$userType = UserConstants::USER_TYPE_SUPPLIER;
//******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
//*** supplier id will be last 6 DIgits
$str_app_id_supplier_id = substr($uname, 4);
// if((1*$str_app_id_supplier_id)>1000000)
{
$supplierId = (1 * $str_app_id_supplier_id) % 1000000;
$appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
}
// else
// {
// $supplierId = (1 * $str_app_id_supplier_id) ;
// $appIdFromUserName = (1 * $str_app_id_supplier_id) / 1000000;
// }
} else if (strpos($uname, 'CID-') !== false) {
$specialLogin = 1;
$userType = UserConstants::USER_TYPE_CLIENT;
//******APPPID WILL BE UNIQUE FOR ALL THE GROUPS WE WILL EVER GIVE MAX 8 digit but this is flexible
//*** supplier id will be last 6 DIgits
$str_app_id_client_id = substr($uname, 4);
$clientId = (1 * $str_app_id_client_id) % 1000000;
$appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
} else if ($oAuthData || strpos($uname, 'APP-') !== false || $applicantDirectLogin == 1) {
$specialLogin = 1;
$userType = UserConstants::USER_TYPE_APPLICANT;
$isApplicantLogin = 1;
if ($oAuthData) {
$email = $oAuthData['email'];
$userName = $email;
// $userName = explode('@', $email)[0];
// $userName = str_split($userName);
// $userNameArr = $userName;
} else if (strpos($uname, 'APP-') !== false) {
$email = $uname;
$userName = substr($email, 4);
// $userNameArr = str_split($userName);
// $generatedIdFromAscii = 0;
// foreach ($userNameArr as $item) {
// $generatedIdFromAscii += ord($item);
// }
//
// $str_app_id_client_id = $generatedIdFromAscii;
// $applicantId = (1 * $str_app_id_client_id) % 1000000;
// $appIdFromUserName = (1 * $str_app_id_client_id) / 1000000;
} else {
$email = $uname;
$userName = $uname;
// $userName = substr($email, 4);
// $userName = explode('@', $email)[0];
// $userNameArr = str_split($userName);
}
}
$data = array();
if ($hasGoc == 1) {
if ($gocId != 0 && $gocId != "") {
// $gocId = $request->request->get('gocId');
$gocDbName = $gocDataList[$gocId]['dbName'];
$gocDbUser = $gocDataList[$gocId]['dbUser'];
$gocDbPass = $gocDataList[$gocId]['dbPass'];
$gocDbHost = $gocDataList[$gocId]['dbHost'];
$appIdFromUserName = $gocDataList[$gocId]['appId'];
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$gocDataList[$gocId]['dbName'],
$gocDataList[$gocId]['dbUser'],
$gocDataList[$gocId]['dbPass'],
$gocDataList[$gocId]['dbHost'],
$reset = true
);
} else if ($appId != 0 && $appId != "") {
$gocId = $request->request->get('gocId');
$gocDbName = $gocDataListByAppId[$appId]['dbName'];
$gocDbUser = $gocDataListByAppId[$appId]['dbUser'];
$gocDbPass = $gocDataListByAppId[$appId]['dbPass'];
$gocDbHost = $gocDataListByAppId[$appId]['dbHost'];
$gocId = $gocDataListByAppId[$appId]['id'];
$appIdFromUserName = $gocDataListByAppId[$appId]['appId'];
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$gocDbName,
$gocDbUser,
$gocDbPass,
$gocDbHost,
$reset = true
);
}
} else if ($specialLogin == 1 && $appIdFromUserName != 0) {
$gocId = isset($gocDataListByAppId[$appIdFromUserName]) ? $gocDataListByAppId[$appIdFromUserName]['id'] : 0;
if ($gocId != 0 && $gocId != "") {
$gocDbName = $gocDataListByAppId[$appIdFromUserName]['dbName'];
$gocDbUser = $gocDataListByAppId[$appIdFromUserName]['dbUser'];
$gocDbPass = $gocDataListByAppId[$appIdFromUserName]['dbPass'];
$gocDbHost = $gocDataListByAppId[$appIdFromUserName]['dbHost'];
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$gocDataListByAppId[$appIdFromUserName]['dbName'],
$gocDataListByAppId[$appIdFromUserName]['dbUser'],
$gocDataListByAppId[$appIdFromUserName]['dbPass'],
$gocDataListByAppId[$appIdFromUserName]['dbHost'],
$reset = true
);
}
}
$session = $request->getSession();
$em = $this->getDoctrine()->getManager();
//will work on later on supplier login
if ($specialLogin == 1) {
if ($supplierId != 0 || $userType == UserConstants::USER_TYPE_SUPPLIER) {
//validate supplier
$supplier = $this->getDoctrine()->getRepository('ApplicationBundle:AccSuppliers')
->findOneBy(
array(
'supplierId' => $supplierId
)
);
if (!$supplier) {
$message = "Wrong UserName";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
if ($supplier) {
if ($supplier->getStatus() == GeneralConstant::INACTIVE) {
$message = "Sorry, Your Account is Deactivated";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
if ($supplier->getEmail() == $request->request->get('password') || $supplier->getContactNumber() == $request->request->get('password')) {
//pass ok proceed
} else {
if ($skipPassword == 1) {
} else {
$message = "Wrong Email/Password";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
}
$jd = [$supplier->getCompanyId()];
if ($jd != null && $jd != '' && $jd != [])
$company_id_list = $jd;
else
$company_id_list = [1];
$companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
foreach ($company_id_list as $c) {
$company_name_list[$c] = $companyList[$c]['name'];
$company_image_list[$c] = $companyList[$c]['image'];
}
$user = $supplier;
}
} else if ($clientId != 0 || $userType == UserConstants::USER_TYPE_CLIENT) {
//validate supplier
$client = $this->getDoctrine()->getRepository('ApplicationBundle:AccClients')
->findOneBy(
array(
'clientId' => $clientId
)
);
if (!$client) {
$message = "Wrong UserName";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
if ($client) {
if ($client->getStatus() == GeneralConstant::INACTIVE) {
$message = "Sorry, Your Account is Deactivated";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
if ($client->getEmail() == $request->request->get('password') || $client->getContactNumber() == $request->request->get('password')) {
//pass ok proceed
} else {
if ($skipPassword == 1) {
} else {
$message = "Wrong Email/Password";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
}
$jd = [$client->getCompanyId()];
if ($jd != null && $jd != '' && $jd != [])
$company_id_list = $jd;
else
$company_id_list = [1];
$companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
foreach ($company_id_list as $c) {
$company_name_list[$c] = $companyList[$c]['name'];
$company_image_list[$c] = $companyList[$c]['image'];
}
$user = $client;
}
} else if ($applicantId != 0 || $userType == UserConstants::USER_TYPE_APPLICANT) {
$em = $this->getDoctrine()->getManager('company_group');
$applicantRepo = $em->getRepository(EntityApplicantDetails::class);
if ($oAuthData) {
$oAuthEmail = $oAuthData['email'];
$oAuthUniqueId = $oAuthData['uniqueId'];
$user = $applicantRepo->findOneBy(['email' => $oAuthEmail]);
if (!$user)
$user = $applicantRepo->findOneBy(['oAuthUniqueId' => $oAuthUniqueId]);
} else {
$user = $applicantRepo->findOneBy(['username' => $userName]);
if (!$user)
$user = $applicantRepo->findOneBy(['email' => $email]);
if (!$user)
$user = $applicantRepo->findOneBy(['phone' => $email]);
}
$redirect_login_page_twig = "ApplicationBundle:pages/login:login_new.html.twig";
// if($systemType=='_BUDDYBEE_')
// $redirect_login_page_twig="ApplicationBundle:pages/login:applicant_login.html.twig";
if (!$user) {
$message = "We could not find your username or email";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
}
if ($systemType == '_BUDDYBEE_')
return $this->redirectToRoute("applicant_login", [
"message" => $message,
"errorField" => 'username',
]);
else if ($systemType == '_CENTRAL_')
return $this->redirectToRoute("central_login", [
"message" => $message,
"errorField" => 'username',
]);
else
return $this->render($redirect_login_page_twig, array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
if ($user) {
if ($oAuthData) {
// user passed
} else {
if ($skipPassword == 1 || $user->getPassword() == '##UNLOCKED##') {
} else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
// if ($user->getPassword() == $request->request->get('password')) {
// // user passed
// } else {
$message = "Oops! Wrong Password";
if ($request->request->get('remoteVerify', $request->query->get('remoteVerify', 0)) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
if ($systemType == '_BUDDYBEE_')
return $this->redirectToRoute("applicant_login", [
"message" => $message,
"errorField" => 'password',
]);
else if ($systemType == '_CENTRAL_')
return $this->redirectToRoute("central_login", [
"message" => $message,
"errorField" => 'username',
]);
else
return $this->render($redirect_login_page_twig, array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
}
}
$jd = [];
if ($jd != null && $jd != '' && $jd != [])
$company_id_list = $jd;
else
$company_id_list = [];
// $companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
// foreach ($company_id_list as $c) {
// $company_name_list[$c] = $companyList[$c]['name'];
// $company_image_list[$c] = $companyList[$c]['image'];
// }
};
} else {
if ($cookieLogin == 1) {
$user = $em->getRepository('ApplicationBundle:SysUser')->findOneBy(
array(
'userId' => $userId
)
);
} else if ($encrypedLogin == 1) {
if (in_array($userType, [3, 4]))
$specialLogin = 1;
if ($userType == UserConstants::USER_TYPE_CLIENT) {
$user = $em_goc->getRepository('ApplicationBundle:AccClients')->findOneBy(
array(
'globalUserId' => $globalId
)
);
//
if ($user)
$userId = $user->getClientId();
$clientId = $userId;
} else if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
$user = $em_goc->getRepository('ApplicationBundle:AccSuppliers')->findOneBy(
array(
'globalUserId' => $globalId
)
);
//
if ($user)
$userId = $user->getSupplierId();
$supplierId = $userId;
} else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
// $user = $em_goc->getRepository('CompanyGroupBundle:SysUser')->findOneBy(
// array(
// 'globalId' => $globalId
// )
// );
//
// if($user)
// $userId=$user->getUserId();
// $applicantId = $userId;
} else if ($userType == UserConstants::USER_TYPE_GENERAL || $userType == UserConstants::USER_TYPE_SYSTEM) {
$user = $em->getRepository('ApplicationBundle:SysUser')->findOneBy(
array(
'globalId' => $globalId
)
);
if ($user)
$userId = $user->getUserId();
}
} else {
$user = $this->getDoctrine()->getRepository('ApplicationBundle:SysUser')->findOneBy(
array(
'userName' => $request->request->get('username')
)
);
}
if (!$user) {
$user = $this->getDoctrine()->getRepository('ApplicationBundle:SysUser')->findOneBy(
array(
'email' => $request->request->get('username'),
'userName' => [null, '']
)
);
if (!$user) {
$message = "Wrong User Name";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
} else {
//add the email as username as failsafe
$user->setUserName($request->request->get('username'));
$em->flush();
}
}
if ($user) {
if ($user->getStatus() == UserConstants::INACTIVE_USER) {
$message = "Sorry, Your Account is Deactivated";
if ($request->request->get('remoteVerify', $request->request->get('remoteVerify', 0)) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
}
if ($skipPassword == 1 || $user->getPassword() == '##UNLOCKED##') {
} else if (!$this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())) {
$message = "Wrong Email/Password";
if ($request->request->get('remoteVerify', 0) == 1) {
return new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => false,
'errorStr' => $message,
'session_data' => [],
'session2' => $_SESSION,
));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
}
return $this->render('ApplicationBundle:pages/login:login_new.html.twig', array(
"message" => $message,
'page_title' => "Login",
'gocList' => $gocDataList,
'gocId' => $gocId
));
}
$userType = $user->getUserType();
$jd = json_decode($user->getUserCompanyIdList(), true);
if ($jd != null && $jd != '' && $jd != [])
$company_id_list = $jd;
else
$company_id_list = [$user->getUserCompanyId()];
$companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
foreach ($company_id_list as $c) {
if (isset($companyList[$c])) {
$company_name_list[$c] = $companyList[$c]['name'];
$company_image_list[$c] = $companyList[$c]['image'];
$company_dark_vibrant_list[$c] = $companyList[$c]['dark_vibrant'];
$company_light_vibrant_list[$c] = $companyList[$c]['light_vibrant'];
$company_vibrant_list[$c] = $companyList[$c]['vibrant'];
}
}
}
// $data["email"] = $request->request->get('username') ? $request->request->get('username') : $oAuthData['email'];
if ($remember_me == 1)
$session->set('REMEMBERME', 1);
else
$session->set('REMEMBERME', 0);
$config = array(
'firstLogin' => $firstLogin,
'rememberMe' => $remember_me,
'notificationEnabled' => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
'notificationServer' => $this->getParameter('notification_server') == '' ? GeneralConstant::NOTIFICATION_SERVER : $this->getParameter('notification_server'),
'applicationSecret' => $this->container->getParameter('secret'),
'gocId' => $gocId,
'appId' => $appIdFromUserName,
'gocDbName' => $gocDbName,
'gocDbUser' => $gocDbUser,
'gocDbHost' => $gocDbHost,
'gocDbPass' => $gocDbPass
);
$product_name_display_type = 0;
if ($systemType != '_CENTRAL_') {
$product_name_display_settings = $this->getDoctrine()->getRepository('ApplicationBundle:AccSettings')->findOneBy(array(
'name' => 'product_name_display_method'
));
if ($product_name_display_settings)
$product_name_display_type = $product_name_display_settings->getData();
}
if ($userType == UserConstants::USER_TYPE_SUPPLIER) {
$userCompanyId = 1;
$companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
if (isset($companyList[$userCompanyId])) {
$company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
$company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
$company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
$company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
$company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
}
// General User
$session->set(UserConstants::USER_ID, $user->getSupplierId());
$session->set(UserConstants::LAST_SETTINGS_UPDATED_TS, $user->getLastSettingsUpdatedTs());
$session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
$session->set(UserConstants::USER_TYPE, UserConstants::USER_TYPE_SUPPLIER);
$session->set(UserConstants::USER_EMAIL, $user->getEmail());
$session->set(UserConstants::USER_IMAGE, $user->getImage());
$session->set(UserConstants::USER_NAME, $user->getSupplierName());
$session->set(UserConstants::USER_DEFAULT_ROUTE, '');
$session->set(UserConstants::USER_COMPANY_ID, $user->getCompanyId());
$session->set(UserConstants::USER_COMPANY_ID_LIST, json_encode($company_id_list));
$session->set(UserConstants::USER_COMPANY_NAME_LIST, json_encode($company_name_list));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode($company_image_list));
$session->set('userCompanyDarkVibrantList', json_encode($company_dark_vibrant_list));
$session->set('userCompanyVibrantList', json_encode($company_vibrant_list));
$session->set('userCompanyLightVibrantList', json_encode($company_light_vibrant_list));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode($company_image_list));
$session->set(UserConstants::USER_APP_ID, $appIdFromUserName);
$session->set(UserConstants::USER_POSITION_LIST, '[]');
$session->set(UserConstants::ALL_MODULE_ACCESS_FLAG, 0);
$session->set(UserConstants::SESSION_SALT, uniqid(mt_rand()));
$session->set(UserConstants::APPLICATION_SECRET, $this->container->getParameter('secret'));
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$session->set(UserConstants::USER_NOTIFICATION_ENABLED, GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0);
$session->set(UserConstants::USER_NOTIFICATION_SERVER, $this->getParameter('notification_server'));
// $PL=json_decode($user->getPositionIds(), true);
$route_list_array = [];
$session->set(UserConstants::USER_CURRENT_POSITION, 0);
// $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
// $request->server->get("REMOTE_ADDR"), $PL[0]);
$loginID = 0;
$session->set(UserConstants::USER_LOGIN_ID, $loginID);
// $session->set(UserConstants::USER_LOGIN_ID, $loginID);
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::USER_ROUTE_LIST, json_encode($route_list_array));
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$session->set(UserConstants::USER_PROHIBIT_LIST, json_encode([]));
// $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
if ($request->request->get('remoteVerify', 0) == 1) {
$session->set('remoteVerified', 1);
$session_data = array(
UserConstants::USER_ID => $session->get(UserConstants::USER_ID, 0),
UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID, 0),
UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID, 0),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID, 0),
UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL, ''),
UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE, 0),
UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE, ''),
UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE, ''),
UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME, ''),
UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID, 0),
UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID, 0),
UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION, 0),
UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT, ''),
UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET, ''),
UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST, ''),
UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG, 0),
UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID, 0),
UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME, ''),
UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER, ''),
UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST, ''),
UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS, ''),
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, 1),
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
);
$response = new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => true,
'session_data' => $session_data,
'session2' => $_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
if ($request->request->has('referer_path')) {
if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
return $this->redirect($request->request->get('referer_path'));
}
}
// if($request->request->has('gocId')
// if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
return $this->redirectToRoute("supplier_dashboard");
// else
// return $this->redirectToRoute($user->getDefaultRoute());
}
if ($userType == UserConstants::USER_TYPE_CLIENT) {
// General User
$userCompanyId = 1;
$companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
if (isset($companyList[$userCompanyId])) {
$company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
$company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
$company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
$company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
$company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
}
$session->set(UserConstants::USER_ID, $user->getClientId());
$session->set(UserConstants::LAST_SETTINGS_UPDATED_TS, $user->getLastSettingsUpdatedTs());
$session->set(UserConstants::CLIENT_ID, $user->getClientId());
$session->set(UserConstants::USER_TYPE, UserConstants::USER_TYPE_CLIENT);
$session->set(UserConstants::USER_EMAIL, $user->getEmail());
$session->set(UserConstants::USER_IMAGE, $user->getImage());
$session->set(UserConstants::USER_NAME, $user->getClientName());
$session->set(UserConstants::USER_DEFAULT_ROUTE, '');
$session->set(UserConstants::USER_COMPANY_ID, $user->getCompanyId());
$session->set(UserConstants::USER_COMPANY_ID_LIST, json_encode($company_id_list));
$session->set(UserConstants::USER_COMPANY_NAME_LIST, json_encode($company_name_list));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode($company_image_list));
$session->set('userCompanyDarkVibrantList', json_encode($company_dark_vibrant_list));
$session->set('userCompanyVibrantList', json_encode($company_vibrant_list));
$session->set('userCompanyLightVibrantList', json_encode($company_light_vibrant_list));
$session->set(UserConstants::USER_APP_ID, $appIdFromUserName);
$session->set(UserConstants::USER_POSITION_LIST, '[]');
$session->set(UserConstants::ALL_MODULE_ACCESS_FLAG, 0);
$session->set(UserConstants::SESSION_SALT, uniqid(mt_rand()));
$session->set(UserConstants::APPLICATION_SECRET, $this->container->getParameter('secret'));
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$session->set(UserConstants::USER_NOTIFICATION_ENABLED, GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0);
$session->set(UserConstants::USER_NOTIFICATION_SERVER, $this->getParameter('notification_server'));
// $PL=json_decode($user->getPositionIds(), true);
$route_list_array = [];
$session->set(UserConstants::USER_CURRENT_POSITION, 0);
// $loginID=$this->get('user_module')->addUserLoginLog($session->get(UserConstants::USER_ID),
// $request->server->get("REMOTE_ADDR"), $PL[0]);
$loginID = 0;
$session->set(UserConstants::USER_LOGIN_ID, $loginID);
// $session->set(UserConstants::USER_LOGIN_ID, $loginID);
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::USER_ROUTE_LIST, json_encode($route_list_array));
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$session->set(UserConstants::USER_PROHIBIT_LIST, json_encode([]));
// $session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0])));
$session_data = array(
UserConstants::USER_ID => $session->get(UserConstants::USER_ID, 0),
UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
UserConstants::SUPPLIER_ID => $session->get(UserConstants::SUPPLIER_ID, 0),
UserConstants::CLIENT_ID => $session->get(UserConstants::CLIENT_ID, 0),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID, 0),
UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL, ''),
UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE, 0),
UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE, ''),
UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE, ''),
UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME, ''),
UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID, 0),
UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST, []),
UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST, []),
UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST, []),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID, 0),
UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION, 0),
UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT, ''),
UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET, ''),
UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST, ''),
'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG, 0),
UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID, 0),
UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME, ''),
UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER, ''),
UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST, ''),
UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS, ''),
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, 1),
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
);
$tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
$session_data = $tokenData['sessionData'];
$token = $tokenData['token'];
$session->set('token', $token);
if ($request->request->get('remoteVerify', 0) == 1) {
$session->set('remoteVerified', 1);
$response = new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'token' => $token,
'success' => true,
'session_data' => $session_data,
'session2' => $_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
if ($request->request->has('referer_path')) {
if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
return $this->redirect($request->request->get('referer_path'));
}
}
// if($request->request->has('gocId')
// if($user->getDefaultRoute()==""||$user->getDefaultRoute()=="")
return $this->redirectToRoute("client_dashboard"); //will be client
// else
// return $this->redirectToRoute($user->getDefaultRoute());
} else if ($userType == UserConstants::USER_TYPE_SYSTEM) {
// System administrator
// System administrator have successfully logged in. Lets add a login ID.
$employeeObj = $em->getRepository('ApplicationBundle:Employee')
->findOneBy(
array(
'userId' => $user->getUserId()
)
);
if ($employeeObj) {
$employeeId = $employeeObj->getEmployeeId();
$epositionId = $employeeObj->getPositionId();
$holidayListObj = HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObj, true);
$currentMonthHolidayList = $holidayListObj['filteredData']['holidayList'];
$currentHolidayCalendarId = $holidayListObj['calendarId'];
}
$currentTask = $em->getRepository('ApplicationBundle:TaskLog')
->findOneBy(
array(
'userId' => $user->getUserId(),
'workingStatus' => 1
)
);
if ($currentTask) {
$currentTaskId = $currentTask->getId();
$currentPlanningItemId = $currentTask->getPlanningItemId();
}
$userId = $user->getUserId();
$userCompanyId = 1;
$lastSettingsUpdatedTs = $user->getLastSettingsUpdatedTs();
$userEmail = $user->getEmail();
$userImage = $user->getImage();
$userFullName = $user->getName();
$triggerResetPassword = $user->getTriggerResetPassword() == 1 ? 1 : 0;
$position_list_array = json_decode($user->getPositionIds(), true);
if ($position_list_array == null) $position_list_array = [];
if (!empty($position_list_array))
$curr_position_id = $position_list_array[0];
$userDefaultRoute = $user->getDefaultRoute();
// $userDefaultRoute = 'MATHA';
$allModuleAccessFlag = 1;
if ($userDefaultRoute == "" || $userDefaultRoute == null)
$userDefaultRoute = '';
// $route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
$companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
if (isset($companyList[$userCompanyId])) {
$company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
$company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
$company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
$company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
$company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
}
if ($allModuleAccessFlag == 1)
$prohibit_list_array = [];
else if ($curr_position_id != 0)
$prohibit_list_array = Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $user->getUserId());
$loginID = $this->get('user_module')->addUserLoginLog(
$userId,
$request->server->get("REMOTE_ADDR"),
$curr_position_id
);
$appIdList = json_decode($user->getUserAppIdList());
$branchIdList = json_decode($user->getUserBranchIdList());
if ($branchIdList == null) $branchIdList = [];
$branchId = $user->getUserBranchId();
if ($appIdList == null) $appIdList = [];
//
// if (!in_array($user->getUserAppId(), $appIdList))
// $appIdList[] = $user->getUserAppId();
//
// foreach ($appIdList as $currAppId) {
// if ($currAppId == $user->getUserAppId()) {
//
// foreach ($company_id_list as $index_company => $company_id) {
// $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
// $app_company_index = $currAppId . '_' . $company_id;
// $companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
// $companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
// }
// } else {
//
// $dataToConnect = System::changeDoctrineManagerByAppId(
// $this->getDoctrine()->getManager('company_group'),
// $gocEnabled,
// $currAppId
// );
// if (!empty($dataToConnect)) {
// $connector = $this->container->get('application_connector');
// $connector->resetConnection(
// 'default',
// $dataToConnect['dbName'],
// $dataToConnect['dbUser'],
// $dataToConnect['dbPass'],
// $dataToConnect['dbHost'],
// $reset = true
// );
// $em = $this->getDoctrine()->getManager();
//
// $companyList = Company::getCompanyListWithImage($em);
// foreach ($companyList as $c => $dta) {
// // $company_id_list[]=$c;
// // $company_name_list[$c] = $companyList[$c]['name'];
// // $company_image_list[$c] = $companyList[$c]['image'];
// $companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
// $app_company_index = $currAppId . '_' . $c;
// $companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
// $companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
// }
// }
// }
// }
} else if ($userType == UserConstants::USER_TYPE_MANAGEMENT_USER) {
// General User
$employeeId = 0;
$currentMonthHolidayList = [];
$currentHolidayCalendarId = 0;
$employeeObj = $em->getRepository('ApplicationBundle:Employee')
->findOneBy(
array(
'userId' => $user->getUserId()
)
);
if ($employeeObj) {
$employeeId = $employeeObj->getEmployeeId();
$holidayListObj = HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObj, true);
$currentMonthHolidayList = $holidayListObj['filteredData']['holidayList'];
$currentHolidayCalendarId = $holidayListObj['calendarId'];
}
$session->set(UserConstants::USER_EMPLOYEE_ID, $employeeId);
$session->set(UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH, json_encode($currentMonthHolidayList));
$session->set(UserConstants::USER_HOLIDAY_CALENDAR_ID, $currentHolidayCalendarId);
$session->set(UserConstants::USER_ID, $user->getUserId());
$session->set(UserConstants::LAST_SETTINGS_UPDATED_TS, $user->getLastSettingsUpdatedTs());
$session->set(UserConstants::USER_TYPE, UserConstants::USER_TYPE_MANAGEMENT_USER);
$session->set(UserConstants::USER_EMAIL, $user->getEmail());
$session->set(UserConstants::USER_IMAGE, $user->getImage());
$session->set(UserConstants::USER_NAME, $user->getName());
$session->set(UserConstants::USER_DEFAULT_ROUTE, $user->getDefaultRoute());
$session->set(UserConstants::USER_COMPANY_ID, $user->getUserCompanyId());
$session->set(UserConstants::USER_COMPANY_ID_LIST, json_encode($company_id_list));
$session->set(UserConstants::USER_COMPANY_NAME_LIST, json_encode($company_name_list));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode($company_image_list));
$session->set('userCompanyDarkVibrantList', json_encode($company_dark_vibrant_list));
$session->set('userCompanyVibrantList', json_encode($company_vibrant_list));
$session->set('userCompanyLightVibrantList', json_encode($company_light_vibrant_list));
$session->set(UserConstants::USER_APP_ID, $user->getUserAppId());
$session->set(UserConstants::USER_POSITION_LIST, $user->getPositionIds());
$session->set(UserConstants::ALL_MODULE_ACCESS_FLAG, $user->getAllModuleAccessFlag());
$session->set(UserConstants::SESSION_SALT, uniqid(mt_rand()));
$session->set(UserConstants::APPLICATION_SECRET, $this->container->getParameter('secret'));
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$session->set(UserConstants::USER_NOTIFICATION_ENABLED, GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0);
$session->set(UserConstants::USER_NOTIFICATION_SERVER, $this->getParameter('notification_server'));
if (count(json_decode($user->getPositionIds(), true)) > 1) {
return $this->redirectToRoute("user_login_position");
} else {
$PL = json_decode($user->getPositionIds(), true);
$route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId());
$session->set(UserConstants::USER_CURRENT_POSITION, $PL[0]);
$loginID = $this->get('user_module')->addUserLoginLog(
$session->get(UserConstants::USER_ID),
$request->server->get("REMOTE_ADDR"),
$PL[0]
);
$session->set(UserConstants::USER_LOGIN_ID, $loginID);
// $session->set(UserConstants::USER_LOGIN_ID, $loginID);
$session->set(UserConstants::USER_GOC_ID, $gocId);
$session->set(UserConstants::USER_DB_NAME, $gocDbName);
$session->set(UserConstants::USER_DB_USER, $gocDbUser);
$session->set(UserConstants::USER_DEFAULT_ROUTE, $user->getDefaultRoute());
$session->set(UserConstants::USER_DB_PASS, $gocDbPass);
$session->set(UserConstants::USER_DB_HOST, $gocDbHost);
$session->set(UserConstants::USER_ROUTE_LIST, json_encode($route_list_array));
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, $product_name_display_type);
$appIdList = json_decode($user->getUserAppIdList());
if ($appIdList == null) $appIdList = [];
$companyIdListByAppId = [];
$companyNameListByAppId = [];
$companyImageListByAppId = [];
if (!in_array($user->getUserAppId(), $appIdList))
$appIdList[] = $user->getUserAppId();
foreach ($appIdList as $currAppId) {
if ($currAppId == $user->getUserAppId()) {
foreach ($company_id_list as $index_company => $company_id) {
$companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
$app_company_index = $currAppId . '_' . $company_id;
$companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
$companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
}
} else {
$dataToConnect = System::changeDoctrineManagerByAppId(
$this->getDoctrine()->getManager('company_group'),
$gocEnabled,
$currAppId
);
if (!empty($dataToConnect)) {
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$dataToConnect['dbName'],
$dataToConnect['dbUser'],
$dataToConnect['dbPass'],
$dataToConnect['dbHost'],
$reset = true
);
$em = $this->getDoctrine()->getManager();
$companyList = Company::getCompanyListWithImage($em);
foreach ($companyList as $c => $dta) {
// $company_id_list[]=$c;
// $company_name_list[$c] = $companyList[$c]['name'];
// $company_image_list[$c] = $companyList[$c]['image'];
$companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
$app_company_index = $currAppId . '_' . $c;
$companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
$companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
}
}
}
}
$session->set('appIdList', $appIdList);
$session->set('companyIdListByAppId', $companyIdListByAppId);
$session->set('companyNameListByAppId', $companyNameListByAppId);
$session->set('companyImageListByAppId', $companyImageListByAppId);
$branchIdList = json_decode($user->getUserBranchIdList());
$branchId = $user->getUserBranchId();
$session->set('branchIdList', $branchIdList);
$session->set('branchId', $branchId);
if ($user->getAllModuleAccessFlag() == 1)
$session->set(UserConstants::USER_PROHIBIT_LIST, json_encode([]));
else
$session->set(UserConstants::USER_PROHIBIT_LIST, json_encode(Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $PL[0], $user->getUserId())));
$session_data = array(
UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
'oAuthToken' => $session->get('oAuthToken'),
'locale' => $session->get('locale'),
'firebaseToken' => $session->get('firebaseToken'),
'token' => $session->get('token'),
'firstLogin' => $firstLogin,
'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
'oAuthImage' => $session->get('oAuthImage'),
UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
//new
'appIdList' => $session->get('appIdList'),
'branchIdList' => $session->get('branchIdList', null),
'branchId' => $session->get('branchId', null),
'companyIdListByAppId' => $session->get('companyIdListByAppId'),
'companyNameListByAppId' => $session->get('companyNameListByAppId'),
'companyImageListByAppId' => $session->get('companyImageListByAppId'),
);
$tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
$session_data = $tokenData['sessionData'];
$token = $tokenData['token'];
$session->set('token', $token);
if ($request->request->get('remoteVerify', 0) == 1) {
$session->set('remoteVerified', 1);
$response = new JsonResponse(array(
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'token' => $token,
'success' => true,
'session_data' => $session_data,
'session2' => $_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
$red = $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', '');
return $this->redirect($red);
}
} else {
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', '');
}
} else if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
return $this->redirectToRoute("dashboard");
else
return $this->redirectToRoute($user->getDefaultRoute());
// if ($request->server->has("HTTP_REFERER")) {
// if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '' && $request->server->get('HTTP_REFERER') != null) {
// return $this->redirect($request->request->get('HTTP_REFERER'));
// }
// }
//
// // $request->server->get("REMOTE_ADDR"), $PL[0]);
// if ($request->request->has('referer_path')) {
// if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '' && $request->request->get('referer_path') != null) {
// return $this->redirect($request->request->get('referer_path'));
// }
// }
// // if($request->request->has('gocId')
//
// if ($user->getDefaultRoute() == "" || $user->getDefaultRoute() == "")
// return $this->redirectToRoute("dashboard");
// else
// return $this->redirectToRoute($user->getDefaultRoute());
}
} else if ($userType == UserConstants::USER_TYPE_APPLICANT) {
$applicantId = $user->getApplicantId();
$userId = $user->getApplicantId();
$globalId = $user->getApplicantId();
$lastSettingsUpdatedTs = $user->getLastSettingsUpdatedTs();
$isConsultant = $user->getIsConsultant() == 1 ? 1 : 0;
$isRetailer = $user->getIsRetailer() == 1 ? 1 : 0;
$retailerLevel = $user->getRetailerLevel() == 1 ? 1 : 0;
$adminLevel = $user->getIsAdmin() == 1 ? (($user->getAdminLevel() != null && $user->getAdminLevel() != 0) ? $user->getAdminLevel() : 1) : ($user->getIsModerator() == 1 ? 1 : 0);
$isModerator = $user->getIsModerator() == 1 ? 1 : 0;
$isAdmin = $user->getIsAdmin() == 1 ? 1 : 0;
$userEmail = $user->getOauthEmail();
$userImage = $user->getImage();
$userFullName = $user->getFirstName() . ' ' . $user->getLastName();
$triggerResetPassword = $user->getTriggerResetPassword() == 1 ? 1 : 0;
$buddybeeBalance = 1 * $user->getAccountBalance();
$buddybeeCoinBalance = 1 * $user->getSessionCountBalance();
$userDefaultRoute = 'applicant_dashboard';
$userAppIds = json_decode($user->getUserAppIds(), true);
$userTypesByAppIds = json_decode($user->getUserTypesByAppIds(), true);
if ($userAppIds == null) $userAppIds = [];
if ($userTypesByAppIds == null) $userTypesByAppIds = [];
if ($user->getOAuthEmail() == '' || $user->getOAuthEmail() == null) $currRequiredPromptFields[] = 'email';
if ($user->getPhone() == '' || $user->getPhone() == null) $currRequiredPromptFields[] = 'phone';
if ($user->getCurrentCountryId() == '' || $user->getCurrentCountryId() == null || $user->getCurrentCountryId() == 0) $currRequiredPromptFields[] = 'currentCountryId';
if ($user->getPreferredConsultancyTopicCountryIds() == '' || $user->getPreferredConsultancyTopicCountryIds() == null || $user->getPreferredConsultancyTopicCountryIds() == '[]') $currRequiredPromptFields[] = 'preferredConsultancyTopicCountryIds';
if ($user->getIsConsultant() == 1 && ($user->getPreferredTopicIdsAsConsultant() == '' || $user->getPreferredTopicIdsAsConsultant() == null || $user->getPreferredTopicIdsAsConsultant() == '[]')) $currRequiredPromptFields[] = 'preferredTopicIdsAsConsultant';
$loginID = MiscActions::addEntityUserLoginLog(
$em_goc,
$userId,
$applicantId,
1,
$request->server->get("REMOTE_ADDR"),
0,
$request->request->get('deviceId', ''),
$request->request->get('oAuthToken', ''),
$request->request->get('oAuthType', ''),
$request->request->get('locale', ''),
$request->request->get('firebaseToken', '')
);
} else if ($userType == UserConstants::USER_TYPE_GENERAL) {
// General User
$employeeObj = $em->getRepository('ApplicationBundle:Employee')
->findOneBy(
array(
'userId' => $user->getUserId()
)
);
if ($employeeObj) {
$employeeId = $employeeObj->getEmployeeId();
$holidayListObj = HumanResource::getFilteredHolidaysSingle($em, ['employeeId' => $employeeId], $employeeObj, true);
$currentMonthHolidayList = $holidayListObj['filteredData']['holidayList'];
$currentHolidayCalendarId = $holidayListObj['calendarId'];
}
$currentTask = $em->getRepository('ApplicationBundle:TaskLog')
->findOneBy(
array(
'userId' => $user->getUserId(),
'workingStatus' => 1
)
);
if ($currentTask) {
$currentTaskId = $currentTask->getId();
$currentPlanningItemId = $currentTask->getPlanningItemId();
}
$userId = $user->getUserId();
$userCompanyId = 1;
$lastSettingsUpdatedTs = $user->getLastSettingsUpdatedTs();
$userEmail = $user->getEmail();
$userImage = $user->getImage();
$userFullName = $user->getName();
$triggerResetPassword = $user->getTriggerResetPassword() == 1 ? 1 : 0;
$position_list_array = json_decode($user->getPositionIds(), true);
if ($position_list_array == null) $position_list_array = [];
if (!empty($position_list_array))
$curr_position_id = $position_list_array[0];
$userDefaultRoute = $user->getDefaultRoute();
$allModuleAccessFlag = $user->getAllModuleAccessFlag() == 1 ? 1 : 0;
if ($userDefaultRoute == "" || $userDefaultRoute == null)
$userDefaultRoute = 'dashboard';
$route_list_array = Position::getUserRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $userId);
$companyList = Company::getCompanyListWithImage($this->getDoctrine()->getManager());
if (isset($companyList[$userCompanyId])) {
$company_name_list[$userCompanyId] = $companyList[$userCompanyId]['name'];
$company_image_list[$userCompanyId] = $companyList[$userCompanyId]['image'];
$company_dark_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['dark_vibrant'];
$company_light_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['light_vibrant'];
$company_vibrant_list[$userCompanyId] = $companyList[$userCompanyId]['vibrant'];
}
if ($allModuleAccessFlag == 1)
$prohibit_list_array = [];
else if ($curr_position_id != 0)
$prohibit_list_array = Position::getUserProhibitRouteArray($this->getDoctrine()->getManager(), $curr_position_id, $user->getUserId());
$loginID = $this->get('user_module')->addUserLoginLog(
$userId,
$request->server->get("REMOTE_ADDR"),
$curr_position_id
);
$appIdList = json_decode($user->getUserAppIdList());
$branchIdList = json_decode($user->getUserBranchIdList());
if ($branchIdList == null) $branchIdList = [];
$branchId = $user->getUserBranchId();
if ($appIdList == null) $appIdList = [];
if (!in_array($user->getUserAppId(), $appIdList))
$appIdList[] = $user->getUserAppId();
foreach ($appIdList as $currAppId) {
if ($currAppId == $user->getUserAppId()) {
foreach ($company_id_list as $index_company => $company_id) {
$companyIdListByAppId[$currAppId][] = $currAppId . '_' . $company_id;
$app_company_index = $currAppId . '_' . $company_id;
$companyNameListByAppId[$app_company_index] = $company_name_list[$company_id];
$companyImageListByAppId[$app_company_index] = $company_image_list[$company_id];
}
} else {
$dataToConnect = System::changeDoctrineManagerByAppId(
$this->getDoctrine()->getManager('company_group'),
$gocEnabled,
$currAppId
);
if (!empty($dataToConnect)) {
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$dataToConnect['dbName'],
$dataToConnect['dbUser'],
$dataToConnect['dbPass'],
$dataToConnect['dbHost'],
$reset = true
);
$em = $this->getDoctrine()->getManager();
$companyList = Company::getCompanyListWithImage($em);
foreach ($companyList as $c => $dta) {
// $company_id_list[]=$c;
// $company_name_list[$c] = $companyList[$c]['name'];
// $company_image_list[$c] = $companyList[$c]['image'];
$companyIdListByAppId[$currAppId][] = $currAppId . '_' . $c;
$app_company_index = $currAppId . '_' . $c;
$companyNameListByAppId[$app_company_index] = $companyList[$c]['name'];
$companyImageListByAppId[$app_company_index] = $companyList[$c]['image'];
}
}
}
}
if (count($position_list_array) > 1) {
$userForcedRoute = 'user_login_position';
// return $this->redirectToRoute("user_login_position");
} else {
}
}
if ($userType == UserConstants::USER_TYPE_APPLICANT ||
$userType == UserConstants::USER_TYPE_GENERAL ||
$userType == UserConstants::USER_TYPE_SYSTEM
) {
$session_data = array(
UserConstants::USER_ID => $userId,
UserConstants::USER_EMPLOYEE_ID => $employeeId,
UserConstants::APPLICANT_ID => $applicantId,
UserConstants::USER_CURRENT_TASK_ID => $currentTaskId,
UserConstants::USER_CURRENT_PLANNING_ITEM_ID => $currentPlanningItemId,
UserConstants::USER_HOLIDAY_LIST_CURRENT_MONTH => json_encode($currentMonthHolidayList),
UserConstants::USER_HOLIDAY_CALENDAR_ID => $currentHolidayCalendarId,
UserConstants::SUPPLIER_ID => $supplierId,
UserConstants::CLIENT_ID => $clientId,
UserConstants::USER_TYPE => $userType,
UserConstants::LAST_SETTINGS_UPDATED_TS => $lastSettingsUpdatedTs == null ? 1 : $lastSettingsUpdatedTs,
UserConstants::IS_CONSULTANT => $isConsultant,
UserConstants::IS_BUDDYBEE_RETAILER => $isRetailer,
UserConstants::BUDDYBEE_RETAILER_LEVEL => $retailerLevel,
UserConstants::BUDDYBEE_ADMIN_LEVEL => $adminLevel,
UserConstants::IS_BUDDYBEE_MODERATOR => $isModerator,
UserConstants::IS_BUDDYBEE_ADMIN => $isAdmin,
UserConstants::USER_EMAIL => $userEmail,
UserConstants::USER_IMAGE => $userImage,
UserConstants::USER_NAME => $userFullName,
UserConstants::USER_DEFAULT_ROUTE => $userDefaultRoute,
UserConstants::USER_COMPANY_ID => $userCompanyId,
UserConstants::USER_COMPANY_ID_LIST => json_encode($company_id_list),
UserConstants::USER_COMPANY_NAME_LIST => json_encode($company_name_list),
UserConstants::USER_COMPANY_IMAGE_LIST => json_encode($company_image_list),
UserConstants::USER_APP_ID => $appIdFromUserName,
UserConstants::USER_POSITION_LIST => json_encode($position_list_array),
UserConstants::ALL_MODULE_ACCESS_FLAG => $allModuleAccessFlag,
UserConstants::SESSION_SALT => uniqid(mt_rand()),
UserConstants::APPLICATION_SECRET => $this->container->getParameter('secret'),
UserConstants::USER_GOC_ID => $gocId,
UserConstants::USER_DB_NAME => $gocDbName,
UserConstants::USER_DB_USER => $gocDbUser,
UserConstants::USER_DB_PASS => $gocDbPass,
UserConstants::USER_DB_HOST => $gocDbHost,
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $product_name_display_type,
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
UserConstants::USER_LOGIN_ID => $loginID,
UserConstants::USER_CURRENT_POSITION => $curr_position_id,
UserConstants::USER_ROUTE_LIST => json_encode($route_list_array),
UserConstants::USER_PROHIBIT_LIST => json_encode($prohibit_list_array),
'relevantRequiredPromptFields' => json_encode($currRequiredPromptFields),
'triggerPromptInfoModalFlag' => empty($currRequiredPromptFields) ? 0 : 1,
'TRIGGER_RESET_PASSWORD' => $triggerResetPassword,
'REMEMBERME' => $remember_me,
'BUDDYBEE_BALANCE' => $buddybeeBalance,
'BUDDYBEE_COIN_BALANCE' => $buddybeeCoinBalance,
'oAuthToken' => $oAuthToken,
'locale' => $locale,
'firebaseToken' => $firebaseToken,
'token' => $session->get('token'),
'firstLogin' => $firstLogin,
'oAuthImage' => $oAuthImage,
'appIdList' => json_encode($appIdList),
'branchIdList' => json_encode($branchIdList),
'branchId' => $branchId,
'companyIdListByAppId' => json_encode($companyIdListByAppId),
'companyNameListByAppId' => json_encode($companyNameListByAppId),
'companyImageListByAppId' => json_encode($companyImageListByAppId),
'userCompanyDarkVibrantList' => json_encode($company_dark_vibrant_list),
'userCompanyVibrantList' => json_encode($company_vibrant_list),
'userCompanyLightVibrantList' => json_encode($company_light_vibrant_list),
);
if ($systemType == '_CENTRAL_') {
$accessList = [];
// System::log_it($this->container->getParameter('kernel.root_dir'),json_encode($gocDataListByAppId),'data_list_by_app_id');
foreach ($userTypesByAppIds as $thisUserAppId => $thisUserUserTypes) {
foreach ($thisUserUserTypes as $thisUserUserType) {
$d = array(
'userType' => $thisUserUserType,
'globalId' => $globalId,
'serverId' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerId'],
'serverUrl' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerAddress'],
'serverPort' => $gocDataListByAppId[$thisUserAppId]['companyGroupServerPort'],
'systemType' => '_ERP_',
'companyId' => 1,
'appId' => $thisUserAppId,
'companyLogoUrl' => $gocDataListByAppId[$thisUserAppId]['image'],
'companyName' => $gocDataListByAppId[$thisUserAppId]['name'],
'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
array(
'globalId' => $globalId,
'appId' => $thisUserAppId,
'authenticate' => 1,
'userType' => $thisUserUserType
)
)
),
'userCompanyList' => [
]
);
$accessList[] = $d;
}
}
$session_data['userAccessList'] = $accessList;
}
$ultimateData = System::setSessionForUser($em_goc,
$session,
$session_data,
$config
);
// $tokenData = MiscActions::CreateTokenFromSessionData($em_goc, $session_data);
$session_data = $ultimateData['sessionData'];
$token = $ultimateData['token'];
$session->set('token', $token);
if ($systemType == '_CENTRAL_') {
$session->set('csToken', $token);
} else {
$session->set('csToken', $csToken);
}
if ($request->request->get('remoteVerify', 0) == 1 || $request->query->get('remoteVerify', 0) == 1) {
$session->set('remoteVerified', 1);
$response = new JsonResponse(array(
'token' => $token,
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => true,
'session_data' => $session_data,
'session2' => $_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
//TEMP START
if ($systemType == '_CENTRAL_') {
return $this->redirectToRoute('central_landing');
}
//TREMP END
if ($userForcedRoute != '')
return $this->redirectToRoute($userForcedRoute);
if ($request->request->has('referer_path')) {
if ($request->request->get('referer_path') != '/' && $request->request->get('referer_path') != '') {
return $this->redirect($request->request->get('referer_path'));
}
}
if ($request->query->has('refRoute')) {
if ($request->query->get('refRoute') == '8917922')
$userDefaultRoute = 'apply_for_consultant';
}
if ($userDefaultRoute == "" || $userDefaultRoute == "" || $userDefaultRoute == null)
$userDefaultRoute = 'dashboard';
if (!empty($session->get('LAST_REQUEST_URI_BEFORE_LOGIN'))) {
if (strripos($session->get('REQUEST_URI'), 'select_data') === false) {
if ($session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != '' && $session->get('LAST_REQUEST_URI_BEFORE_LOGIN') != null) {
$red = $session->get('LAST_REQUEST_URI_BEFORE_LOGIN');
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', '');
return $this->redirect($red);
}
} else {
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', '');
}
} else
return $this->redirectToRoute($userDefaultRoute);
}
}
}
$session = $request->getSession();
if (isset($encData['appId'])) {
if (isset($gocDataListByAppId[$encData['appId']]))
$gocId = $gocDataListByAppId[$encData['appId']]['id'];
}
$routeName = $request->attributes->get('_route');
if ($systemType == '_BUDDYBEE_' && $routeName != 'erp_login') {
$refRoute = '';
$message = '';
$errorField = '_NONE_';
// if ($req->query->has('message')) {
// $message = $req->query->get('message');
//
// }
// if ($req->query->has('errorField')) {
// $errorField = $req->query->get('errorField');
//
// }
if ($refRoute != '') {
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
if ($request->query->has('refRoute')) {
$refRoute = $request->query->get('refRoute');
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
$google_client = new Google_Client();
// $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
// $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
$url = $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
} else {
$url = $this->generateUrl(
'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
);
}
$selector = ConsultancyConstant::$selector;
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
// $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
$google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
// $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
$google_client->setRedirectUri($url);
$google_client->setAccessType('offline'); // offline access
$google_client->setIncludeGrantedScopes(true); // incremental auth
$google_client->setRedirectUri($url);
$google_client->addScope('email');
$google_client->addScope('profile');
$google_client->addScope('openid');
return $this->render(
'ApplicationBundle:pages/login:applicant_login.html.twig',
[
'page_title' => 'BuddyBee Login',
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'message' => $message,
'errorField' => '',
'systemType' => $systemType,
'ownServerId' => $ownServerId,
'refRoute' => $refRoute,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
]
);
} else if ($systemType == '_CENTRAL_' && $routeName != 'erp_login') {
$refRoute = '';
$message = '';
$errorField = '_NONE_';
// if ($req->query->has('message')) {
// $message = $req->query->get('message');
//
// }
// if ($req->query->has('errorField')) {
// $errorField = $req->query->get('errorField');
//
// }
if ($refRoute != '') {
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
if ($request->query->has('refRoute')) {
$refRoute = $request->query->get('refRoute');
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
$google_client = new Google_Client();
// $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
// $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
$url = $this->generateUrl('central_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
} else {
$url = $this->generateUrl(
'central_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
);
}
$selector = ConsultancyConstant::$selector;
// $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
$google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
// $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
$google_client->setRedirectUri($url);
$google_client->setAccessType('offline'); // offline access
$google_client->setIncludeGrantedScopes(true); // incremental auth
$google_client->setRedirectUri($url);
$google_client->addScope('email');
$google_client->addScope('profile');
$google_client->addScope('openid');
return $this->render(
'ApplicationBundle:pages/login:central_login.html.twig',
[
'page_title' => 'Central Login',
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'message' => $message,
'systemType' => $systemType,
'ownServerId' => $ownServerId,
'errorField' => '',
'refRoute' => $refRoute,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
]
);
} else if ($systemType == '_ERP_' && ($this->container->hasParameter('system_auth_type') ? $this->container->getParameter('system_auth_type') : '_LOCAL_AUTH_') == '_CENTRAL_AUTH_') {
return $this->redirect(GeneralConstant::HONEYBEE_CENTRAL_SERVER);
} else
return $this->render(
'ApplicationBundle:pages/login:login_new.html.twig',
array(
"message" => $message,
'page_title' => 'Login',
'gocList' => $gocDataListForLoginWeb,
'gocId' => $gocId != 0 ? $gocId : '',
'systemType' => $systemType,
'ownServerId' => $ownServerId,
'encData' => $encData,
// 'ref'=>$request->
)
);
}
public function initiateAdminAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
MiscActions::initiateAdminUser($em);
$this->addFlash(
'success',
'The Action was Successful.'
);
return $this->redirectToRoute('user_login');
}
public function LogoutAction(Request $request)
{
$session = $request->getSession();
$em_goc = $this->getDoctrine()->getManager('company_group');
$session = $request->getSession();
$currentTime = new \Datetime();
$currTs = $currentTime->format('U');
$currentTaskId = $session->get(UserConstants::USER_CURRENT_TASK_ID, 0);
$currentPlanningItemId = $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID, 0);
if($request->query->get('endCurrentTask', 0) == 1)
{
if (
($currentTaskId != 0 && $currentTaskId != null && $currentTaskId != '') &&
($session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_GENERAL ||
$session->get(UserConstants::USER_TYPE) == UserConstants::USER_TYPE_SYSTEM)
) {
$gocId = $session->get(UserConstants::USER_GOC_ID);
if ($gocId != 0 && $gocId != "") {
$gocDbName = $session->get(UserConstants::USER_DB_NAME);
$gocDbUser = $session->get(UserConstants::USER_DB_USER);
$gocDbPass = $session->get(UserConstants::USER_DB_PASS);
$gocDbHost = $session->get(UserConstants::USER_DB_HOST);
// $connector = $this->container->get('application_connector');
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$gocDbName,
$gocDbUser,
$gocDbPass,
$gocDbHost,
$reset = false);
}
$em = $this->getDoctrine()->getManager();
$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) . ' ;');
$stmt->execute();
$stmt->closeCursor();
if (1) {
$session->set(UserConstants::USER_CURRENT_TASK_ID, 0);
$session->set(UserConstants::USER_CURRENT_PLANNING_ITEM_ID, 0);
$empId = $session->get(UserConstants::USER_EMPLOYEE_ID, 0);
$currTime = new \DateTime();
$options = array(
'notification_enabled' => $this->container->getParameter('notification_enabled'),
'notification_server' => $this->container->getParameter('notification_server'),
);
$positionsArray = [
array(
'employeeId' => $empId,
'userId' => $session->get(UserConstants::USER_ID, 0),
'sysUserId' => $session->get(UserConstants::USER_ID, 0),
'timeStamp' => $currTime->format(DATE_ISO8601),
'lat' => 23.8623834,
'lng' => 90.3979294,
'markerId' => HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT,
// 'userId'=>$session->get(UserConstants::USER_ID, 0),
)
];
if (is_string($positionsArray)) $positionsArray = json_decode($positionsArray, true);
if ($positionsArray == null) $positionsArray = [];
$dataByAttId = [];
$workPlaceType = '_UNSET_';
foreach ($positionsArray as $findex => $d) {
$sysUserId = 0;
$userId = 0;
$empId = 0;
$dtTs = 0;
$timeZoneStr = '+0000';
if (isset($d['employeeId'])) $empId = $d['employeeId'];
if (isset($d['userId'])) $userId = $d['userId'];
if (isset($d['sysUserId'])) $sysUserId = $d['sysUserId'];
if (isset($d['tsMilSec'])) {
$dtTs = ceil((1 * $d['tsMilSec']) / 1000);
}
if ($dtTs == 0) {
$currTsTime = new \DateTime();
$dtTs = $currTsTime->format('U');
} else {
$currTsTime = new \DateTime('@' . $dtTs);
}
$currTsTime->setTimezone(new \DateTimeZone('UTC'));
$attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' . $timeZoneStr);
$EmployeeAttendance = $this->getDoctrine()
->getRepository(EmployeeAttendance::class)
->findOneBy(array('employeeId' => $empId, 'date' => $attDate));
if (!$EmployeeAttendance) {
continue;
} else {
}
$attendanceInfo = HumanResource::StoreAttendance($em, $empId, $sysUserId, $request, $EmployeeAttendance, $attDate, $dtTs, $timeZoneStr, $d['markerId']);
if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_OUT) {
$workPlaceType = '_STATIC_';
}
if (!isset($dataByAttId[$attendanceInfo->getId()]))
$dataByAttId[$attendanceInfo->getId()] = array(
'attendanceInfo' => $attendanceInfo,
'empId' => $empId,
'lat' => 0,
'lng' => 0,
'address' => 0,
'sysUserId' => $sysUserId,
'companyId' => $request->getSession()->get(UserConstants::USER_COMPANY_ID),
'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
'positionArray' => []
);
$posData = array(
'ts' => $dtTs,
'lat' => $d['lat'],
'lng' => $d['lng'],
'marker' => $d['markerId'],
'src' => 2,
);
$posDataArray = array(
$dtTs,
$d['lat'],
$d['lng'],
$d['markerId'],
2
);
$dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
//this markerId will be calclulted and modified to check if user is in our out of office/workplace later
$dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
$dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
$dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat']; //for last lat lng etc
$dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng']; //for last lat lng etc
if (isset($d['address']))
$dataByAttId[$attendanceInfo->getId()]['address'] = $d['address']; //for last lat lng etc
// $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
}
$response = array(
'success' => true,
);
foreach ($dataByAttId as $attInfoId => $d) {
$response = HumanResource::setAttendanceLogFlutterApp($em,
$d['empId'],
$d['sysUserId'],
$d['companyId'],
$d['appId'],
$request,
$d['attendanceInfo'],
$options,
$d['positionArray'],
$d['lat'],
$d['lng'],
$d['address'],
$d['markerId']
);
}
}
}
}
$token = $request->request->get('token', '');
if ($token != '')
MiscActions::DeleteToken($em_goc, $token);
$session->clear();
$session->set('CLEARLOGIN', 1);
if (strripos($request->server->get('HTTP_REFERER'), 'select_data') === false) {
if ($request->server->get('HTTP_REFERER') != '/' && $request->server->get('HTTP_REFERER') != '') {
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', $request->server->get('HTTP_REFERER'));
}
} else {
$session->set('LAST_REQUEST_URI_BEFORE_LOGIN', '');
}
// $request->headers->setCookie(Cookie::create('CLEARLOGINCOOKIE', 1
// )
//
// );
if ($request->request->get('remoteVerify', 0) == 1 || $request->query->get('remoteVerify', 0) == 1 || $request->get('returnJson', 0) == 1) {
return new JsonResponse(array(
"success" => empty($session->get(UserConstants::USER_ID)) ? true : false,
// 'session'=>$request->getSession(),
'session_data' => [],
// 'session2'=>$_SESSION,
));
}
return $this->redirectToRoute("dashboard");
}
public function applicantLoginAction(Request $req, $refRoute = '')
{
$session = $req->getSession();
$email = $req->getSession()->get('userEmail');
$sessionUserId = $req->getSession()->get('userId');
$oAuthData = [];
// $refRoute='';
$em = $this->getDoctrine()->getManager('company_group');
$applicantRepo = $em->getRepository(EntityApplicantDetails::class);
$redirectRoute = 'dashboard';
if ($refRoute != '') {
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
if ($req->query->has('refRoute')) {
$refRoute = $req->query->get('refRoute');
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
$message = '';
$errorField = '_NONE_';
if ($req->query->has('message')) {
$message = $req->query->get('message');
}
if ($req->query->has('errorField')) {
$errorField = $req->query->get('errorField');
}
if ($req->request->has('oAuthData')) {
$oAuthData = $req->request->get('oAuthData', []);
} else {
$oAuthData = [
'email' => $req->request->get('email', ''),
'uniqueId' => $req->request->get('uniqueId', ''),
'oAuthHash' => '_NONE_',
'image' => $req->request->get('image', ''),
'emailVerified' => $req->request->get('emailVerified', ''),
'name' => $req->request->get('name', ''),
'firstName' => $req->request->get('firstName', ''),
'lastName' => $req->request->get('lastName', ''),
'type' => 1,
'token' => $req->request->get('oAuthtoken', ''),
];
}
$isApplicantExist = null;
if ($email) {
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
$isApplicantExist = $applicantRepo->findOneBy([
'applicantId' => $sessionUserId
]);
} else
return $this->redirectToRoute($redirectRoute);
}
$google_client = new Google_Client();
// $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
// $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
$url = $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
} else {
$url = $this->generateUrl(
'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
);
}
$selector = ConsultancyConstant::$selector;
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$ownServerId = $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
// $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
$google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json');
// $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
$google_client->setRedirectUri($url);
$google_client->setAccessType('offline'); // offline access
$google_client->setIncludeGrantedScopes(true); // incremental auth
$google_client->addScope('email');
$google_client->addScope('profile');
$google_client->addScope('openid');
// $google_client->setRedirectUri('http://localhost/applicant_login');
//linked in 1st
if (isset($_GET["code"]) && isset($_GET["state"])) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
CURLOPT_USERAGENT => 'InnoPM',
CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" . $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
)
));
$content = curl_exec($curl);
$contentArray = [];
curl_close($curl);
$token = false;
// return new JsonResponse(array(
// 'content'=>$content,
// 'contentArray'=>json_decode($content,true),
//
// ));
if ($content) {
$contentArray = json_decode($content, true);
$token = $contentArray['access_token'];
}
if ($token) {
$applicantInfo = [];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
CURLOPT_USERAGENT => 'InnoPM',
CURLOPT_HTTPGET => 1,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $token,
'Header-Key-2: Header-Value-2'
)
));
$userGeneralcontent = curl_exec($curl);
curl_close($curl);
if ($userGeneralcontent) {
$userGeneralcontent = json_decode($userGeneralcontent, true);
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
// CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
CURLOPT_USERAGENT => 'InnoPM',
CURLOPT_HTTPGET => 1,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $token,
'Header-Key-2: Header-Value-2'
)
));
$userEmailcontent = curl_exec($curl);
curl_close($curl);
$token = false;
if ($userEmailcontent) {
$userEmailcontent = json_decode($userEmailcontent, true);
}
// $oAuthEmail = $applicantInfo['email'];
// return new JsonResponse(array(
// 'userEmailcontent'=>$userEmailcontent,
// 'userGeneralcontent'=>$userGeneralcontent,
// ));
// return new response($userGeneralcontent);
$oAuthData = [
'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
'uniqueId' => $userGeneralcontent['id'],
'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
'name' => $userGeneralcontent['localizedFirstName'] . ' ' . $userGeneralcontent['localizedLastName'],
'firstName' => $userGeneralcontent['localizedFirstName'],
'lastName' => $userGeneralcontent['localizedLastName'],
'type' => 1,
'token' => $token,
];
}
} else if (isset($_GET["code"])) {
$token = $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
if (!isset($token['error'])) {
$google_client->setAccessToken($token['access_token']);
$google_service = new Google_Service_Oauth2($google_client);
$applicantInfo = $google_service->userinfo->get();
$oAuthEmail = $applicantInfo['email'];
$oAuthData = [
'email' => $applicantInfo['email'],
'uniqueId' => $applicantInfo['id'],
'image' => $applicantInfo['picture'],
'emailVerified' => $applicantInfo['verifiedEmail'],
'name' => $applicantInfo['givenName'] . ' ' . $applicantInfo['familyName'],
'firstName' => $applicantInfo['givenName'],
'lastName' => $applicantInfo['familyName'],
'type' => $token['token_type'],
'token' => $token['access_token'],
];
}
}
if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
$isApplicantExist = $applicantRepo->findOneBy([
'email' => $oAuthData['email']
]);
if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
$isApplicantExist = $applicantRepo->findOneBy([
'oAuthUniqueId' => $oAuthData['uniqueId']
]);
}
if ($isApplicantExist) {
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
} else
return $this->redirectToRoute("user_login", [
'id' => $isApplicantExist->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
'locale' => $req->request->get('locale', 'en'),
'remoteVerify' => $req->request->get('remoteVerify', 0),
'firebaseToken' => $req->request->get('firebaseToken', ''),
]);
} else {
$fname = $oAuthData['firstName'];
$lname = $oAuthData['lastName'];
$img = $oAuthData['image'];
$email = $oAuthData['email'];
$oAuthEmail = $oAuthData['email'];
$userName = explode('@', $email)[0];
//now check if same username exists
$username_already_exist = 1;
$initial_user_name = $userName;
$timeoutSafeCount = 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
while ($username_already_exist == 1 && $timeoutSafeCount > 0) {
$isUsernameExist = $applicantRepo->findOneBy([
'username' => $userName
]);
if ($isUsernameExist) {
$username_already_exist = 1;
$userName = $initial_user_name . '' . rand(300, 9987);
} else {
$username_already_exist = 0;
}
$timeoutSafeCount--;
}
if ($timeoutSafeCount == 0 && $username_already_exist == 1) {
$currentUnixTimeStamp = '';
$currentUnixTime = new \DateTime();
$currentUnixTimeStamp = $currentUnixTime->format('U');
$userName = $userName . '' . $currentUnixTimeStamp;
}
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$length = 8;
$password = 0;
for ($i = 0; $i < $length; $i++) {
$password .= $characters[rand(0, $charactersLength - 1)];
}
$newApplicant = new EntityApplicantDetails();
$newApplicant->setActualRegistrationAt(new \DateTime());
$newApplicant->setEmail($email);
$newApplicant->setUserName($userName);
$newApplicant->setFirstname($fname);
$newApplicant->setLastname($lname);
$newApplicant->setOAuthEmail($oAuthEmail);
$newApplicant->setIsEmailVerified(1);
$newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
$newApplicant->setAccountStatus(1);
//salt will be username
// $this->container->get('sha256salted_encoder')->isPasswordValid($user->getPassword(), $request->request->get('password'), $user->getSalt())
$salt = uniqid(mt_rand());
$encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
$newApplicant->setPassword($encodedPassword);
$newApplicant->setSalt($salt);
$newApplicant->setTempPassword($password);
// $newApplicant->setPassword($password);
$marker = $userName . '-' . time();
// $extension_here=$uploadedFile->guessExtension();
// $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
// $path = $fileName;
$upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
if (!file_exists($upl_dir)) {
mkdir($upl_dir, 0777, true);
}
$ch = curl_init($img);
$fp = fopen($upl_dir . '/' . $marker . '.jiff', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$newApplicant->setImage('/uploads/applicants/' . $marker . '.jiff');
// $newApplicant->setImage($img);
$newApplicant->setIsConsultant(0);
$newApplicant->setIsTemporaryEntry(0);
$newApplicant->setApplyForConsultant(0);
$newApplicant->setTriggerResetPassword(0);
$em->persist($newApplicant);
$em->flush();
$isApplicantExist = $newApplicant;
if (GeneralConstant::EMAIL_ENABLED == 1) {
if ($systemType == '_BUDDYBEE_') {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => $userName,
'showPassword' => $newApplicant->getTempPassword() != '' ? 1 : 0,
'password' => $newApplicant->getTempPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Welcome to BuddyBee ',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'registration@buddybee.eu',
'userName' => 'registration@buddybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
'encryptionMethod' => 'ssl',
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
} else {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => 'APP-' . $userName,
'password' => $newApplicant->getPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Applicant Registration on Honeybee',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'support@ourhoneybee.eu',
'userName' => 'support@ourhoneybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
'encryptionMethod' => 'ssl',
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
}
}
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
} else {
return $this->redirectToRoute("user_login", [
'id' => $newApplicant->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
'remoteVerify' => $req->request->get('remoteVerify', 0),
'locale' => $req->request->get('locale', 'en'),
'firebaseToken' => $req->request->get('firebaseToken', ''),
]);
}
}
}
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
if ($isApplicantExist) {
$user = $isApplicantExist;
$userType = UserConstants::USER_TYPE_APPLICANT;
if ($userType == UserConstants::USER_TYPE_APPLICANT) {
$session->set(UserConstants::USER_ID, $user->getApplicantId());
$session->set(UserConstants::LAST_SETTINGS_UPDATED_TS, $user->getLastSettingsUpdatedTs());
$session->set(UserConstants::IS_CONSULTANT, $user->getIsConsultant() == 1 ? 1 : 0);
$session->set('BUDDYBEE_BALANCE', 1 * $user->getAccountBalance());
$session->set('BUDDYBEE_COIN_BALANCE', 1 * $user->getSessionCountBalance());
$session->set(UserConstants::IS_BUDDYBEE_RETAILER, $user->getIsRetailer() == 1 ? 1 : 0);
$session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL, $user->getRetailerLevel() == 1 ? 1 : 0);
$session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL, $user->getIsAdmin() == 1 ? 3 : ($user->getIsModerator() == 1 ? 1 : 0));
$session->set(UserConstants::IS_BUDDYBEE_MODERATOR, $user->getIsModerator() == 1 ? 1 : 0);
$session->set(UserConstants::IS_BUDDYBEE_ADMIN, $user->getIsAdmin() == 1 ? 1 : 0);
// $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
$session->set(UserConstants::USER_TYPE, UserConstants::USER_TYPE_APPLICANT);
$session->set(UserConstants::USER_EMAIL, $user->getOauthEmail());
$session->set(UserConstants::USER_IMAGE, $user->getImage());
$session->set(UserConstants::USER_NAME, $user->getFirstName() . ' ' . $user->getLastName());
$session->set(UserConstants::USER_DEFAULT_ROUTE, '');
$session->set(UserConstants::USER_COMPANY_ID, 1);
$session->set(UserConstants::USER_COMPANY_ID_LIST, json_encode([]));
$session->set(UserConstants::USER_COMPANY_NAME_LIST, json_encode([]));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode([]));
$session->set('userCompanyDarkVibrantList', json_encode([]));
$session->set('userCompanyVibrantList', json_encode([]));
$session->set('userCompanyLightVibrantList', json_encode([]));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode([]));
$session->set(UserConstants::USER_APP_ID, 0);
$session->set(UserConstants::USER_POSITION_LIST, '[]');
$session->set(UserConstants::ALL_MODULE_ACCESS_FLAG, 0);
$session->set(UserConstants::SESSION_SALT, uniqid(mt_rand()));
$session->set(UserConstants::APPLICATION_SECRET, $this->container->getParameter('secret'));
$session->set(UserConstants::USER_GOC_ID, 0);
$session->set(UserConstants::USER_DB_NAME, '');
$session->set(UserConstants::USER_DB_USER, '');
$session->set(UserConstants::USER_DB_PASS, '');
$session->set(UserConstants::USER_DB_HOST, '');
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, '');
$session->set(UserConstants::USER_NOTIFICATION_ENABLED, GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0);
$session->set(UserConstants::USER_NOTIFICATION_SERVER, $this->getParameter('notification_server'));
$session->set('oAuthToken', $req->request->get('oAuthToken', ''));
$session->set('locale', $req->request->get('locale', ''));
$session->set('firebaseToken', $req->request->get('firebaseToken', ''));
$route_list_array = [];
$session->set(UserConstants::USER_CURRENT_POSITION, 0);
$loginID = 0;
$loginID = MiscActions::addEntityUserLoginLog(
$em,
$session->get(UserConstants::USER_ID),
$session->get(UserConstants::USER_ID),
1,
$req->server->get("REMOTE_ADDR"),
0,
$req->request->get('deviceId', ''),
$req->request->get('oAuthToken', ''),
$req->request->get('oAuthType', ''),
$req->request->get('locale', ''),
$req->request->get('firebaseToken', '')
);
$session->set(UserConstants::USER_LOGIN_ID, $loginID);
$session_data = array(
UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
'oAuthToken' => $session->get('oAuthToken'),
'locale' => $session->get('locale'),
'firebaseToken' => $session->get('firebaseToken'),
'token' => $session->get('token'),
'firstLogin' => 0,
'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
'oAuthImage' => $session->get('oAuthImage'),
UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
//new
'appIdList' => $session->get('appIdList'),
'branchIdList' => $session->get('branchIdList', null),
'branchId' => $session->get('branchId', null),
'companyIdListByAppId' => $session->get('companyIdListByAppId'),
'companyNameListByAppId' => $session->get('companyNameListByAppId'),
'companyImageListByAppId' => $session->get('companyImageListByAppId'),
);
$tokenData = MiscActions::CreateTokenFromSessionData($em, $session_data);
$session_data = $tokenData['sessionData'];
$token = $tokenData['token'];
$session->set('token', $token);
if ($req->request->get('remoteVerify', 0) == 1 || $req->query->get('remoteVerify', 0) == 1) {
$session->set('remoteVerified', 1);
$response = new JsonResponse(array(
'token' => $token,
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => true,
'session_data' => $session_data,
'session2' => $_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
if ($req->request->has('referer_path')) {
if ($req->request->get('referer_path') != '/' && $req->request->get('referer_path') != '') {
return $this->redirect($req->request->get('referer_path'));
}
}
$redirectRoute = 'applicant_dashboard';
if ($req->query->has('refRoute')) {
if ($req->query->get('refRoute') == '8917922')
$redirectRoute = 'apply_for_consultant';
}
return $this->redirectToRoute($redirectRoute);
}
// $response = new JsonResponse(array(
// 'token' => $token,
// 'uid' => $session->get(UserConstants::USER_ID),
// 'session' => $session,
//
// 'success' => true,
// 'session_data' => $session_data,
// 'session2' => $_SESSION,
// ));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
// return $this->redirectToRoute("user_login", [
// 'id' => $isApplicantExist->getApplicantId(),
// 'oAuthData' => $oAuthData,
// 'refRoute' => $refRoute,
// 'locale' => $req->request->get('locale', 'en'),
// 'remoteVerify' => $req->request->get('remoteVerify', 0),
// 'firebaseToken' => $req->request->get('firebaseToken', ''),
// ]);
}
}
// if ($req->isMethod('POST')){
// $new = new EntityApplicantDetails();
//
// $new-> setUsername->$req->request->get('userName');
// $new-> setEmail()->$req->request->get('email');
// $new-> setPassword()->$req->request->get('password');
// $new-> setSelector()->$req->request->get('selector');
//
//
// $em->persist($new);
// $em->flush();
// }
$selector = ConsultancyConstant::$selector;
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$twig_file = 'ApplicationBundle:pages/login:applicant_login.html.twig';
if ($systemType == '_ERP_') {
} else if ($systemType == '_BUDDYBEE_') {
return $this->render(
'ApplicationBundle:pages/login:applicant_login.html.twig',
[
'page_title' => 'BuddyBee Login',
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'message' => $message,
'errorField' => $errorField,
'refRoute' => $refRoute,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
]
);
}
return $this->render(
'ApplicationBundle:pages/login:applicant_login.html.twig',
[
'page_title' => 'Applicant Registration',
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'refRoute' => $refRoute,
'message' => $message,
'errorField' => $errorField,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
]
);
}
public function centralLoginAction(Request $req, $refRoute = '')
{
$session = $req->getSession();
$email = $req->getSession()->get('userEmail');
$sessionUserId = $req->getSession()->get('userId');
$oAuthData = [];
// $refRoute='';
$em = $this->getDoctrine()->getManager('company_group');
$applicantRepo = $em->getRepository(EntityApplicantDetails::class);
$redirectRoute = 'dashboard';
if ($refRoute != '') {
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
if ($req->query->has('refRoute')) {
$refRoute = $req->query->get('refRoute');
if ($refRoute == '8917922')
$redirectRoute = 'apply_for_consultant';
}
$message = '';
$errorField = '_NONE_';
if ($req->query->has('message')) {
$message = $req->query->get('message');
}
if ($req->query->has('errorField')) {
$errorField = $req->query->get('errorField');
}
if ($req->request->has('oAuthData')) {
$oAuthData = $req->request->get('oAuthData', []);
} else {
$oAuthData = [
'email' => $req->request->get('email', ''),
'uniqueId' => $req->request->get('uniqueId', ''),
'oAuthHash' => '_NONE_',
'image' => $req->request->get('image', ''),
'emailVerified' => $req->request->get('emailVerified', ''),
'name' => $req->request->get('name', ''),
'firstName' => $req->request->get('firstName', ''),
'lastName' => $req->request->get('lastName', ''),
'type' => 1,
'token' => $req->request->get('oAuthtoken', ''),
];
}
$isApplicantExist = null;
if ($email) {
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
$isApplicantExist = $applicantRepo->findOneBy([
'applicantId' => $sessionUserId
]);
} else
return $this->redirectToRoute($redirectRoute);
}
$google_client = new Google_Client();
// $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
// $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
$url = $this->generateUrl('applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL);
} else {
$url = $this->generateUrl(
'applicant_login', ['refRoute' => $refRoute], UrlGenerator::ABSOLUTE_URL
);
}
$selector = ConsultancyConstant::$selector;
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$ownServerId = $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
// $this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/client_secret.json';
$google_client->setAuthConfig($this->container->getParameter('kernel.root_dir') . '/../src/ApplicationBundle/Resources/config/central_config.json');
// $google_client->addScope(Google_Service\Drive::DRIVE_METADATA_READONLY);
$google_client->setRedirectUri($url);
$google_client->setAccessType('offline'); // offline access
$google_client->setIncludeGrantedScopes(true); // incremental auth
$google_client->addScope('email');
$google_client->addScope('profile');
$google_client->addScope('openid');
// $google_client->setRedirectUri('http://localhost/applicant_login');
//linked in 1st
if (isset($_GET["code"]) && isset($_GET["state"])) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_URL => 'https://www.linkedin.com/oauth/v2/accessToken',
CURLOPT_USERAGENT => 'InnoPM',
CURLOPT_POSTFIELDS => urldecode("grant_type=authorization_code&code=" . $_GET["code"] . "&redirect_uri=$url&client_id=86wi39zpo46wsl&client_secret=X59ktZnreWPomqIe"),
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
)
));
$content = curl_exec($curl);
$contentArray = [];
curl_close($curl);
$token = false;
// return new JsonResponse(array(
// 'content'=>$content,
// 'contentArray'=>json_decode($content,true),
//
// ));
if ($content) {
$contentArray = json_decode($content, true);
$token = $contentArray['access_token'];
}
if ($token) {
$applicantInfo = [];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_URL => 'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,firstName,lastName,profilePicture(displayImage~:playableStreams))',
CURLOPT_USERAGENT => 'InnoPM',
CURLOPT_HTTPGET => 1,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $token,
'Header-Key-2: Header-Value-2'
)
));
$userGeneralcontent = curl_exec($curl);
curl_close($curl);
if ($userGeneralcontent) {
$userGeneralcontent = json_decode($userGeneralcontent, true);
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))',
// CURLOPT_URL => 'https://api.linkedin.com/v2/emailAddress',
CURLOPT_USERAGENT => 'InnoPM',
CURLOPT_HTTPGET => 1,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $token,
'Header-Key-2: Header-Value-2'
)
));
$userEmailcontent = curl_exec($curl);
curl_close($curl);
$token = false;
if ($userEmailcontent) {
$userEmailcontent = json_decode($userEmailcontent, true);
}
// $oAuthEmail = $applicantInfo['email'];
// return new JsonResponse(array(
// 'userEmailcontent'=>$userEmailcontent,
// 'userGeneralcontent'=>$userGeneralcontent,
// ));
// return new response($userGeneralcontent);
$oAuthData = [
'email' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
'uniqueId' => $userGeneralcontent['id'],
'image' => $userGeneralcontent['profilePicture']['displayImage~']['elements'][0]['identifiers'][0]['identifier'],
'emailVerified' => $userEmailcontent['elements'][0]['handle~']['emailAddress'],
'name' => $userGeneralcontent['localizedFirstName'] . ' ' . $userGeneralcontent['localizedLastName'],
'firstName' => $userGeneralcontent['localizedFirstName'],
'lastName' => $userGeneralcontent['localizedLastName'],
'type' => 1,
'token' => $token,
];
}
} else if (isset($_GET["code"])) {
$token = $google_client->fetchAccessTokenWithAuthCode($_GET["code"]);
if (!isset($token['error'])) {
$google_client->setAccessToken($token['access_token']);
$google_service = new Google_Service_Oauth2($google_client);
$applicantInfo = $google_service->userinfo->get();
$oAuthEmail = $applicantInfo['email'];
$oAuthData = [
'email' => $applicantInfo['email'],
'uniqueId' => $applicantInfo['id'],
'image' => $applicantInfo['picture'],
'emailVerified' => $applicantInfo['verifiedEmail'],
'name' => $applicantInfo['givenName'] . ' ' . $applicantInfo['familyName'],
'firstName' => $applicantInfo['givenName'],
'lastName' => $applicantInfo['familyName'],
'type' => $token['token_type'],
'token' => $token['access_token'],
];
}
}
if ($oAuthData['email'] != '' || $oAuthData['uniqueId'] != '') {
$isApplicantExist = $applicantRepo->findOneBy([
'email' => $oAuthData['email']
]);
if (!$isApplicantExist && $oAuthData['uniqueId'] != '') {
$isApplicantExist = $applicantRepo->findOneBy([
'oAuthUniqueId' => $oAuthData['uniqueId']
]);
}
if ($isApplicantExist) {
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
} else
return $this->redirectToRoute("user_login", [
'id' => $isApplicantExist->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
'locale' => $req->request->get('locale', 'en'),
'remoteVerify' => $req->request->get('remoteVerify', 0),
'firebaseToken' => $req->request->get('firebaseToken', ''),
]);
} else {
$fname = $oAuthData['firstName'];
$lname = $oAuthData['lastName'];
$img = $oAuthData['image'];
$email = $oAuthData['email'];
$oAuthEmail = $oAuthData['email'];
$userName = explode('@', $email)[0];
//now check if same username exists
$username_already_exist = 1;
$initial_user_name = $userName;
$timeoutSafeCount = 10;//only 10 timeout for safety if this fails just add the unix timestamp to make it unique
while ($username_already_exist == 1 && $timeoutSafeCount > 0) {
$isUsernameExist = $applicantRepo->findOneBy([
'username' => $userName
]);
if ($isUsernameExist) {
$username_already_exist = 1;
$userName = $initial_user_name . '' . rand(300, 9987);
} else {
$username_already_exist = 0;
}
$timeoutSafeCount--;
}
if ($timeoutSafeCount == 0 && $username_already_exist == 1) {
$currentUnixTimeStamp = '';
$currentUnixTime = new \DateTime();
$currentUnixTimeStamp = $currentUnixTime->format('U');
$userName = $userName . '' . $currentUnixTimeStamp;
}
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$length = 8;
$password = 0;
for ($i = 0; $i < $length; $i++) {
$password .= $characters[rand(0, $charactersLength - 1)];
}
$newApplicant = new EntityApplicantDetails();
$newApplicant->setActualRegistrationAt(new \DateTime());
$newApplicant->setEmail($email);
$newApplicant->setUserName($userName);
$newApplicant->setFirstname($fname);
$newApplicant->setLastname($lname);
$newApplicant->setOAuthEmail($oAuthEmail);
$newApplicant->setIsEmailVerified(1);
$newApplicant->setOauthUniqueId($oAuthData['uniqueId']);
$newApplicant->setAccountStatus(1);
$salt = uniqid(mt_rand());
$encodedPassword = $this->container->get('sha256salted_encoder')->encodePassword($password, $salt);
$newApplicant->setPassword($encodedPassword);
$newApplicant->setSalt($salt);
$newApplicant->setTempPassword($password);;
// $newApplicant->setPassword($password);
$marker = $userName . '-' . time();
// $extension_here=$uploadedFile->guessExtension();
// $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
// $path = $fileName;
$upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicants';
if (!file_exists($upl_dir)) {
mkdir($upl_dir, 0777, true);
}
$ch = curl_init($img);
$fp = fopen($upl_dir . '/' . $marker . '.jiff', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$newApplicant->setImage('/uploads/applicants/' . $marker . '.jiff');
// $newApplicant->setImage($img);
$newApplicant->setIsConsultant(0);
$newApplicant->setIsTemporaryEntry(0);
$newApplicant->setApplyForConsultant(0);
$em->persist($newApplicant);
$em->flush();
$isApplicantExist = $newApplicant;
if (GeneralConstant::EMAIL_ENABLED == 1) {
if ($systemType == '_BUDDYBEE_') {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/templates:buddybeeRegistrationComplete.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => $userName,
'password' => $newApplicant->getPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Welcome to BuddyBee ',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'registration@buddybee.eu',
'userName' => 'registration@buddybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
'encryptionMethod' => 'ssl',
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
} else {
$bodyHtml = '';
$bodyTemplate = 'ApplicationBundle:email/user:applicant_login.html.twig';
$bodyData = array(
'name' => $newApplicant->getFirstname() . ' ' . $newApplicant->getLastname(),
'email' => 'APP-' . $userName,
'password' => $newApplicant->getPassword(),
);
$attachments = [];
$forwardToMailAddress = $newApplicant->getOAuthEmail();
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Applicant Registration on Honeybee',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'support@ourhoneybee.eu',
'userName' => 'support@ourhoneybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
'encryptionMethod' => 'ssl',
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
}
}
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
} else {
return $this->redirectToRoute("user_login", [
'id' => $newApplicant->getApplicantId(),
'oAuthData' => $oAuthData,
'refRoute' => $refRoute,
'remoteVerify' => $req->request->get('remoteVerify', 0),
'locale' => $req->request->get('locale', 'en'),
'firebaseToken' => $req->request->get('firebaseToken', ''),
]);
}
}
}
if ($req->request->get('remoteVerify', $req->query->get('remoteVerify', 0)) == 1) {
if ($isApplicantExist) {
$user = $isApplicantExist;
$userType = UserConstants::USER_TYPE_APPLICANT;
if ($userType == UserConstants::USER_TYPE_APPLICANT) {
$session->set(UserConstants::USER_ID, $user->getApplicantId());
$session->set(UserConstants::LAST_SETTINGS_UPDATED_TS, $user->getLastSettingsUpdatedTs());
$session->set(UserConstants::IS_CONSULTANT, $user->getIsConsultant() == 1 ? 1 : 0);
$session->set('BUDDYBEE_BALANCE', 1 * $user->getAccountBalance());
$session->set('BUDDYBEE_COIN_BALANCE', 1 * $user->getSessionCountBalance());
$session->set(UserConstants::IS_BUDDYBEE_RETAILER, $user->getIsRetailer() == 1 ? 1 : 0);
$session->set(UserConstants::BUDDYBEE_RETAILER_LEVEL, $user->getRetailerLevel() == 1 ? 1 : 0);
$session->set(UserConstants::BUDDYBEE_ADMIN_LEVEL, $user->getIsAdmin() == 1 ? 3 : ($user->getIsModerator() == 1 ? 1 : 0));
$session->set(UserConstants::IS_BUDDYBEE_MODERATOR, $user->getIsModerator() == 1 ? 1 : 0);
$session->set(UserConstants::IS_BUDDYBEE_ADMIN, $user->getIsAdmin() == 1 ? 1 : 0);
// $session->set(UserConstants::SUPPLIER_ID, $user->getSupplierId());
$session->set(UserConstants::USER_TYPE, UserConstants::USER_TYPE_APPLICANT);
$session->set(UserConstants::USER_EMAIL, $user->getOauthEmail());
$session->set(UserConstants::USER_IMAGE, $user->getImage());
$session->set(UserConstants::USER_NAME, $user->getFirstName() . ' ' . $user->getLastName());
$session->set(UserConstants::USER_DEFAULT_ROUTE, '');
$session->set(UserConstants::USER_COMPANY_ID, 1);
$session->set(UserConstants::USER_COMPANY_ID_LIST, json_encode([]));
$session->set(UserConstants::USER_COMPANY_NAME_LIST, json_encode([]));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode([]));
$session->set('userCompanyDarkVibrantList', json_encode([]));
$session->set('userCompanyVibrantList', json_encode([]));
$session->set('userCompanyLightVibrantList', json_encode([]));
$session->set(UserConstants::USER_COMPANY_IMAGE_LIST, json_encode([]));
$session->set(UserConstants::USER_APP_ID, 0);
$session->set(UserConstants::USER_POSITION_LIST, '[]');
$session->set(UserConstants::ALL_MODULE_ACCESS_FLAG, 0);
$session->set(UserConstants::SESSION_SALT, uniqid(mt_rand()));
$session->set(UserConstants::APPLICATION_SECRET, $this->container->getParameter('secret'));
$session->set(UserConstants::USER_GOC_ID, 0);
$session->set(UserConstants::USER_DB_NAME, '');
$session->set(UserConstants::USER_DB_USER, '');
$session->set(UserConstants::USER_DB_PASS, '');
$session->set(UserConstants::USER_DB_HOST, '');
$session->set(UserConstants::PRODUCT_NAME_DISPLAY_TYPE, '');
$session->set(UserConstants::USER_NOTIFICATION_ENABLED, GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0);
$session->set(UserConstants::USER_NOTIFICATION_SERVER, $this->getParameter('notification_server'));
$session->set('oAuthToken', $req->request->get('oAuthToken', ''));
$session->set('locale', $req->request->get('locale', ''));
$session->set('firebaseToken', $req->request->get('firebaseToken', ''));
$route_list_array = [];
$session->set(UserConstants::USER_CURRENT_POSITION, 0);
$loginID = 0;
$loginID = MiscActions::addEntityUserLoginLog(
$em,
$session->get(UserConstants::USER_ID),
$session->get(UserConstants::USER_ID),
1,
$req->server->get("REMOTE_ADDR"),
0,
$req->request->get('deviceId', ''),
$req->request->get('oAuthToken', ''),
$req->request->get('oAuthType', ''),
$req->request->get('locale', ''),
$req->request->get('firebaseToken', '')
);
$session->set(UserConstants::USER_LOGIN_ID, $loginID);
$session_data = array(
UserConstants::USER_ID => $session->get(UserConstants::USER_ID),
UserConstants::LAST_SETTINGS_UPDATED_TS => $session->get(UserConstants::LAST_SETTINGS_UPDATED_TS),
UserConstants::USER_EMPLOYEE_ID => $session->get(UserConstants::USER_EMPLOYEE_ID),
'oAuthToken' => $session->get('oAuthToken'),
'locale' => $session->get('locale'),
'firebaseToken' => $session->get('firebaseToken'),
'token' => $session->get('token'),
'firstLogin' => 0,
'BUDDYBEE_BALANCE' => $session->get('BUDDYBEE_BALANCE'),
'BUDDYBEE_COIN_BALANCE' => $session->get('BUDDYBEE_COIN_BALANCE'),
UserConstants::IS_BUDDYBEE_RETAILER => $session->get(UserConstants::IS_BUDDYBEE_RETAILER),
UserConstants::BUDDYBEE_RETAILER_LEVEL => $session->get(UserConstants::BUDDYBEE_RETAILER_LEVEL),
UserConstants::BUDDYBEE_ADMIN_LEVEL => $session->get(UserConstants::BUDDYBEE_ADMIN_LEVEL),
UserConstants::IS_BUDDYBEE_MODERATOR => $session->get(UserConstants::IS_BUDDYBEE_MODERATOR),
UserConstants::IS_BUDDYBEE_ADMIN => $session->get(UserConstants::IS_BUDDYBEE_ADMIN),
UserConstants::USER_LOGIN_ID => $session->get(UserConstants::USER_LOGIN_ID),
UserConstants::USER_EMAIL => $session->get(UserConstants::USER_EMAIL),
UserConstants::USER_TYPE => $session->get(UserConstants::USER_TYPE),
UserConstants::USER_IMAGE => $session->get(UserConstants::USER_IMAGE),
'oAuthImage' => $session->get('oAuthImage'),
UserConstants::USER_DEFAULT_ROUTE => $session->get(UserConstants::USER_DEFAULT_ROUTE),
UserConstants::USER_NAME => $session->get(UserConstants::USER_NAME),
UserConstants::USER_COMPANY_ID => $session->get(UserConstants::USER_COMPANY_ID),
UserConstants::USER_COMPANY_ID_LIST => $session->get(UserConstants::USER_COMPANY_ID_LIST),
UserConstants::USER_COMPANY_NAME_LIST => $session->get(UserConstants::USER_COMPANY_NAME_LIST),
UserConstants::USER_COMPANY_IMAGE_LIST => $session->get(UserConstants::USER_COMPANY_IMAGE_LIST),
UserConstants::USER_APP_ID => $session->get(UserConstants::USER_APP_ID),
UserConstants::USER_CURRENT_POSITION => $session->get(UserConstants::USER_CURRENT_POSITION),
UserConstants::SESSION_SALT => $session->get(UserConstants::SESSION_SALT),
UserConstants::APPLICATION_SECRET => $session->get(UserConstants::APPLICATION_SECRET),
UserConstants::USER_POSITION_LIST => $session->get(UserConstants::USER_POSITION_LIST),
'userCompanyDarkVibrantList' => $session->get('userCompanyDarkVibrantList', []),
'userCompanyVibrantList' => $session->get('userCompanyVibrantList', []),
'userCompanyLightVibrantList' => $session->get('userCompanyLightVibrantList', []),
UserConstants::ALL_MODULE_ACCESS_FLAG => $session->get(UserConstants::ALL_MODULE_ACCESS_FLAG),
UserConstants::USER_GOC_ID => $session->get(UserConstants::USER_GOC_ID),
UserConstants::USER_DB_NAME => $session->get(UserConstants::USER_DB_NAME),
UserConstants::USER_DB_USER => $session->get(UserConstants::USER_DB_USER),
UserConstants::USER_DB_HOST => $session->get(UserConstants::USER_DB_HOST),
UserConstants::USER_DB_PASS => $session->get(UserConstants::USER_DB_PASS),
UserConstants::PRODUCT_NAME_DISPLAY_TYPE => $session->get(UserConstants::PRODUCT_NAME_DISPLAY_TYPE),
UserConstants::USER_NOTIFICATION_ENABLED => GeneralConstant::NOTIFICATION_ENABLED == 1 ? ($this->getParameter('notification_enabled') == 1 ? 1 : 0) : 0,
UserConstants::USER_NOTIFICATION_SERVER => $this->getParameter('notification_server'),
//new
'appIdList' => $session->get('appIdList'),
'branchIdList' => $session->get('branchIdList', null),
'branchId' => $session->get('branchId', null),
'companyIdListByAppId' => $session->get('companyIdListByAppId'),
'companyNameListByAppId' => $session->get('companyNameListByAppId'),
'companyImageListByAppId' => $session->get('companyImageListByAppId'),
);
$tokenData = MiscActions::CreateTokenFromSessionData($em, $session_data);
$session_data = $tokenData['sessionData'];
$token = $tokenData['token'];
$session->set('token', $token);
if ($req->request->get('remoteVerify', 0) == 1 || $req->query->get('remoteVerify', 0) == 1) {
$session->set('remoteVerified', 1);
$response = new JsonResponse(array(
'token' => $token,
'uid' => $session->get(UserConstants::USER_ID),
'session' => $session,
'success' => true,
'session_data' => $session_data,
'session2' => $_SESSION,
));
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
if ($req->request->has('referer_path')) {
if ($req->request->get('referer_path') != '/' && $req->request->get('referer_path') != '') {
return $this->redirect($req->request->get('referer_path'));
}
}
$redirectRoute = 'applicant_dashboard';
if ($req->query->has('refRoute')) {
if ($req->query->get('refRoute') == '8917922')
$redirectRoute = 'apply_for_consultant';
}
return $this->redirectToRoute($redirectRoute);
}
// $response = new JsonResponse(array(
// 'token' => $token,
// 'uid' => $session->get(UserConstants::USER_ID),
// 'session' => $session,
//
// 'success' => true,
// 'session_data' => $session_data,
// 'session2' => $_SESSION,
// ));
// $response->headers->set('Access-Control-Allow-Origin', '*');
// return $response;
// return $this->redirectToRoute("user_login", [
// 'id' => $isApplicantExist->getApplicantId(),
// 'oAuthData' => $oAuthData,
// 'refRoute' => $refRoute,
// 'locale' => $req->request->get('locale', 'en'),
// 'remoteVerify' => $req->request->get('remoteVerify', 0),
// 'firebaseToken' => $req->request->get('firebaseToken', ''),
// ]);
}
}
$selector = ConsultancyConstant::$selector;
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$twig_file = 'ApplicationBundle:pages/login:applicant_login.html.twig';
if ($systemType == '_ERP_') {
} else if ($systemType == '_CENTRAL_') {
return $this->render(
'ApplicationBundle:pages/login:central_login.html.twig',
[
'page_title' => 'Central Login',
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'message' => $message,
'systemType' => $systemType,
'ownServerId' => $ownServerId,
'errorField' => '',
'refRoute' => $refRoute,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector,
]
);
} else if ($systemType == '_BUDDYBEE_') {
return $this->render(
'ApplicationBundle:pages/login:applicant_login.html.twig',
[
'page_title' => 'BuddyBee Login',
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'message' => $message,
'errorField' => $errorField,
'refRoute' => $refRoute,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
]
);
}
return $this->render(
'ApplicationBundle:pages/login:applicant_login.html.twig',
[
'page_title' => 'Applicant Registration',
'oAuthLink' => $google_client->createAuthUrl(),
'redirect_url' => $url,
'refRoute' => $refRoute,
'message' => $message,
'errorField' => $errorField,
'state' => 'DCEeFWf45A53sdfKeSS424',
'selector' => $selector
]
);
}
public function FindAccountAction(Request $request, $encData = '')
{
// $userCategory=$request->request->has('userCategory');
$encryptedData = [];
$errorField = '';
$message = '';
$userType = '';
$otpExpireSecond = 180;
$otpExpireTs = 0;
$otp = '';
if ($encData != '')
$encryptedData = json_decode($this->get('url_encryptor')->decrypt($encData), true);
// $encryptedData = $this->get('url_encryptor')->decrypt($encData);
$userCategory = '_BUDDYBEE_USER_';
if (isset($encryptedData['userCategory']))
$userCategory = $encryptedData['userCategory'];
else
$userCategory = $request->request->get('userCategory', '_BUDDYBEE_USER_');
$em = $this->getDoctrine()->getManager('company_group');
$em_goc = $this->getDoctrine()->getManager('company_group');
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$ownServerId = $this->container->hasParameter('server_id') ? $this->container->getParameter('server_id') : '_NONE_';
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [];
$email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
$email_address = $request->request->get('email', '');
$email_twig_data = [];
$appendCode = $request->request->get('appendCode', $request->query->get('appendCode', ''));
if ($request->isMethod('POST')) {
//set an otp and its expire and send mail
$email_address = $request->request->get('email');
$userObj = null;
$userData = [];
if ($systemType == '_ERP_') {
if ($userCategory == '_APPLICANT_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'email' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'oAuthEmail' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'username' => $email_address
)
);
}
}
if ($userObj) {
$email_address = $userObj->getEmail();
if ($email_address == null || $email_address == '')
$email_address = $userObj->getOAuthEmail();
}
// triggerResetPassword:
// type: integer
// nullable: true
$otpData = MiscActions::GenerateOtp($otpExpireSecond);
$otp = $otpData['otp'];
$otpExpireTs = $otpData['expireTs'];
$userObj->setOtp($otpData['otp']);
$userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
$userObj->setOtpExpireTs($otpData['expireTs']);
$em_goc->flush();
$userData = array(
'id' => $userObj->getApplicantId(),
'email' => $email_address,
'appId' => 0,
// 'appId'=>$userObj->getUserAppId(),
);
$email_twig_file = 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
$email_twig_data = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
'otp' => $otpData['otp'],
'otpExpireSecond' => $otpExpireSecond,
'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
'otpExpireTs' => $otpData['expireTs'],
'systemType' => $systemType,
'userData' => $userData
];
if ($userObj)
$email_twig_data['success'] = true;
} else {
$userType = UserConstants::USER_TYPE_GENERAL;
$email_twig_file = 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
$email_twig_data = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
];
}
} else if ($systemType == '_CENTRAL_') {
$userType = UserConstants::USER_TYPE_ENTITY_USER_GENERAL_USER;
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
array(
'email' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
array(
'oAuthEmail' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityUser')->findOneBy(
array(
'username' => $email_address
)
);
}
}
if ($userObj) {
$email_address = $userObj->getEmail();
if ($email_address == null || $email_address == '')
$email_address = $userObj->getOAuthEmail();
// triggerResetPassword:
// type: integer
// nullable: true
$otpData = MiscActions::GenerateOtp($otpExpireSecond);
$otp = $otpData['otp'];
$otpExpireTs = $otpData['expireTs'];
$userObj->setOtp($otpData['otp']);
$userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
$userObj->setOtpExpireTs($otpData['expireTs']);
$em_goc->flush();
$userData = array(
'id' => $userObj->getApplicantId(),
'email' => $email_address,
'appId' => 0,
'image' => $userObj->getImage(),
'firstName' => $userObj->getFirstname(),
'lastName' => $userObj->getLastname(),
'phone' => $userObj->getPhone(),
// 'appId'=>$userObj->getUserAppId(),
);
$email_twig_file = 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
$email_twig_data = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
'otp' => $otpData['otp'],
'otpExpireSecond' => $otpExpireSecond,
'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
'otpExpireTs' => $otpData['expireTs'],
'systemType' => $systemType,
'userCategory' => $userCategory,
'userData' => $userData
];
$email_twig_data['success'] = true;
} else {
$message = "Oops! Could not find your account";
$email_twig_data['success'] = false;
}
} else if ($systemType == '_BUDDYBEE_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'email' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'oAuthEmail' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'username' => $email_address
)
);
}
}
if ($userObj) {
$email_address = $userObj->getEmail();
if ($email_address == null || $email_address == '')
$email_address = $userObj->getOAuthEmail();
// triggerResetPassword:
// type: integer
// nullable: true
$otpData = MiscActions::GenerateOtp($otpExpireSecond);
$otp = $otpData['otp'];
$otpExpireTs = $otpData['expireTs'];
$userObj->setOtp($otpData['otp']);
$userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
$userObj->setOtpExpireTs($otpData['expireTs']);
$em_goc->flush();
$userData = array(
'id' => $userObj->getApplicantId(),
'email' => $email_address,
'appId' => 0,
'image' => $userObj->getImage(),
'firstName' => $userObj->getFirstname(),
'lastName' => $userObj->getLastname(),
'phone' => $userObj->getPhone(),
// 'appId'=>$userObj->getUserAppId(),
);
$email_twig_file = 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
$email_twig_data = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
'otp' => $otpData['otp'],
'otpExpireSecond' => $otpExpireSecond,
'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
'otpActionTitle' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionTitle'],
'otpActionDescForMail' => UserConstants::$OTP_ACTION_DATA[UserConstants::OTP_ACTION_FORGOT_PASSWORD]['actionDescForMail'],
'otpExpireTs' => $otpData['expireTs'],
'systemType' => $systemType,
'userCategory' => $userCategory,
'userData' => $userData
];
$email_twig_data['success'] = true;
} else {
$message = "Oops! Could not find your account";
$email_twig_data['success'] = false;
}
}
if ($email_twig_data['success'] == true && GeneralConstant::EMAIL_ENABLED == 1) {
if ($systemType == '_BUDDYBEE_') {
$bodyHtml = '';
$bodyTemplate = $email_twig_file;
$bodyData = $email_twig_data;
$attachments = [];
$forwardToMailAddress = $email_address;
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Account Verification',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'no-reply@buddybee.eu',
'userName' => 'no-reply@buddybee.eu',
'password' => 'Honeybee@0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
} else if ($systemType == '_CENTRAL_') {
$bodyHtml = '';
$bodyTemplate = $email_twig_file;
$bodyData = $email_twig_data;
$attachments = [];
$forwardToMailAddress = $email_address;
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Account Verification',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'no-reply@ourhoneybee.eu',
'userName' => 'no-reply@ourhoneybee.eu',
'password' => 'Honeybee@0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
// 'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
} else {
$bodyHtml = '';
$bodyTemplate = $email_twig_file;
$bodyData = $email_twig_data;
$attachments = [];
$forwardToMailAddress = $email_address;
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
'senderHash' => '_CUSTOM_',
// 'senderHash'=>'_CUSTOM_',
'forwardToMailAddress' => $forwardToMailAddress,
'subject' => 'Applicant Registration on Honeybee',
// 'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
'attachments' => $attachments,
'toAddress' => $forwardToMailAddress,
'fromAddress' => 'support@ourhoneybee.eu',
'userName' => 'support@ourhoneybee.eu',
'password' => 'Y41dh8g0112',
'smtpServer' => 'smtp.hostinger.com',
'smtpPort' => 465,
'emailBody' => $bodyHtml,
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
// 'embedCompanyImage' => 1,
// 'companyId' => $companyId,
// 'companyImagePath' => $company_data->getImage()
));
}
}
if ($email_twig_data['success'] == true && GeneralConstant::NOTIFICATION_ENABLED == 1 && $userData['phone'] != '' && $userData['phone'] != null) {
if ($systemType == '_BUDDYBEE_') {
$searchVal = ['_OTP_', '_EXPIRE_MINUTES_', '_APPEND_CODE_'];
$replaceVal = [$otp, floor($otpExpireSecond / 60), $appendCode];
$msg = 'Use OTP _OTP_ for BuddyBee. Your OTP will expire in _EXPIRE_MINUTES_ minutes
_APPEND_CODE_';
$msg = str_replace($searchVal, $replaceVal, $msg);
$emitMarker = '_SEND_TEXT_TO_MOBILE_';
$sendType = 'all';
$socketUserIds = [];
System::SendSmsBySocket($this->container->getParameter('notification_enabled'), $msg, $userData['phone'], $emitMarker, $sendType, $socketUserIds);
} else {
}
}
if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
$response = new JsonResponse(array(
'templateData' => $twigData,
'message' => $message,
// "otp"=>'',
"otp" => $otp,
"otpExpireTs" => $otpExpireTs,
'actionData' => $email_twig_data,
'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
)
);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else if ($email_twig_data['success'] == true) {
$encData = array(
"userType" => $userType,
"otp" => '',
// "otp"=>$otp,
"otpExpireTs" => $otpExpireTs,
"otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
"userCategory" => $userCategory,
"userId" => $userData['id'],
"systemType" => $systemType,
"email" => $email_address,
);
$encDataStr = $this->get('url_encryptor')->encrypt(json_encode($encData));
$url = $this->generateUrl(
'verify_otp'
);
return $this->redirect($url . "/" . $encDataStr);
// return $this->redirectToRoute("verify_otp_forgot_password",[
//// 'encData'
//// 'id' => $isApplicantExist->getApplicantId(),
//// 'oAuthData' => $oAuthData,
//// 'refRoute' => $refRoute,
// ]);
}
}
if ($systemType == '_ERP_') {
if ($userCategory == '_APPLICANT_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'systemType' => $systemType,
'ownServerId' => $ownServerId,
'userType' => $userType,
'errorField' => $errorField,
];
} else {
$userType = UserConstants::USER_TYPE_GENERAL;
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'systemType' => $systemType,
'ownServerId' => $ownServerId,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
];
}
} else if ($systemType == '_CENTRAL_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'systemType' => $systemType,
'ownServerId' => $ownServerId,
"otp" => '',
// "otp"=>$otp,
"otpExpireTs" => $otpExpireTs,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
];
} else if ($systemType == '_BUDDYBEE_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
"otp" => '',
'systemType' => $systemType,
'ownServerId' => $ownServerId,
// "otp"=>$otp,
"otpExpireTs" => $otpExpireTs,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
];
}
if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
$response = new JsonResponse(array(
'templateData' => $twigData,
'message' => $message,
"otp" => '',
// "otp"=>$otp,
"otpExpireTs" => $otpExpireTs,
'actionData' => $email_twig_data,
'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
)
);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else {
return $this->render(
$twig_file,
$twigData
);
}
}
public function VerifyOtpAction(Request $request, $encData = '')
{
// $userCategory=$request->request->has('userCategory');
$encryptedData = [];
$errorField = '';
$message = '';
$userType = '';
$otpExpireSecond = 180;
$otpExpireTs = 0;
if ($encData != '')
$encryptedData = json_decode($this->get('url_encryptor')->decrypt($encData), true);
// $encryptedData = $this->get('url_encryptor')->decrypt($encData);
$otp = isset($encryptedData['otp']) ? $encryptedData['otp'] : 0;
$email = isset($encryptedData['email']) ? $encryptedData['email'] : 0;
$otpExpireTs = isset($encryptedData['otpExpireTs']) ? $encryptedData['otpExpireTs'] : 0;
$otpActionId = isset($encryptedData['otpActionId']) ? $encryptedData['otpActionId'] : 0;
$userId = isset($encryptedData['userId']) ? $encryptedData['userId'] : 0;
$userCategory = isset($encryptedData['otp']) ? $encryptedData['userCategory'] : '_BUDDYBEE_USER_';
$em = $this->getDoctrine()->getManager('company_group');
$em_goc = $this->getDoctrine()->getManager('company_group');
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [];
$email_twig_file = 'ApplicationBundle:pages/email:find_account_buddybee.html.twig';
$email_twig_data = [];
$userData = [];
if ($request->isMethod('POST') || $otp != '') {
$otp = $request->request->get('otp', $otp);
$otpActionId = $request->request->get('otpActionId', $otpActionId);
$userId = $request->request->get('userId', $userId);
$userCategory = $request->request->get('userCategory', $userCategory);
$email_address = $request->request->get('email', $email);
if ($systemType == '_ERP_') {
if ($userCategory == '_APPLICANT_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'email' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'oAuthEmail' => $email_address
)
);
if ($userObj) {
} else {
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'userName' => $email_address
)
);
}
}
if ($userObj) {
$email_address = $userObj->getEmail();
if ($email_address == null || $email_address == '')
$email_address = $userObj->getOAuthEmail();
}
// triggerResetPassword:
// type: integer
// nullable: true
$otpData = MiscActions::GenerateOtp($otpExpireSecond);
$userObj->setOtp($otpData['otp']);
$userObj->setOtpActionId(UserConstants::OTP_ACTION_FORGOT_PASSWORD);
$userObj->setOtpExpireTs($otpData['expireTs']);
$em_goc->flush();
$userData = array(
'id' => $userObj->getApplicantId(),
'email' => $email_address,
'appId' => 0,
// 'appId'=>$userObj->getUserAppId(),
);
$email_twig_file = 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
$email_twig_data = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
'otp' => $otpData['otp'],
'otpExpireSecond' => $otpExpireSecond,
'otpActionId' => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
'otpExpireTs' => $otpData['expireTs'],
'systemType' => $systemType,
'userData' => $userData
];
if ($userObj)
$email_twig_data['success'] = true;
} else {
$userType = UserConstants::USER_TYPE_GENERAL;
$email_twig_file = 'ApplicationBundle:email/templates:forgotPasswordOtp.html.twig';
$email_twig_data = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
];
}
} else if ($systemType == '_BUDDYBEE_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$userObj = $em_goc->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findOneBy(
array(
'applicantId' => $userId
)
);
if ($userObj) {
$userOtp = $userObj->getOtp();
$userOtpActionId = $userObj->getOtpActionId();
$userOtpExpireTs = 1 * $userObj->getOtpExpireTs();
$otpExpireTs = 1 * $userObj->getOtpExpireTs();
$currentTime = new \DateTime();
$currentTimeTs = 1 * $currentTime->format('U');
if ($userOtp != $otp) {
$message = "Invalid OTP!";
$email_twig_data['success'] = false;
} else if ($userOtpActionId != $otpActionId) {
$message = "Invalid OTP Action!";
$email_twig_data['success'] = false;
} else if ($currentTimeTs > $userOtpExpireTs) {
$message = "OTP Expired!";
$email_twig_data['success'] = false;
} else {
$userObj->setOtp(0);
$userObj->setOtpActionId(UserConstants::OTP_ACTION_NONE);
$userObj->setOtpExpireTs(0);
$userObj->setTriggerResetPassword(1);
$em_goc->flush();
$email_twig_data['success'] = true;
$message = "";
}
$userData = array(
'id' => $userObj->getApplicantId(),
'email' => $email_address,
'appId' => 0,
'image' => $userObj->getImage(),
'firstName' => $userObj->getFirstname(),
'lastName' => $userObj->getLastname(),
// 'appId'=>$userObj->getUserAppId(),
);
$email_twig_data['userData'] = $userData;
} else {
$message = "Account not found!";
$email_twig_data['success'] = false;
}
}
if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
$response = new JsonResponse(array(
'templateData' => $twigData,
'message' => $message,
'actionData' => $email_twig_data,
'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
)
);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else if ($email_twig_data['success'] == true) {
$encData = array(
"userType" => $userType,
"otp" => '',
"otpExpireTs" => $otpExpireTs,
"otpActionId" => UserConstants::OTP_ACTION_FORGOT_PASSWORD,
"userCategory" => $userCategory,
"userId" => $userData['id'],
"systemType" => $systemType,
);
$encDataStr = $this->get('url_encryptor')->encrypt(json_encode($encData));
$url = $this->generateUrl(
'reset_password_new_password'
);
return $this->redirect($url . "/" . $encDataStr);
// return $this->redirectToRoute("reset_password_new_password", [
//// 'id' => $isApplicantExist->getApplicantId(),
//// 'oAuthData' => $oAuthData,
//// 'refRoute' => $refRoute,
// ]);
}
}
if ($systemType == '_ERP_') {
if ($userCategory == '_APPLICANT_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
];
} else {
$userType = UserConstants::USER_TYPE_GENERAL;
$twig_file = 'ApplicationBundle:pages/login:find_account_buddybee.html.twig';
$twigData = [
'page_title' => 'Find Account',
'encryptedData' => $encryptedData,
'message' => $message,
'userType' => $userType,
'errorField' => $errorField,
];
}
} else if ($systemType == '_BUDDYBEE_') {
$userType = UserConstants::USER_TYPE_APPLICANT;
$twig_file = 'ApplicationBundle:pages/login:verify_otp_buddybee.html.twig';
$twigData = [
'page_title' => 'Verify Otp',
'encryptedData' => $encryptedData,
'message' => $message,
'email' => $email,
"otp" => '',
// "otp"=>$otp,
"otpExpireTs" => $otpExpireTs,
'userType' => $userType,
'userCategory' => $userCategory,
'errorField' => $errorField,
];
}
if ($request->request->has('remoteVerify') || $request->request->has('returnJson') || $request->query->has('returnJson')) {
$response = new JsonResponse(array(
'templateData' => $twigData,
'message' => $message,
'actionData' => $email_twig_data,
'success' => isset($email_twig_data['success']) ? $email_twig_data['success'] : false,
)
);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else {
return $this->render(
$twig_file,
$twigData
);
}
}
}