FIX_LOGIN_API : RV

This commit is contained in:
VENKATESHWARAN 2025-03-03 11:56:59 +05:30
parent 9b4ecff57b
commit 6efcb610d3

View File

@ -104,65 +104,63 @@ class RestAuthenticationController extends AdminController
$email = $this->request->getJSON()->email; $email = $this->request->getJSON()->email;
$employeeData = $this->employeeModel->select('employees.relationship,EP.employee_id') $employeeData = $this->employeeModel->select('
employees.relationship,
EP.employee_id,
employees.client_id,
employees.client_branch_id,
employees.email_corporate
')
->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner')
->where('employees.is_active', 1) ->where('employees.is_active', 1)
->where('employees.relationship', 'self') ->where('employees.relationship', 'Self')
->where('employees.emp_status !=', 'truncated') ->where('employees.emp_status !=', 'truncated')
->where('employees.email_corporate', $email) ->where('employees.email_corporate', $email)
->where('EP.is_active', 1) ->where('EP.is_active', 1)
->whereIn('EP.status', ['active']) ->whereIn('EP.status', ['draft', 'enrolled'])
->first(); ->first();
if (isset($employeeData['employee_id'])) if (isset($employeeData['employee_id'])) {
{
$otp = random_int(100000, 999999); $otp = random_int(100000, 999999);
$update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'self') $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self')
->where('is_active', 1)->set(array('otp' => $otp )) ->where('is_active', 1)->set(array('otp' => $otp))
->update(); ->update();
if($update) if ($update) {
{
$common = [ $common = [
'client_id' => $employeeData['client_id'], 'client_id' => $employeeData['client_id'],
'client_branch_id' => $employeeData['client_branch_id'], 'client_branch_id' => $employeeData['client_branch_id'],
'client_policy_id' => null, 'client_policy_id' => null,
'employee_policy_id' => null, 'employee_policy_id' => null,
'employee_id' => $employeeData['id'], 'employee_id' => $employeeData['employee_id'],
'mail_type' => 'otp_mail', 'mail_type' => 'otp_mail',
]; ];
$subject = 'Nhance user verification - OTP'; $subject = 'Nhance user verification - OTP';
$mail_content = $otp.' is your verification code for Nhance.'; $mail_content = $otp . ' is your verification code for Nhance.';
$res = MailHelper::send_email(['mail' => $employeeData['email_corporate'], 'subject' => $subject ,'common'=>$common ,'message' => $mail_content]); $res = MailHelper::send_email(['mail' => $employeeData['email_corporate'], 'subject' => $subject, 'common' => $common, 'message' => $mail_content]);
$this->myLogger->logme("info", $res); $this->myLogger->logme("info", $res);
if(json_decode($res)->status == 'success') if (json_decode($res)->status == 'success') {
{ $result = ['user_verification' => true, 'message' => "Verified Successfully"];
$result = ['user_verification' => true ,'message' => "Verified Successfully"]; return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else {
$result = ['user_verification' => false, 'message' => "Mail sending failed , try again"];
}else{ return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
$result = ['user_verification' => false , 'message' => "Mail sending failed , try again"]; }
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
}
}else{
$result = ['user_verification' => false , 'message' => "Verification failed , try again"];
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
}
} else { } else {
$result = ['user_verification' => false , 'message' => "User not found"];
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200);
$result = ['user_verification' => false, 'message' => "Verification failed , try again"];
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
}
} else {
$result = ['user_verification' => false, 'message' => "User not found"];
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
} }
} catch (\Throwable $th) { } catch (\Throwable $th) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500);
} }
} }