FEAT_RETAIL_UENIFITS_LOGIN
This commit is contained in:
parent
0f0211e465
commit
6cc12a8731
@ -264,26 +264,63 @@ class RestAuthenticationController extends AdminController
|
||||
$empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email]);
|
||||
// print_r($empdata); die;
|
||||
|
||||
$otp = random_int(100000, 999999);
|
||||
|
||||
if(empty($empdata)){
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: No employee data found both PRE & POST");
|
||||
log_message('error', ' ');
|
||||
log_message('error', '************************ PRE END ********************************');
|
||||
|
||||
$retailUserdata = RestAuthHelper::getRetailUserData(['email_id' => $email]);
|
||||
// print_r($retailUserdata); die;
|
||||
|
||||
if (!empty($retailUserdata)) {
|
||||
|
||||
$retailApiParams['client_id'] = $retailUserdata['id'];
|
||||
$retailApiParams['email_id'] = $email;
|
||||
$retailApiParams['otp'] = $otp;
|
||||
|
||||
// update the otp in retail user
|
||||
$api_response = $this->callThirdPartyAPI($retailApiParams, 'updateRetailUserAuthDetails');
|
||||
$api_response = json_decode($api_response ?? '{}', true) ?? $api_response;
|
||||
// print_r($api_response); die;
|
||||
if (isset($api_response['status']) && $api_response['status'] == true) {
|
||||
|
||||
//send Email
|
||||
$retail_common = [
|
||||
'client_id' => $retailUserdata['id'],
|
||||
'client_branch_id' => null,
|
||||
'client_policy_id' => null,
|
||||
'employee_policy_id' => null,
|
||||
'employee_id' => null,
|
||||
'mail_type' => 'retail_user_otp_mail',
|
||||
];
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Sending Retail user OTP email to " . $email);
|
||||
$res = $this->sendEmailOtp($email, $otp, $retail_common);
|
||||
|
||||
if (json_decode($res)->status == 'success') {
|
||||
$result = ['user_verification' => true, 'message' => "Verified Successfully"];
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
|
||||
} else {
|
||||
$result = ['user_verification' => false, 'message' => "Mail sending failed , try again"];
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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 - verifyEmployeeWithEmailId: employee data both PRE & POST = " . json_encode($empdata));
|
||||
|
||||
|
||||
|
||||
$employeeData = [];
|
||||
if (isset($empdata['pre']) && !empty($empdata['pre'])) {
|
||||
$employeeData = $empdata['pre'];
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Using PRE data");
|
||||
}
|
||||
|
||||
$otp = random_int(100000, 999999);
|
||||
|
||||
if (isset($employeeData['employee_id']))
|
||||
{
|
||||
|
||||
@ -321,7 +358,6 @@ class RestAuthenticationController extends AdminController
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Calling callThirdPartyAPI for updateEmpOTP");
|
||||
}
|
||||
|
||||
|
||||
//send Email
|
||||
$common = [
|
||||
'client_id' => $employeeData['client_id'],
|
||||
@ -332,11 +368,8 @@ class RestAuthenticationController extends AdminController
|
||||
'mail_type' => 'otp_mail',
|
||||
];
|
||||
|
||||
$subject = 'Nhance user verification - OTP';
|
||||
$mail_content = $otp . ' is your verification code for Nhance.';
|
||||
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Sending OTP email to " . $employeeData['email_corporate']);
|
||||
$res = MailHelper::send_email(['mail' => $employeeData['email_corporate'], 'subject' => $subject, 'common' => $common, 'message' => $mail_content]);
|
||||
$res = $this->sendEmailOtp($employeeData['email_corporate'], $otp, $common);
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: Mail response = " . $res);
|
||||
|
||||
if (json_decode($res)->status == 'success') {
|
||||
@ -350,6 +383,7 @@ class RestAuthenticationController extends AdminController
|
||||
$result = ['user_verification' => false, 'message' => "Mail sending failed , try again"];
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithEmailId: OTP update failed in PRE DATABASE");
|
||||
log_message('error', ' ');
|
||||
@ -407,8 +441,23 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
if(empty($empdata)){
|
||||
$this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedUserData: empdata is empty");
|
||||
log_message('error', ' ');
|
||||
log_message('error', '************************ PRE END ********************************');
|
||||
|
||||
$retailUserdata = RestAuthHelper::getRetailUserData(['email_id' => $email_id, 'mobile_number' => $mobile_number, 'otp' => $otp]);
|
||||
// print_r($retailUserdata); die;
|
||||
|
||||
if (!empty($retailUserdata)) {
|
||||
|
||||
$retailApiParams['client_id'] = $retailUserdata['id'];
|
||||
$retailApiParams['email_id'] = $email_id;
|
||||
$retailApiParams['mobile_number'] = $mobile_number;
|
||||
$retailApiParams['otp'] = $otp;
|
||||
|
||||
// Call the third-party API function
|
||||
$apiResponse = $this->callThirdPartyAPI($retailApiParams, 'getVerifiedRetailUserData');
|
||||
// print_r($apiResponse); die;
|
||||
return $this->respond(['status' => 'success', 'code' => 200, 'data' => [], 'post_enrollment' => json_decode($apiResponse, true)], 200);
|
||||
}
|
||||
|
||||
return $this->respond(['status' => 'Invalid OTP','code' => 404,'data' => "", 'message' => "Invalid OTP"],200);
|
||||
}
|
||||
|
||||
@ -484,6 +533,15 @@ class RestAuthenticationController extends AdminController
|
||||
|
||||
// employee auth api's end
|
||||
|
||||
public function sendEmailOtp($email, $otp, $common)
|
||||
{
|
||||
$subject = 'Nhance user verification - OTP';
|
||||
$mail_content = $otp . ' is your verification code for Nhance.';
|
||||
$response = MailHelper::send_email(['mail' => $email, 'subject' => $subject, 'common' => $common, 'message' => $mail_content]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -383,7 +383,7 @@ class RestAuthHelper
|
||||
return $data;
|
||||
}
|
||||
|
||||
log_message('warning', 'No mobile or email present in params for post fetch.');
|
||||
log_message('error', 'No mobile or email present in params for post fetch.');
|
||||
}
|
||||
|
||||
public static function updatePreMpin(array $params)
|
||||
@ -440,4 +440,60 @@ class RestAuthHelper
|
||||
log_message('warning', '[updatePostMpin] Missing required parameters: employee_id or mpin');
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
public static function getRetailUserData(array $params)
|
||||
{
|
||||
log_message('error', 'Function getRetailUserData called with: ' . json_encode($params));
|
||||
|
||||
$mobile_number = $params['mobile_number'] ?? null;
|
||||
$email_id = $params['email_id'] ?? null;
|
||||
$otp = $params['otp'] ?? null;
|
||||
$old_mpin = $params['old_mpin'] ?? null;
|
||||
|
||||
if (!empty($mobile_number) || !empty($email_id)) {
|
||||
|
||||
$client = \Config\Services::curlrequest();
|
||||
$endPoint = 'getRetailUserData';
|
||||
$url = env('POST_ENROLLMENT_BASEURL') . $endPoint;
|
||||
$headers = [
|
||||
'App-Signature' => getenv('APP_SIGNATURE'),
|
||||
];
|
||||
|
||||
$postData = [];
|
||||
|
||||
if (!empty($mobile_number)) {
|
||||
$postData['mobile_number'] = $mobile_number;
|
||||
}
|
||||
|
||||
if (!empty($email_id)) {
|
||||
$postData['email_id'] = $email_id;
|
||||
}
|
||||
|
||||
if (!empty($otp)) {
|
||||
$postData['otp'] = $otp;
|
||||
}
|
||||
|
||||
if (!empty($old_mpin)) {
|
||||
$postData['old_mpin'] = $old_mpin;
|
||||
}
|
||||
|
||||
log_message('error', 'Sending POST to external API: ' . $url);
|
||||
log_message('error', 'POST payload: ' . json_encode($postData));
|
||||
|
||||
$response = $client->post($url, ['json' => $postData, 'headers' => $headers, 'http_errors' => false]);
|
||||
|
||||
$post_json = $response->getBody();
|
||||
// print_r($post_json);
|
||||
|
||||
$post_data = json_decode($post_json, true);
|
||||
|
||||
$data = $post_data['data'] ?? [];
|
||||
log_message('error', 'Parsed post_data: ' . json_encode($data));
|
||||
return $data;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user