Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
73ef321d37
@ -434,8 +434,6 @@ $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDr
|
||||
//Employee login api's
|
||||
$routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber");
|
||||
$routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData");
|
||||
$routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin");
|
||||
$routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin");
|
||||
$routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationController::verifyEmployeeWithEmailId");
|
||||
// $routes->post("/employeeRest/saveMpin", "RestAuthenticationController::saveMpin");
|
||||
|
||||
@ -450,12 +448,21 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) {
|
||||
$routes->post("getId", "RestAuthenticationController::getUserIdFromToken");
|
||||
});
|
||||
|
||||
// MPIN api's
|
||||
$routes->post("employeeRest/saveMpin", "RestAuthenticationController::saveMpin");
|
||||
$routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMpin");
|
||||
$routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin");
|
||||
$routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin");
|
||||
$routes->post("employeeRest/forgotMPIN", "RestAuthenticationController::forgotMPIN");
|
||||
$routes->post("calculatePremium", "EmployeeRestController::calculatePremium");
|
||||
$routes->post("employeeRest/updateMobileNumber", "RestAuthenticationController::updateMobileNumber");
|
||||
|
||||
// PASSWORD api's
|
||||
$routes->post("employeeRest/savePassword", "RestAuthenticationController::savePassword");
|
||||
$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");
|
||||
@ -507,11 +514,12 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) {
|
||||
$routes->post("hrFileUpload", "EmployeeRestController::hrFileUpload");
|
||||
|
||||
});
|
||||
|
||||
$routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy");
|
||||
$routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification");
|
||||
$routes->post("sendEmail", "EmployeeRestController::send_email");
|
||||
$routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData");
|
||||
|
||||
$routes->post("calculatePremium", "EmployeeRestController::calculatePremium");
|
||||
$routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrolledDetails");
|
||||
|
||||
//crone job
|
||||
|
||||
@ -504,7 +504,8 @@ class EmployeeRestController extends AdminController
|
||||
if ($dateTime instanceof \DateTime) {
|
||||
return $dateTime->format('Y-m-d');
|
||||
} else {
|
||||
return null;
|
||||
// return null;
|
||||
return change_date_format($dateString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -563,6 +563,7 @@ class RestAuthenticationController extends AdminController
|
||||
->first();
|
||||
|
||||
$otp = random_int(100000, 999999);
|
||||
$data->otp = $otp;
|
||||
|
||||
if ($HrData) {
|
||||
|
||||
@ -609,11 +610,9 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
} else {
|
||||
// Call the third-party API function
|
||||
$reqData = $this->request->getJSON();
|
||||
$reqData->otp = $otp;
|
||||
return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithEmail');
|
||||
|
||||
return $this->callThirdPartyAPI($data,'verifyHrWithEmail');
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
}
|
||||
@ -629,9 +628,9 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
if (isset($mobile_number))
|
||||
{
|
||||
$hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->where('otp', $otp)->first();
|
||||
$hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->where('is_active', 1)->where('otp', $otp)->first();
|
||||
}else{
|
||||
$hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('otp', $otp)->first();
|
||||
$hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('is_active', 1)->where('otp', $otp)->first();
|
||||
}
|
||||
|
||||
if ($hrData)
|
||||
@ -659,6 +658,9 @@ class RestAuthenticationController extends AdminController
|
||||
->join('clients', 'client_branch.client_id = clients.id', 'left')
|
||||
->where('level_contacts.mobile', $mobile_number )
|
||||
->where('level_contacts.contact_type', 'client')
|
||||
->where('level_contacts.is_active', 1)
|
||||
->where('clients.is_active', 1)
|
||||
->where('client_branch.is_active', 1)
|
||||
->findAll();
|
||||
//set otp value null
|
||||
$this->hrModel->where('mobile', $mobile_number)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
|
||||
@ -670,6 +672,9 @@ class RestAuthenticationController extends AdminController
|
||||
->join('clients', 'client_branch.client_id = clients.id', 'left')
|
||||
->where('level_contacts.email', $email )
|
||||
->where('level_contacts.contact_type', 'client')
|
||||
->where('level_contacts.is_active', 1)
|
||||
->where('clients.is_active', 1)
|
||||
->where('client_branch.is_active', 1)
|
||||
->findAll();
|
||||
//set otp value null
|
||||
$this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update();
|
||||
@ -1410,9 +1415,6 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Exception: " . $th->getMessage());
|
||||
log_message('error', ' ');
|
||||
log_message('error', ' ************************************* UPDATE MOBILE END **************************************** ');
|
||||
log_message('error', ' ');
|
||||
|
||||
$errorData = [
|
||||
'message' => $th->getMessage(),
|
||||
@ -1433,4 +1435,368 @@ class RestAuthenticationController extends AdminController
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public function savePassword()
|
||||
{
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Received payload = " . json_encode($this->request->getJSON() ?? []));
|
||||
try {
|
||||
|
||||
$payload = $this->request->getJSON();
|
||||
// print_r($payload); die;
|
||||
$mobile_number = $payload->mobile_number ?? null;
|
||||
$email_id = $payload->email_id ?? null;
|
||||
$client_id = $payload->client_id ?? null;
|
||||
$plain_password = $payload->password ?? null;
|
||||
$confirm_password = $payload->confirm_password ?? null;
|
||||
|
||||
if (empty($plain_password) || empty($confirm_password)) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Both password cannot be empty'], 400);
|
||||
}
|
||||
|
||||
if($plain_password !== $confirm_password){
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Password and confirm password not matched'], 400);
|
||||
}
|
||||
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number ]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: No employee data found both PRE and POST");
|
||||
$result = ['user_verification' => false , 'message' => "User not found"];
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
|
||||
}
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: empdata = " . json_encode($empdata));
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Using PRE data from empdata");
|
||||
}
|
||||
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$payload->client_id = $empdata['post']['client_id'];
|
||||
$payload->employee_id = $empdata['post']['employee_id'];
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Added client_id & employee_id to requestData to get the POST employee data");
|
||||
}
|
||||
|
||||
if (isset($employeeData['employee_id'])) {
|
||||
|
||||
$id = $employeeData['employee_id'];
|
||||
$hashedPassword = password_hash($plain_password, PASSWORD_DEFAULT);
|
||||
|
||||
$updateData = [
|
||||
'password' => $hashedPassword,
|
||||
];
|
||||
|
||||
$updated = $this->employeeModel->where('id', $id)->set($updateData)->update();
|
||||
|
||||
if ($updated) {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Password saved successfully");
|
||||
$this->callThirdPartyAPI($payload, 'savePassword');
|
||||
$result = ['user_verification' => true, 'message' => "Password saved successfully"];
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
|
||||
} else {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Password save failed");
|
||||
$result = ['user_verification' => true, 'message' => "Password not saved"];
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $result], 200);
|
||||
}
|
||||
} else {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Employee not found with email or mobile in the PRE DATABASE, falling back to third-party API");
|
||||
$result = ['user_verification' => false, 'message' => "User not found"];
|
||||
return $this->callThirdPartyAPI($payload, 'savePassword');
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString());
|
||||
$errorData = [
|
||||
'message' => $th->getMessage(),
|
||||
'file' => $th->getFile(),
|
||||
'line' => $th->getLine(),
|
||||
'code' => $th->getCode(),
|
||||
'trace' => $th->getTraceAsString(),
|
||||
'trace_array' => $th->getTrace(), // full array version (optional)
|
||||
'function' => $th->getTrace()[0]['function'] ?? null,
|
||||
'class' => $th->getTrace()[0]['class'] ?? null,
|
||||
];
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => $th->getMessage(), 'error_data' => $errorData], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function changePassword()
|
||||
{
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Received payload = " . json_encode($this->request->getJSON() ?? []));
|
||||
|
||||
try {
|
||||
|
||||
$payload = $this->request->getJSON(true);
|
||||
$mobile_number = $payload['mobile_number'] ?? null;
|
||||
$email_id = $payload['email_id'] ?? null;
|
||||
$client_id = $payload['client_id'] ?? null;
|
||||
$old_password = $payload['old_password'] ?? null;
|
||||
$new_password = $payload['new_password'] ?? null;
|
||||
$confirm_password = $payload['confirm_password'] ?? null;
|
||||
|
||||
if (empty($new_password) || empty($confirm_password) || empty($old_password)) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'old_password , New password and Confirm password are required' ], 400);
|
||||
}
|
||||
|
||||
// Fetch employee details
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number ]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: No employee data found both PRE and POST");
|
||||
$result = ['user_verification' => false , 'message' => "User not found"];
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
|
||||
}
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: empdata = " . json_encode($empdata));
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Using PRE data from empdata");
|
||||
}
|
||||
|
||||
if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) {
|
||||
$payload['client_id'] = $empdata['post']['client_id'];
|
||||
$payload['employee_id'] = $empdata['post']['employee_id'];
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Added client_id & employee_id to requestData to get the POST employee data");
|
||||
}
|
||||
|
||||
if (isset($employeeData['employee_id']) && password_verify($old_password, $employeeData['password'])) {
|
||||
|
||||
// Hash new password
|
||||
// $newHashedPassword = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
$newHashedPassword = $new_password;
|
||||
|
||||
// Update password and clear OTP
|
||||
$updated = $this->employeeModel->update($employeeData['employee_id'], [
|
||||
'password' => $newHashedPassword,
|
||||
]);
|
||||
|
||||
if ($updated) {
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Password updated successfully");
|
||||
|
||||
// Call the third-party API function
|
||||
$this->callThirdPartyAPI($payload, 'changePassword');
|
||||
return $this->respond(['status' => 'success','code' => 200,'message' => 'Password changed successfully' ], 200);
|
||||
} else {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'message' => 'Failed to update password'], 500);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Employee not verified - calling third-party API fallback to get the POST employee data");
|
||||
|
||||
// Call the third-party API function
|
||||
return $this->callThirdPartyAPI($payload, 'changePassword');
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Exception: " . $th->getMessage());
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => $th->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyPassword()
|
||||
{
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Received payload = " . json_encode($this->request->getJSON() ?? []));
|
||||
|
||||
try {
|
||||
|
||||
$requestData = $this->request->getJSON(true);
|
||||
$mobile_number = $requestData['mobile_number'] ?? null;
|
||||
$email_id = $requestData['email_id'] ?? null;
|
||||
$client_id = $requestData['client_id'] ?? null;
|
||||
$password = $requestData['password'] ?? null;
|
||||
|
||||
if (!$password) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => "", 'message' => 'Password is required'], 400);
|
||||
}
|
||||
|
||||
// 🔹 Fetch employee data
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyMpin: No employee data found both PRE and POST");
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => ""], 200);
|
||||
}
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyMpin: empdata = " . json_encode($empdata));
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyMpin: Using PRE data from empdata");
|
||||
}
|
||||
|
||||
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 - verifyMpin: Added client_id to requestData to get the POST employee data");
|
||||
}
|
||||
|
||||
// 🔹 Verify password hash
|
||||
if (isset($employeeData['employee_id']) && password_verify($password, $employeeData['password'])) {
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Verified employee found");
|
||||
|
||||
// ✅ Log authentication info
|
||||
$auth = HttpRequestHelper::getRequestInfo();
|
||||
if ($auth) {
|
||||
$this->authHistoryModel->insert([
|
||||
'user_id' => $employeeData['employee_id'],
|
||||
'user_type' => 'employee',
|
||||
'ip' => $auth['ip'],
|
||||
'platform' => $auth['platform'],
|
||||
'broswer' => $auth['browser'],
|
||||
]);
|
||||
}
|
||||
|
||||
// ✅ Generate JWT token
|
||||
unset($employeeData['employee_id']);
|
||||
$employeeData['token_type'] = "pre";
|
||||
$token = JWTToken::encode($employeeData);
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($requestData, 'verifyPassword');
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $token, 'post_enrollment' => json_decode($apiResponse, true)], 200);
|
||||
|
||||
} else {
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Employee not verified - calling third-party API fallback to get the POST employee data");
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($requestData, 'verifyPassword');
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => "", 'post_enrollment' => json_decode($apiResponse, true)], 200);
|
||||
}
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine());
|
||||
$errorData = [
|
||||
'message' => $th->getMessage(),
|
||||
'file' => $th->getFile(),
|
||||
'line' => $th->getLine(),
|
||||
'code' => $th->getCode(),
|
||||
'trace' => $th->getTraceAsString(),
|
||||
'trace_array' => $th->getTrace(), // full array version (optional)
|
||||
'function' => $th->getTrace()[0]['function'] ?? null,
|
||||
'class' => $th->getTrace()[0]['class'] ?? null,
|
||||
];
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => "", 'message' => $th->getMessage(), 'error_data' => $errorData], 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function verifyOtp()
|
||||
{
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Received payload = " . json_encode($this->request->getJSON() ?? []));
|
||||
|
||||
try {
|
||||
|
||||
$requestData = $this->request->getJSON(true);
|
||||
$mobile_number = $requestData['mobile_number'] ?? null;
|
||||
$email_id = $requestData['email_id'] ?? null;
|
||||
$client_id = $requestData['client_id'] ?? null;
|
||||
$otp = $requestData['otp'] ?? null;
|
||||
|
||||
if (!$otp) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => "", 'message' => 'OTP is required'], 400);
|
||||
}
|
||||
|
||||
// 🔹 Fetch employee data
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
if(empty($empdata)){
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: No employee data found both PRE and POST");
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => ""], 200);
|
||||
}
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: empdata = " . json_encode($empdata));
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Using PRE data from empdata");
|
||||
}
|
||||
|
||||
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 - verifyOtp: Added client_id to requestData to get the POST employee data");
|
||||
}
|
||||
|
||||
// 🔹 Verify password hash
|
||||
if ($employeeData && $employeeData['otp'] == $otp) {
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Verified employee found");
|
||||
$this->employeeModel->where('id', $employeeData['id'])->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update();
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'message' => "OTP verified succesfully"], 200);
|
||||
|
||||
} else {
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Employee not verified - calling third-party API fallback to get the POST employee data");
|
||||
|
||||
// Call the third-party API function
|
||||
return $this->callThirdPartyAPI($requestData, 'verifyOtp');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Exception: " . $e->getMessage() . " --- Line: " . $e->getLine());
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => "", 'message' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ class EmployeeModel extends Model
|
||||
"mpin",
|
||||
"is_mpin_skipped",
|
||||
"is_biometric_enabled",
|
||||
"password",
|
||||
];
|
||||
|
||||
// Callbacks
|
||||
|
||||
Loading…
Reference in New Issue
Block a user