myLogger = \Config\Services::mylogger(); $this->AgentModel = new AgentModel(); } public function verifyAgentWithMobileNumber() { try { $mobile = $this->request->getJSON()->mobile; $agentData = $this->AgentModel->where('mobile', $mobile)->where('is_active', 1)->first(); if (isset($agentData['id'])) { $otp = random_int(100000, 999999); $update = $this->AgentModel->where('mobile', $mobile)->where('is_active', 1)->set(['email_otp' => $otp])->update(); if ($update) { $SMSResult = sendOtpSms($mobile,$otp); if ($SMSResult['status'] == 'success') { $result = ['agent_verification' => true, 'message' => "Verified Successfully"]; return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); } else { $result = ['agent_verification' => false, 'message' => "Mail sending failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['agent_verification' => false, 'message' => "Verification failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['agent_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); } } public function verifyAgentWithEmailId() { try { $email = $this->request->getJSON()->email; $agentData = $this->AgentModel->where('email', $email)->where('is_active', 1)->first(); if (isset($agentData['id'])) { $otp = random_int(100000, 999999); $update = $this->AgentModel->where('email', $email)->where('is_active', 1)->set(['email_otp' => $otp])->update(); if ($update) { $EmailResult = trigger_email('login_otp',['email'=>$email, 'name'=>$agentData['name'], 'otp'=>$otp, ]); if ($EmailResult['status'] == 'success') { $result = ['agent_verification' => true, 'message' => "Verified Successfully"]; return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); } else { $result = ['agent_verification' => false, 'message' => "Mail sending failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['agent_verification' => false, 'message' => "Verification failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } } else { $result = ['agent_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); } } public function getVerifiedAgentData() { try { $mobile = isset($this->request->getJSON()->mobile) ? $this->request->getJSON()->mobile : null; $email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : null; $otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null; if (isset($mobile)) { $agentData = $this->AgentModel->where('mobile', $mobile)->where('is_active', 1)->where('email_otp', $otp)->first(); } else { $agentData = $this->AgentModel->where('email', $email)->where('email_otp', $otp)->where('is_active', 1)->first(); } if ($agentData && isset($this->request->getJSON()->otp) ) { $this->AgentModel->where('id', $agentData['id'])->where('email_otp', $otp)->where('is_active', 1)->set(['email_otp'=>null])->update(); $result = generateJWT($agentData); return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { return $this->respond(['status' => 'failed','code' => 404,'data' => 'Please try again'],200); } } catch (\Exception $e) { return $this->respond(['status' => 'failed','code' => 500,'data' =>[], 'error' => $e->getMessage()],500); } } }