GWM : hr auth api

This commit is contained in:
Gowtham M 2025-10-09 10:29:45 +05:30
parent 5dd082fe0c
commit 78dccf1c21

View File

@ -74,18 +74,7 @@ class RestAuthenticationController extends AdminController
return $response->getBody(); 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 = []) public function callThirdPartyGETAPI($queryParams, $endPoint, $params = [])
{ {
@ -115,6 +104,18 @@ class RestAuthenticationController extends AdminController
// employee auth api's start // employee auth api's start
public function verifyEmployeeWithMobileNumber() public function verifyEmployeeWithMobileNumber()
@ -461,27 +462,76 @@ class RestAuthenticationController extends AdminController
// employee auth api's end // employee auth api's end
// HR auth api's start // HR auth api's start
public function verifyHrWithMobileNumber() public function verifyHrWithMobileNumber()
{ {
try { try {
$mobile_number = $this->request->getJSON()->mobile_number;
$data = $this->request->getJSON();
$mobile_number = $data->mobile_number;
$HrData = $this->hrModel->where('mobile', $mobile_number) $HrData = $this->hrModel->where('mobile', $mobile_number)
->where('contact_type', 'client') ->where('contact_type', 'client')
->where('is_active', 1) ->where('is_active', 1)
->first(); ->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); 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 { } 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 // Call the third-party API function
return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithMobileNumber'); $reqData = $this->request->getJSON();
$reqData->otp = $otp;
return $this->callThirdPartyAPI($reqData,'verifyHrWithMobileNumber');
} }
} catch (\Throwable $th) { } catch (\Throwable $th) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
} }
@ -500,9 +550,11 @@ class RestAuthenticationController extends AdminController
->where('is_active', 1) ->where('is_active', 1)
->first(); ->first();
$otp = random_int(100000, 999999);
if ($HrData) { if ($HrData) {
$otp = random_int(100000, 999999);
$sql = " $sql = "
UPDATE level_contacts UPDATE level_contacts
@ -545,6 +597,8 @@ class RestAuthenticationController extends AdminController
} else { } else {
// Call the third-party API function // Call the third-party API function
$reqData = $this->request->getJSON();
$reqData->otp = $otp;
return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithEmail'); return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithEmail');
} }
@ -556,21 +610,19 @@ class RestAuthenticationController extends AdminController
public function getVerifiedHrData() public function getVerifiedHrData()
{ {
try { 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; $otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : 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)) 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{ }else{
$hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('otp', $otp)->first(); $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(); $auth = HttpRequestHelper::getRequestInfo();
@ -596,10 +648,10 @@ class RestAuthenticationController extends AdminController
->where('level_contacts.mobile', $mobile_number ) ->where('level_contacts.mobile', $mobile_number )
->where('level_contacts.contact_type', 'client') ->where('level_contacts.contact_type', 'client')
->findAll(); ->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)){ }else if(isset($this->request->getJSON()->email)){
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
$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') $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') ->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.email', $email )
->where('level_contacts.contact_type', 'client') ->where('level_contacts.contact_type', 'client')
->findAll(); ->findAll();
//set otp value null
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
} }
if(count($getAllhrData)) if(count($getAllhrData))
{ {
$db2 = \Config\Database::connect('postDB'); $db2 = \Config\Database::connect('postDB');
foreach ($getAllhrData as $key => $value) { foreach ($getAllhrData as $key => $value) {
@ -635,26 +692,18 @@ class RestAuthenticationController extends AdminController
} }
} }
}
// Call the third-party API function
$apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData'); $apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData , 'post_enrollment'=> json_decode($apiResponse, true)],200); 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 }else {
// $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'; // Call the third-party API function
// $result = JWTToken::encode($hrData['0']); $apiResponse = $this->callThirdPartyAPI($this->request->getJSON(),'getVerifiedHrData');
return $this->respond(['status' => 'failed','code' => 404,'data' => "" , 'post_enrollment'=> json_decode($apiResponse, true)],200);
// // 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 { } else {