diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 752d116c..616a69cd 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -102,70 +102,68 @@ class RestAuthenticationController extends AdminController { try { $email = $this->request->getJSON()->email; - - $employeeData = $this->employeeModel->select('employees.relationship,EP.employee_id') - ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') - ->where('employees.is_active', 1) - ->where('employees.relationship', 'self') - ->where('employees.emp_status !=', 'truncated') - ->where('employees.email_corporate', $email) - ->where('EP.is_active', 1) - ->whereIn('EP.status', ['active']) - ->first(); - - if (isset($employeeData['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') + ->where('employees.is_active', 1) + ->where('employees.relationship', 'Self') + ->where('employees.emp_status !=', 'truncated') + ->where('employees.email_corporate', $email) + ->where('EP.is_active', 1) + ->whereIn('EP.status', ['draft', 'enrolled']) + ->first(); + + if (isset($employeeData['employee_id'])) { $otp = random_int(100000, 999999); - $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'self') - ->where('is_active', 1)->set(array('otp' => $otp )) - ->update(); - if($update) - { + $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self') + ->where('is_active', 1)->set(array('otp' => $otp)) + ->update(); + if ($update) { $common = [ 'client_id' => $employeeData['client_id'], 'client_branch_id' => $employeeData['client_branch_id'], 'client_policy_id' => null, 'employee_policy_id' => null, - 'employee_id' => $employeeData['id'], + 'employee_id' => $employeeData['employee_id'], 'mail_type' => 'otp_mail', - ]; + ]; $subject = 'Nhance user verification - OTP'; - $mail_content = $otp.' is your verification code for Nhance.'; - $res = MailHelper::send_email(['mail' => $employeeData['email_corporate'], 'subject' => $subject ,'common'=>$common ,'message' => $mail_content]); + $mail_content = $otp . ' is your verification code for Nhance.'; + $res = MailHelper::send_email(['mail' => $employeeData['email_corporate'], 'subject' => $subject, 'common' => $common, 'message' => $mail_content]); $this->myLogger->logme("info", $res); - 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); + 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); } + } else { - }else{ - - $result = ['user_verification' => false , 'message' => "Verification failed , try again"]; - 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); - + $result = ['user_verification' => false, 'message' => "User not found"]; + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } catch (\Throwable $th) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); } } - + public function getVerifiedUserData() {