From b1533f4f8cd91125c03488fa35b327839ab551ef Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 8 Oct 2025 17:07:07 +0530 Subject: [PATCH] GWM --- .../RestAuthenticationController.php | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 8ef10b0..1634c60 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -258,22 +258,7 @@ class RestAuthenticationController extends AdminController $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: employee data both PRE & POST = " . json_encode($empdata)); - // $employeeData = $this->employeeModel->select(' - // employees.relationship, - // EP.employee_id, - // employees.client_id, - // employees.client_branch_id, - // employees.email_corporate - - // ') - // ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') - // ->where('employees.is_active', 1) - // ->where('employees.relationship', 'Self') - // ->where('employees.emp_status !=', 'truncated') - // ->where('employees.email_corporate', $email) - // ->where('EP.is_active', 1) - // ->whereIn('EP.status', ['draft', 'enrolled', 'expired']) - // ->first(); + $employeeData = []; if (isset($empdata['pre']) && !empty($empdata['pre'])) { @@ -281,15 +266,12 @@ class RestAuthenticationController extends AdminController $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Using PRE data"); } + $otp = random_int(100000, 999999); - if (isset($employeeData['employee_id'])) { + if (isset($employeeData['employee_id'])) + { $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Valid employee found, generating OTP"); - $otp = random_int(100000, 999999); - - // $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'self') - // ->where('is_active', 1)->set(array('otp' => $otp )) - // ->update(); $sql = " UPDATE employees @@ -303,7 +285,7 @@ class RestAuthenticationController extends AdminController "; $db = db_connect(); - // $update = $db->query($sql, [$otp, $email]); + $update = $db->query($sql, [$otp, $employeeData['employee_id']]); $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: OTP update query executed. SQL = " . $db->getLastQuery()); @@ -311,17 +293,20 @@ class RestAuthenticationController extends AdminController if($update) { $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: OTP updated successfully in PRE DATABASE"); - $data->otp = $otp; + + //If post-enrollment data exist update the same otp generated from pre-enrollment. if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + $data->otp = $otp; $data->client_id = $empdata['post']['client_id']; $data->employee_id = $empdata['post']['employee_id']; $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Attached otp, client_id and employee_id from POST data to update the otp"); + + $this->callThirdPartyAPI($data, 'updateEmpOTP'); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Calling callThirdPartyAPI for updateEmpOTP"); } - $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Calling callThirdPartyAPI for updateEmpOTP"); - $this->callThirdPartyAPI($data, 'updateEmpOTP'); - + //send Email $common = [ 'client_id' => $employeeData['client_id'], 'client_branch_id' => $employeeData['client_branch_id'], @@ -359,15 +344,16 @@ class RestAuthenticationController extends AdminController } else { $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Employee not found with email in the PRE DATABASE, falling back to third-party API"); + + // Call the third-party API function $apiParams = $this->request->getJSON(); if (!empty($empdata['post']['client_id'])) { $apiParams->client_id = $empdata['post']['client_id']; } - // print_r($apiParams); die; - // Call the third-party API function + $apiParams->otp = $otp; + return $this->callThirdPartyAPI($apiParams, 'verifyEmployeeEmailId'); log_message('error', ' '); log_message('error', '************************ PRE END ********************************'); - return $this->callThirdPartyAPI($apiParams, 'verifyEmployeeEmailId'); } } catch (\Throwable $th) { log_message('error', ' ');