GWM : HR auth api
This commit is contained in:
parent
03608dbda4
commit
fa233c2bcb
@ -79,10 +79,6 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function verifyEmployeeWithMobileNumber()
|
||||
{
|
||||
log_message('error', ' ');
|
||||
@ -339,58 +335,7 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
}
|
||||
|
||||
// public function updateEmpMPIN()
|
||||
// {
|
||||
// $requestData = $this->request->getJSON();
|
||||
// print_r($requestData); die;
|
||||
// $mobile_number = $requestData->mobile_number ?? null;
|
||||
// $email_id = $requestData->email_id ?? null;
|
||||
// $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null;
|
||||
// $old_mpin = $requestData->old_mpin ?? null;
|
||||
// $is_mpin_skipped = $requestData->is_mpin_skipped ?? null;
|
||||
// $is_biometric_enabled = $requestData->is_biometric_enabled ?? null;
|
||||
|
||||
// if (!$new_mpin) {
|
||||
// return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']);
|
||||
// }
|
||||
|
||||
// $query = $this->employeeModel->where('relationship', 'self');
|
||||
|
||||
// if ($mobile_number) {
|
||||
// $query->where('mobile', $mobile_number);
|
||||
// } elseif ($email_id) {
|
||||
// $query->where('email_corporate', $email_id);
|
||||
// } else {
|
||||
// return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']);
|
||||
// }
|
||||
|
||||
// if (!empty($old_mpin)) {
|
||||
// $query->where('mpin', $old_mpin);
|
||||
// }
|
||||
|
||||
// // Fetch employee data
|
||||
// $employeeData = $query->first();
|
||||
|
||||
// if (!$employeeData) {
|
||||
// return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']);
|
||||
// }
|
||||
|
||||
// if(!empty($is_mpin_skipped) && !empty($is_biometric_enabled)){
|
||||
// $mpin_data_to_updata = [
|
||||
// 'mpin' => $new_mpin,
|
||||
// 'is_mpin_skipped' => $is_mpin_skipped,
|
||||
// 'is_biometric_enabled' => $is_biometric_enabled
|
||||
// ];
|
||||
// }else{
|
||||
// $mpin_data_to_updata = ['mpin' => $new_mpin];
|
||||
// }
|
||||
|
||||
// // Update MPIN
|
||||
// $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_updata);
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
public function updateEmpMPIN()
|
||||
{
|
||||
try {
|
||||
@ -553,17 +498,43 @@ class RestAuthenticationController extends AdminController
|
||||
public function verifyHrWithMobileNumber()
|
||||
{
|
||||
try {
|
||||
$mobile_number = $this->request->getJSON()->mobile_number;
|
||||
|
||||
$data = $this->request->getJSON();
|
||||
|
||||
$mobile_number = $data->mobile_number;
|
||||
$otp = $data->otp;
|
||||
|
||||
$HrData = $this->hrModel->where('mobile', $mobile_number)
|
||||
->where('contact_type', 'client')
|
||||
->where('is_active', 1)
|
||||
->first();
|
||||
|
||||
|
||||
|
||||
if ($HrData) {
|
||||
|
||||
$result = ['user_verification' => true ,'message' => "Verified Successfully"];
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
||||
$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)
|
||||
{
|
||||
|
||||
//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 {
|
||||
$result = ['user_verification' => false , 'message' => "User not found"];
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
|
||||
@ -581,6 +552,7 @@ class RestAuthenticationController extends AdminController
|
||||
$data = $this->request->getJSON();
|
||||
|
||||
$email = $data->email;
|
||||
$otp = $data->otp;
|
||||
|
||||
$HrData = $this->hrModel->where('email', $email)
|
||||
->where('contact_type', 'client')
|
||||
@ -588,8 +560,6 @@ class RestAuthenticationController extends AdminController
|
||||
->first();
|
||||
|
||||
if ($HrData) {
|
||||
|
||||
$otp = random_int(100000, 999999);
|
||||
|
||||
$sql = "
|
||||
UPDATE level_contacts
|
||||
@ -604,7 +574,7 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
if($update)
|
||||
{
|
||||
$data->otp = $otp;
|
||||
|
||||
|
||||
$common = [
|
||||
'login_type' => 'HR login',
|
||||
@ -637,39 +607,53 @@ class RestAuthenticationController extends AdminController
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function updateHROTP()
|
||||
{
|
||||
|
||||
$email = $this->request->getJSON()->email;
|
||||
$otp = $this->request->getJSON()->otp;
|
||||
|
||||
$this->hrModel->where('email', $email) ->where('contact_type', 'client')
|
||||
->where('is_active', 1)->set(array('otp' => $otp))
|
||||
->update();
|
||||
|
||||
$email = $this->request->getJSON()->email ?? null;
|
||||
$mobile_number = $this->request->getJSON()->mobile_number ?? null;
|
||||
$otp = $this->request->getJSON()->otp ?? null;
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
$builder = $this->hrModel
|
||||
->where('contact_type', 'client')
|
||||
->where('is_active', 1);
|
||||
|
||||
if (!empty($email)) {
|
||||
$builder->where('email', $email);
|
||||
} elseif (!empty($mobile_number)) {
|
||||
$builder->where('mobile', $mobile_number);
|
||||
}
|
||||
|
||||
$builder->set(['otp' => $otp])->update();
|
||||
|
||||
if ($this->hrModel->db->affectedRows() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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
|
||||
try {
|
||||
|
||||
$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();
|
||||
@ -689,23 +673,25 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
if(isset($this->request->getJSON()->mobile_no)){
|
||||
|
||||
$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.pre_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('clients', 'client_branch.client_id = clients.id', 'left')
|
||||
->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)){
|
||||
}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')
|
||||
->join('clients', 'client_branch.client_id = clients.id', 'left')
|
||||
->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();
|
||||
|
||||
$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.pre_branch_id')
|
||||
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
|
||||
->join('clients', 'client_branch.client_id = clients.id', 'left')
|
||||
->where('level_contacts.email', $email )
|
||||
->where('level_contacts.contact_type', 'client')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
if(count($getAllhrData))
|
||||
@ -734,29 +720,26 @@ class RestAuthenticationController extends AdminController
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData ],200);
|
||||
|
||||
}else {
|
||||
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "" , 'message' => 'User not found' ],200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $getAllhrData ],200);
|
||||
|
||||
|
||||
// $HRAccessData = $this->getHRAccessData( $hrData['0']['id'] , 'post_enrollment');
|
||||
|
||||
// if(isset($HRAccessData['allowed_modules'])){ $hrData['0']['allowed_modules'] = json_decode($HRAccessData['allowed_modules'],true)['post']; }else{ $hrData['0']['allowed_modules'] = []; }
|
||||
|
||||
// $hrData['0']['token_type'] = 'post';
|
||||
// $result = JWTToken::encode($hrData['0']);
|
||||
|
||||
|
||||
// return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "" ],200);
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => "" , 'message' => 'User not found' ],200);
|
||||
}
|
||||
// } catch (\Exception $e) {
|
||||
// return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);
|
||||
// }
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user