From a9dae0ea7640e1cb786156e78506c6e10ce35bf4 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 10 Nov 2025 14:37:37 +0530 Subject: [PATCH] FEAT_CHECK_PASS --- app/Config/Routes.php | 2 + .../RestAuthenticationController.php | 47 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a713956..fb8e437 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -461,6 +461,8 @@ $routes->post("employeeRest/savePassword", "RestAuthenticationController::savePa $routes->post("employeeRest/changePassword", "RestAuthenticationController::changePassword"); $routes->post("employeeRest/verifyPassword", "RestAuthenticationController::verifyPassword"); $routes->post("employeeRest/verifyOtp", "RestAuthenticationController::verifyOtp"); +$routes->post("employeeRest/checkPassword", "RestAuthenticationController::checkPassword"); + // $routes->post("employeeRest/createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount"); // $routes->post("employeeRest/calculatePremium", "EmployeeRestController::calculatePremium"); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 30d4f89..23b8891 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -1747,5 +1747,52 @@ class RestAuthenticationController extends AdminController } } + public function checkPassword() + { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Request payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $payload = $this->request->getJSON() ?? []; + $mobile_number = $payload->mobile_number ?? null; + $email_id = $payload->email_id ?? null; + + $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number, 'check_mpin' => true]); + // print_r($empdata); die; + + if(empty($empdata)){ + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: No employee data found both PRE and POST"); + return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200); + } + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: empdata = " . json_encode($empdata)); + + $employeeData = []; + if (isset($empdata['pre']) && !empty($empdata['pre'])) { + $employeeData = $empdata['pre']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Using PRE data from empdata"); + } + + $requestData = $this->request->getJSON(); + if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + $requestData->client_id = $empdata['post']['client_id']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Added client_id to requestData to get the POST employee data"); + } + + + if ($employeeData && $employeeData["password"] != null) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Mpin - Exist"); + return $this->respond(['status' => 'success','code' => 200,'data' => "", 'message' => "Password - exist"],200); + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Password - not found in PRE so call the thirdpartapi to the POST to check the MPIN"); + return $this->callThirdPartyAPI($requestData, 'checkPassword'); + } + + } catch (\Exception $e) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - Exception: " . $e->getMessage() . " --- Line: " . $e->getLine() . " --- Trace: " . $e->getTraceAsString()); + return $this->respond(['status' => 'failed','code' => 500,'data' => "", 'message' => $e->getMessage()],500); + } + } + }