diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 67cbf08..98e80cc 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -445,6 +445,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->post("employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); $routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMpin"); +$routes->post("employeeRest/forgotMPIN", "RestAuthenticationController::forgotMPIN"); $routes->post("calculatePremium", "EmployeeRestController::calculatePremium"); // $routes->post("employeeRest/createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount"); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 6ebd109..2f0b72b 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -492,13 +492,18 @@ class RestAuthenticationController extends AdminController } $mpin = $this->request->getJSON()->mpin; + $is_mpin_skipped = $this->request->getJSON()->is_mpin_skipped; + $is_biometric_enabled = $this->request->getJSON()->is_biometric_enabled; - - + $mpin_data_to_updata = [ + 'mpin' => $mpin, + 'is_mpin_skipped' => $is_mpin_skipped, + 'is_biometric_enabled' => $is_biometric_enabled + ]; if ($employeeData) { $id= $employeeData["id"]; - $updateMpin = $this->employeeModel->where('id', $id)->set('mpin', $mpin)->update(); + $updateMpin = $this->employeeModel->where('id', $id)->set($mpin_data_to_updata)->update(); if($updateMpin){ $this->callThirdPartyAPI($this->request->getJSON(), 'updateEmpMPIN'); $result = ['user_verification' => true , 'message' => "Mpin Updated"]; @@ -623,7 +628,7 @@ class RestAuthenticationController extends AdminController if ($employeeData && $employeeData["mpin"] != null) { - return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"]],200); + return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"], 'is_mpin_skipped' => $employeeData['is_mpin_skipped'], 'is_biometric_enabled' => $employeeData['is_biometric_enabled']],200); } else { // return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200); return $this->callThirdPartyAPI($this->request->getJSON(), 'checkMpin'); @@ -634,6 +639,86 @@ class RestAuthenticationController extends AdminController } } + public function forgotMPIN() + { + try { + log_message('info', 'forgotMPIN() called.'); - + $json = $this->request->getJSON(); + $mobile_number = $json->mobile_number ?? null; + $email_id = $json->email_id ?? null; + + log_message('info', 'Received input - Mobile: ' . var_export($mobile_number, true) . ', Email: ' . var_export($email_id, true)); + + // Step 1: Check input + if (!$mobile_number && !$email_id) { + log_message('error', 'Mobile number and email ID are both missing.'); + return $this->respond([ + 'status' => 'failed', + 'code' => 400, + 'message' => 'Mobile number or email ID is required.' + ], 400); + } + + // Step 2: Fetch employee data + if ($mobile_number) { + log_message('info', 'Looking up employee by mobile number: ' . $mobile_number); + $employeeData = $this->employeeModel + ->where('mobile', $mobile_number) + ->where('relationship', 'self') + ->first(); + } else { + log_message('info', 'Looking up employee by email: ' . $email_id); + $employeeData = $this->employeeModel + ->where('email_corporate', $email_id) + ->where('relationship', 'self') + ->first(); + } + + // Step 3: Found employee + if (!empty($employeeData)) { + log_message('info', 'Employee found: ID = ' . $employeeData['id']); + + $updateData = [ + 'mpin' => null, + 'is_mpin_skipped' => null, + 'is_biometric_enabled' => null + ]; + + log_message('info', 'Updating employee MPIN fields to null for ID: ' . $employeeData['id']); + + $updated = $this->employeeModel + ->where('id', $employeeData['id']) + ->set($updateData) + ->update(); + + if ($updated) { + log_message('info', 'MPIN reset successful for employee ID: ' . $employeeData['id']); + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'MPIN reset successfully.' + ], 200); + } else { + log_message('error', 'Failed to update MPIN fields for employee ID: ' . $employeeData['id']); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Could not reset MPIN values.', + ], 500); + } + } else { + // Step 4: Not found in local DB — call external fallback + log_message('warning', 'Employee not found locally. Falling back to third-party API.'); + return $this->callThirdPartyAPI($json, 'forgotMPIN'); + } + } catch (\Throwable $e) { + log_message('error', 'Exception in forgotMPIN(): ' . $e->getMessage()); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Server error: ' . $e->getMessage() + ], 500); + } + } } \ No newline at end of file diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 97c2dfe..3a23f98 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -42,7 +42,9 @@ class EmployeeModel extends Model "token_time_out", "emp_type", "unit", - "mpin" + "mpin", + "is_mpin_skipped", + "is_biometric_enabled", ]; // Callbacks diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 2622d41..5e6227b 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -160,7 +160,7 @@