From 7108b95562e0bf98d4524db2b2009e2556c7dbfd Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Mon, 16 Jun 2025 12:07:27 +0530 Subject: [PATCH] HR login api : GWM --- app/Config/Routes.php | 2 + .../RestAuthenticationController.php | 138 ++++++++++++++++-- 2 files changed, 131 insertions(+), 9 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c5eed924..0318acfd 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -442,7 +442,9 @@ $routes->post("/employeeRest/updateEmpOTP", "RestAuthenticationController::updat //HR login api's $routes->post("/employeeRest/verifyHrWithMobileNumber", "RestAuthenticationController::verifyHrWithMobileNumber"); +$routes->post("/employeeRest/verifyHrWithEmail", "RestAuthenticationController::verifyHrWithEmail"); $routes->post("/employeeRest/getVerifiedHrData", "RestAuthenticationController::getVerifiedHrData"); +$routes->post("/employeeRest/updateHROTP", "RestAuthenticationController::updateHROTP"); // Test initiate Claim $routes->post('initiateClaim',"EmployeeRestController::initiateClaim"); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 3d141b2b..e82548c9 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -65,6 +65,12 @@ class RestAuthenticationController extends AdminController } + + + + + + public function verifyEmployeeWithMobileNumber() { try { @@ -178,7 +184,6 @@ class RestAuthenticationController extends AdminController } - public function getVerifiedUserData() { try { @@ -232,6 +237,13 @@ class RestAuthenticationController extends AdminController } } + + + + + + + public function verifyHrWithMobileNumber() { try { @@ -255,16 +267,105 @@ class RestAuthenticationController extends AdminController return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } + + public function verifyHrWithEmail() + { + try { + + $data = $this->request->getJSON(); + + $email = $data->email; + + $HrData = $this->hrModel->where('email', $email) + ->where('contact_type', 'client') + ->where('is_active', 1) + ->first(); + + if ($HrData) { + + $otp = random_int(100000, 999999); + + $sql = " + UPDATE level_contacts + SET otp = ? + WHERE email = ? + AND contact_type = 'client' + AND is_active = 1 + "; + + $db = db_connect(); + $update = $db->query($sql, [$otp, $email]); + + if($update) + { + $data->otp = $otp; + + $common = [ + 'login_type' => 'HR login', + 'login_email' => $email, + 'mail_type' => 'otp_mail' + ]; + $subject = 'Nhance user verification - OTP'; + $mail_content = $otp . ' is your verification code for Nhance.'; + $res = MailHelper::send_email(['mail' => $email, 'subject' => $subject, 'common' => $common, 'message' => $mail_content]); + $this->myLogger->logme("info", $res); + + if (json_decode($res)->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' => "Mail sending failed , try again"]; + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); + } + } else { + + $result = ['user_verification' => false, 'message' => "Verification 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); + } + } catch (\Throwable $th) { + 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(); + + return true; + + } public function getVerifiedHrData() { try { - $mobile_number = $this->request->getJSON()->mobile_number; - $otp_verification = $this->request->getJSON()->otp_verification; + // mobile number + $otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null; + $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : 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; + + if (isset($mobile_number)) + { + $hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->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) ) + { - $hrData = $this->hrModel->where('mobile', $mobile_number)->first(); - if ($hrData && $otp_verification == true) { $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $data = [ @@ -280,15 +381,34 @@ class RestAuthenticationController extends AdminController } - $hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id') + if(isset($this->request->getJSON()->mobile_number)){ + + $hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id') + ->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left') + ->where('level_contacts.mobile', $mobile_number ) + ->where('level_contacts.contact_type', 'client') + ->find(); + + }else if(isset($this->request->getJSON()->otp)){ + + $this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update(); + + $hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id') ->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left') - ->where('level_contacts.mobile', $mobile_number ) + ->where('level_contacts.email', $email ) + ->where('level_contacts.contact_type', 'client') ->find(); + } $result = JWTToken::encode($hrData['0']); - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + + + return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200); + + } else { - return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); + + return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP" ],200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500);