GWM : hr auth api
This commit is contained in:
parent
5dd082fe0c
commit
78dccf1c21
@ -74,18 +74,7 @@ class RestAuthenticationController extends AdminController
|
||||
return $response->getBody();
|
||||
}
|
||||
|
||||
// public function callThirdPartyGETAPI($queryParams, $endPoint)
|
||||
// {
|
||||
// $client = \Config\Services::curlrequest();
|
||||
// $url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
|
||||
// $response = $client->get($url, [
|
||||
// 'query' => $queryParams, // pass as query parameters
|
||||
// 'http_errors' => false // prevent exception on non-200 status
|
||||
// ]);
|
||||
|
||||
// return $response->getBody();
|
||||
// }
|
||||
|
||||
public function callThirdPartyGETAPI($queryParams, $endPoint, $params = [])
|
||||
{
|
||||
@ -115,6 +104,18 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// employee auth api's start
|
||||
|
||||
public function verifyEmployeeWithMobileNumber()
|
||||
@ -461,27 +462,76 @@ class RestAuthenticationController extends AdminController
|
||||
// employee auth api's end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// HR auth api's start
|
||||
|
||||
public function verifyHrWithMobileNumber()
|
||||
{
|
||||
try {
|
||||
$mobile_number = $this->request->getJSON()->mobile_number;
|
||||
|
||||
$data = $this->request->getJSON();
|
||||
|
||||
$mobile_number = $data->mobile_number;
|
||||
|
||||
$HrData = $this->hrModel->where('mobile', $mobile_number)
|
||||
->where('contact_type', 'client')
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
|
||||
if ($HrData) {
|
||||
$otp = random_int(100000, 999999);
|
||||
|
||||
$result = ['user_verification' => true ,'message' => "Verified Successfully"];
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
||||
} else {
|
||||
// Call the third-party API function
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithMobileNumber');
|
||||
|
||||
if ($HrData)
|
||||
{
|
||||
|
||||
$sql = "UPDATE level_contacts SET otp = ? WHERE mobile = ? AND contact_type = 'client' AND is_active = 1";
|
||||
|
||||
$db = db_connect();
|
||||
$update = $db->query($sql, [$otp, $mobile_number]);
|
||||
|
||||
if($update)
|
||||
{
|
||||
//update otp in post-enrollment
|
||||
$data->otp = $otp;
|
||||
$this->callThirdPartyAPI($data, 'updateHROTP');
|
||||
|
||||
//send sms
|
||||
$SMSResult = sendOtpSms($mobile_number, $otp);
|
||||
if ($SMSResult['status'] == 'success')
|
||||
{
|
||||
$result = ['user_verification' => true, 'message' => "Verified Successfully"];
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
|
||||
} else {
|
||||
$result = ['user_verification' => false, 'message' => "SMS sending failed , try again"];
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
|
||||
}
|
||||
|
||||
}else {
|
||||
$result = ['user_verification' => false, 'message' => "SMS sending failed , try again"];
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
// Call the third-party API function
|
||||
$reqData = $this->request->getJSON();
|
||||
$reqData->otp = $otp;
|
||||
return $this->callThirdPartyAPI($reqData,'verifyHrWithMobileNumber');
|
||||
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
}
|
||||
@ -500,9 +550,11 @@ class RestAuthenticationController extends AdminController
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
|
||||
$otp = random_int(100000, 999999);
|
||||
|
||||
if ($HrData) {
|
||||
|
||||
$otp = random_int(100000, 999999);
|
||||
|
||||
|
||||
$sql = "
|
||||
UPDATE level_contacts
|
||||
@ -545,6 +597,8 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
} else {
|
||||
// Call the third-party API function
|
||||
$reqData = $this->request->getJSON();
|
||||
$reqData->otp = $otp;
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithEmail');
|
||||
|
||||
}
|
||||
@ -556,21 +610,19 @@ class RestAuthenticationController extends AdminController
|
||||
public function getVerifiedHrData()
|
||||
{
|
||||
try {
|
||||
// mobile number
|
||||
$otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null;
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_no) ? $this->request->getJSON()->mobile_no : null;
|
||||
// email id
|
||||
|
||||
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
|
||||
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : null;
|
||||
$mobile_number = isset($this->request->getJSON()->mobile_no) ? $this->request->getJSON()->mobile_no : null;
|
||||
|
||||
if (isset($mobile_number))
|
||||
{
|
||||
$hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first();
|
||||
$hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->where('otp', $otp)->first();
|
||||
}else{
|
||||
$hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('otp', $otp)->first();
|
||||
}
|
||||
|
||||
if ($hrData && $otp_verification == true || $hrData && isset($this->request->getJSON()->otp) )
|
||||
if ($hrData)
|
||||
{
|
||||
|
||||
$auth = HttpRequestHelper::getRequestInfo();
|
||||
@ -596,10 +648,10 @@ class RestAuthenticationController extends AdminController
|
||||
->where('level_contacts.mobile', $mobile_number )
|
||||
->where('level_contacts.contact_type', 'client')
|
||||
->findAll();
|
||||
//set otp value null
|
||||
$this->hrModel->where('mobile', $mobile_number)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
|
||||
|
||||
}else if(isset($this->request->getJSON()->otp)){
|
||||
|
||||
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
|
||||
}else if(isset($this->request->getJSON()->email)){
|
||||
|
||||
$getAllhrData = $this->hrModel->select('level_contacts.id ,level_contacts.mobile , level_contacts.email , clients.id as client_id, clients.client_name, clients.short_name , client_branch.id as client_branch_id,client_branch.branch_name , client_branch.post_branch_id')
|
||||
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
|
||||
@ -607,10 +659,15 @@ class RestAuthenticationController extends AdminController
|
||||
->where('level_contacts.email', $email )
|
||||
->where('level_contacts.contact_type', 'client')
|
||||
->findAll();
|
||||
//set otp value null
|
||||
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
|
||||
}
|
||||
|
||||
|
||||
if(count($getAllhrData))
|
||||
{
|
||||
|
||||
|
||||
$db2 = \Config\Database::connect('postDB');
|
||||
foreach ($getAllhrData as $key => $value) {
|
||||
|
||||
@ -635,27 +692,19 @@ class RestAuthenticationController extends AdminController
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
|
||||
}else {
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "" , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
}
|
||||
|
||||
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
|
||||
//call and get allowed module data from post enrollment
|
||||
// $queryParams = [
|
||||
// 'hr_id' => $hrData['0']['id'],
|
||||
// 'request_for' => 'pre_enrollment'
|
||||
// ];
|
||||
// $HRAccessRes = $this->callThirdPartyGETAPI($queryParams,'getHRAccessData');
|
||||
// $HRAccessData = json_decode($HRAccessRes,true);
|
||||
// if(isset($HRAccessData['data']['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['data']['allowed_modules'],true)['pre']; }else{ $hrData['0']['allowed_modules'] = []; }
|
||||
|
||||
// $hrData['0']['token_type'] = 'pre';
|
||||
// $result = JWTToken::encode($hrData['0']);
|
||||
|
||||
// // Call the third-party API function
|
||||
// $apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
|
||||
// return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'post_enrollment'=> json_decode($apiResponse, true)],200);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user