diff --git a/.env.sample b/.env.sample index c302d13..31df2e6 100644 --- a/.env.sample +++ b/.env.sample @@ -184,4 +184,13 @@ CORS_DEBUG=true APP_SIGNATURE = TOKENTIMEOUT = -JWT_SECRET = \ No newline at end of file +JWT_SECRET = + + +#-------------------------------------------------------------------- +# OTP Configuration +#-------------------------------------------------------------------- + +DEFAULT_OTP = '' +IS_SEND_EMAIL_OTP = +IS_SEND_SMS_OTP = \ No newline at end of file diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c5d99b3..8541d19 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -1288,6 +1288,8 @@ class EmployeeRestController extends AdminController // Execute query + + $builder->orderBy('files.id', 'desc'); $data = $builder->get()->getResultArray(); if (!empty($data)) { diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index e29c0a7..c6ea35c 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -158,10 +158,17 @@ class RestAuthenticationController extends AdminController } $otp = random_int(100000, 999999); - if($mobile_number == '9442741776') - { + $default_otp = env('DEFAULT_OTP') ?? ''; + $is_send_sms_otp = filter_var(env('IS_SEND_SMS_OTP') ?? true, FILTER_VALIDATE_BOOLEAN); + + if(!empty($default_otp)){ + $otp = $default_otp; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Sending default otp"); + } + + if($mobile_number == '9442741776') { $otp = '123456'; - $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: setting 123456 for IOS APP TESTING = " . json_encode($employeeData)); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: setting 123456 for IOS APP TESTING = " . json_encode($employeeData)); } $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Final employee data to verify = " . json_encode($employeeData)); @@ -211,13 +218,13 @@ class RestAuthenticationController extends AdminController } //skip sms for live test no - if($mobile_number == '9442741776') - { - + if($mobile_number == '9442741776' || $is_send_sms_otp == false) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: skip SMS sent for IOS APP TESTING = " . ($mobile_number)); - $result = ['user_verification' => true ,'message' => "Verified Successfully" ]; - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + $result = ['user_verification' => true ,'message' => "Verified Successfully" ]; + return $this->respond(['status' => 'success','code' => 200,'data' => $result, 'is_sms_send' => false],200); } + //send sms $SMSResult = sendOtpSms($mobile_number, $otp); if ($SMSResult['status'] == 'success') @@ -276,6 +283,14 @@ class RestAuthenticationController extends AdminController $otp = random_int(100000, 999999); + $default_otp = env('DEFAULT_OTP') ?? ''; + $is_send_email_otp = filter_var(env('IS_SEND_EMAIL_OTP') ?? true, FILTER_VALIDATE_BOOLEAN); + + if(!empty($default_otp)){ + $otp = $default_otp; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Sending default otp"); + } + //only retail policy if(empty($empdata)){ $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: No employee data found both PRE & POST"); @@ -387,6 +402,11 @@ class RestAuthenticationController extends AdminController 'mail_type' => 'otp_mail', ]; + if($is_send_email_otp == false){ + $result = ['user_verification' => true, 'message' => "Verified Successfully"]; + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'is_email_send' => false], 200); + } + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Sending OTP email to " . $employeeData['email_corporate']); $res = $this->sendEmailOtp($employeeData['email_corporate'], $otp, $common); $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Mail response = " . $res); @@ -596,6 +616,13 @@ class RestAuthenticationController extends AdminController $otp = random_int(100000, 999999); + $default_otp = env('DEFAULT_OTP') ?? ''; + $is_send_sms_otp = filter_var(env('IS_SEND_SMS_OTP') ?? true, FILTER_VALIDATE_BOOLEAN); + + if(!empty($default_otp)){ + $otp = $default_otp; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Sending default otp"); + } if ($HrData) { @@ -617,6 +644,11 @@ class RestAuthenticationController extends AdminController $data->otp = $otp; $this->callThirdPartyAPI($data, 'updateHROTP'); + if($is_send_sms_otp == false){ + $result = ['user_verification' => true, 'message' => "Verified Successfully"]; + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'is_sms_send' => false], 200); + } + //send sms $SMSResult = sendOtpSms($mobile_number, $otp); if ($SMSResult['status'] == 'success') @@ -653,6 +685,7 @@ class RestAuthenticationController extends AdminController $data = $this->request->getJSON(); + $email = $data->email; $HrData = $this->hrModel->where('email', $email) @@ -661,7 +694,16 @@ class RestAuthenticationController extends AdminController ->first(); $otp = random_int(100000, 999999); - $data->otp = $otp; + + $default_otp = env('DEFAULT_OTP') ?? ''; + $is_send_email_otp = filter_var(env('IS_SEND_EMAIL_OTP') ?? true, FILTER_VALIDATE_BOOLEAN); + + if(!empty($default_otp)){ + $otp = $default_otp; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Sending default otp"); + } + + $data->otp = $otp; if ($HrData) { @@ -685,10 +727,16 @@ class RestAuthenticationController extends AdminController $update = $db->query($sql, [$otp, $email]); if($update) - { + { + $data->otp = $otp; $this->callThirdPartyAPI($data, 'updateHROTP'); + if($is_send_email_otp == false){ + $result = ['user_verification' => true, 'message' => "Verified Successfully"]; + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'is_email_send' => false], 200); + } + $common = [ 'login_type' => 'HR login', 'login_email' => $email, @@ -1932,7 +1980,7 @@ class RestAuthenticationController extends AdminController } $decoded = $result['decoded']; - $userId = $decoded['id'] ?? null; + $userId = $decoded['pre_hr_id'] ?? null; if (!$userId) { return $this->respond([ diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php index 4eac9e5..00d985d 100755 --- a/app/Filters/AuthJWT.php +++ b/app/Filters/AuthJWT.php @@ -115,9 +115,19 @@ class AuthJWT implements FilterInterface } // Refresh sliding expiration - $model->update($id, [ - 'token_time_out' => time() + getenv('TOKENTIMEOUT') - ]); + $newExpiry = time() + getenv('TOKENTIMEOUT'); + + if (!isset($decoded['emp_code'])) { + // HR user: refresh token_time_out across all branches (same mobile/email) + // so switching branches doesn't cause an unexpected expiry + $field = !empty($user['mobile']) ? 'mobile' : 'email'; + $model->where($field, $user[$field]) + ->where('contact_type', 'client') + ->where('is_active', 1) + ->update(null, ['token_time_out' => $newExpiry]); + } else { + $model->update($id, ['token_time_out' => $newExpiry]); + } return true; } diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index f7b32ba..1715d54 100755 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -137,7 +137,7 @@ class JWTToken $token = $jwtParts[0]; try { - $decoded = JWT::decode($token, new Key("secret", 'HS512')); + $decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512')); return json_encode(['status' => true, 'message' => 'Token is valid', 'data' =>$decoded->data->id ]); } catch (ExpiredException $e) { return json_encode(['status' => false, 'message' => 'Token has expired']); @@ -159,7 +159,7 @@ class JWTToken $jwtParts = explode(' ', $jwt); $token = $jwtParts[1]; - $decoded = JWT::decode($token, new Key("secret", 'HS512')); + $decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512')); return $decoded->id; } @@ -170,7 +170,7 @@ class JWTToken $jwtParts = explode(' ', $jwt); $token = $jwtParts[1]; - $decoded = JWT::decode($token, new Key("secret", 'HS512')); + $decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512')); return $decoded->role; } @@ -182,7 +182,7 @@ class JWTToken $jwtParts = explode(' ', $jwt); $token = $jwtParts[1]; - $decoded = JWT::decode($token, new Key("secret", 'HS512')); + $decoded = JWT::decode($token, new Key(env('JWT_SECRET'), 'HS512')); return $decoded; } diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php index 29d2c76..9f651ae 100755 --- a/app/Views/client_basic_info.php +++ b/app/Views/client_basic_info.php @@ -238,6 +238,9 @@ input:checked + .slider:before { var message = (PrimaryKey === '') ? 'Client General Info Created successfully' : 'Client General Info Updated successfully'; toastr.success(message, 'Success'); $submitButton.prop('disabled', false); + let client_name = res.data.client_name ? (' - ' + res.data.client_name) : ''; + $('#client_heading').text(client_name); + }, 1000); } diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index 08e9359..7f55c01 100755 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -41,7 +41,7 @@ body {