CHANGE_MPIN : RV

This commit is contained in:
VENKATESHWARAN 2025-07-01 14:10:57 +05:30
parent 80e979d361
commit ba3b7c6ece
3 changed files with 95 additions and 3 deletions

View File

@ -458,6 +458,7 @@ $routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpi
$routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationController::verifyEmployeeWithEmailId");
$routes->post("/employeeRest/updateEmpOTP", "RestAuthenticationController::updateEmpOTP");
$routes->post("/employeeRest/updateEmpMPIN", "RestAuthenticationController::updateEmpMPIN");
$routes->post("employeeRest/forgotMPIN", "RestAuthenticationController::forgotMPIN");
// $routes->post("/employeeRest/saveMpin", "RestAuthenticationController::saveMpin");

View File

@ -512,13 +512,20 @@ 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){
$result = ['user_verification' => true , 'message' => "Mpin Updated"];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
@ -639,7 +646,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);
}
@ -648,6 +655,88 @@ 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->respond(['status' => 'failed','code' => 404,'data' => "Employee not found"],200); }
} catch (\Throwable $e) {
log_message('error', 'Exception in forgotMPIN(): ' . $e->getMessage());
return $this->respond([
'status' => 'failed',
'code' => 500,
'message' => 'Server error: ' . $e->getMessage()
], 500);
}
}
// TokenController.php
public function bookstackLoginToken()

View File

@ -42,7 +42,9 @@ class EmployeeModel extends Model
"token_time_out",
"emp_type",
"unit",
"mpin"
"mpin",
"is_mpin_skipped",
"is_biometric_enabled",
];
// Callbacks