GWM : sms api integration
This commit is contained in:
parent
2dbb0ad464
commit
74938ec1e5
@ -90,5 +90,5 @@ class Autoload extends AutoloadConfig
|
|||||||
*
|
*
|
||||||
* @var list<string>
|
* @var list<string>
|
||||||
*/
|
*/
|
||||||
public $helpers = ['JwtHelper','common_helper','mail_helper','url_helper','status_helper'];
|
public $helpers = ['JwtHelper','common_helper','mail_helper','url_helper','status_helper','sms_helper'];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,8 +31,26 @@ class AgentAuthController extends ResourceController
|
|||||||
|
|
||||||
if (isset($agentData['id']))
|
if (isset($agentData['id']))
|
||||||
{
|
{
|
||||||
$result = ['agent_verification' => true ,'message' => "Verified Successfully"];
|
|
||||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
$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 {
|
} else {
|
||||||
|
|
||||||
@ -90,27 +108,23 @@ class AgentAuthController extends ResourceController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null;
|
|
||||||
$mobile = isset($this->request->getJSON()->mobile) ? $this->request->getJSON()->mobile : null;
|
$mobile = isset($this->request->getJSON()->mobile) ? $this->request->getJSON()->mobile : null;
|
||||||
|
|
||||||
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
|
|
||||||
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : 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))
|
if (isset($mobile))
|
||||||
{
|
{
|
||||||
$agentData = $this->AgentModel->where('mobile', $mobile)->where('is_active', 1)->first();
|
$agentData = $this->AgentModel->where('mobile', $mobile)->where('is_active', 1)->where('email_otp', $otp)->first();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$agentData = $this->AgentModel->where('email', $email)->where('email_otp', $otp)->where('is_active', 1)->first();
|
$agentData = $this->AgentModel->where('email', $email)->where('email_otp', $otp)->where('is_active', 1)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($agentData && $otp_verification == true || $agentData && isset($this->request->getJSON()->otp) ) {
|
if ($agentData && isset($this->request->getJSON()->otp) ) {
|
||||||
|
|
||||||
if(isset($this->request->getJSON()->otp)){
|
|
||||||
$this->AgentModel->where('id', $agentData['id'])->where('email_otp', $otp)->where('is_active', 1)->set(['email_otp'=>null])->update();
|
$this->AgentModel->where('id', $agentData['id'])->where('email_otp', $otp)->where('is_active', 1)->set(['email_otp'=>null])->update();
|
||||||
}
|
|
||||||
|
|
||||||
$result = generateJWT($agentData);
|
$result = generateJWT($agentData);
|
||||||
|
|
||||||
|
|||||||
@ -31,8 +31,25 @@ class StaffAuthController extends ResourceController
|
|||||||
|
|
||||||
if (isset($StaffData['id']))
|
if (isset($StaffData['id']))
|
||||||
{
|
{
|
||||||
$result = ['Staff_verification' => true ,'message' => "Verified Successfully"];
|
$otp = random_int(100000, 999999);
|
||||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
|
||||||
|
$update = $this->StaffModel->where('mobile', $mobile)->where('is_active', 1)->set(['email_otp' => $otp])->update();
|
||||||
|
|
||||||
|
if ($update) {
|
||||||
|
|
||||||
|
$SMSResult = sendOtpSms($mobile,$otp);
|
||||||
|
|
||||||
|
if ($SMSResult['status'] == 'success') {
|
||||||
|
$result = ['Staff_verification' => true, 'message' => "Verified Successfully"];
|
||||||
|
return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200);
|
||||||
|
} else {
|
||||||
|
$result = ['Staff_verification' => false, 'message' => "Mail sending failed , try again"];
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = ['Staff_verification' => false, 'message' => "Verification failed , try again"];
|
||||||
|
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -90,27 +107,23 @@ class StaffAuthController extends ResourceController
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$otp_verification = isset($this->request->getJSON()->otp_verification) ? $this->request->getJSON()->otp_verification : null;
|
|
||||||
$mobile = isset($this->request->getJSON()->mobile) ? $this->request->getJSON()->mobile : null;
|
$mobile = isset($this->request->getJSON()->mobile) ? $this->request->getJSON()->mobile : null;
|
||||||
|
|
||||||
$otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null;
|
|
||||||
$email = isset($this->request->getJSON()->email) ? $this->request->getJSON()->email : 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))
|
if (isset($mobile))
|
||||||
{
|
{
|
||||||
$StaffData = $this->StaffModel->where('mobile', $mobile)->where('is_active', 1)->first();
|
$StaffData = $this->StaffModel->where('mobile', $mobile)->where('is_active', 1)->where('email_otp', $otp)->first();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$StaffData = $this->StaffModel->where('email', $email)->where('email_otp', $otp)->where('is_active', 1)->first();
|
$StaffData = $this->StaffModel->where('email', $email)->where('email_otp', $otp)->where('is_active', 1)->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($StaffData && $otp_verification == true || $StaffData && isset($this->request->getJSON()->otp) ) {
|
if ($StaffData && isset($this->request->getJSON()->otp) ) {
|
||||||
|
|
||||||
if(isset($this->request->getJSON()->otp)){
|
|
||||||
$this->StaffModel->where('id', $StaffData['id'])->where('email_otp', $otp)->where('is_active', 1)->set(['email_otp'=>null])->update();
|
$this->StaffModel->where('id', $StaffData['id'])->where('email_otp', $otp)->where('is_active', 1)->set(['email_otp'=>null])->update();
|
||||||
}
|
|
||||||
|
|
||||||
$result = generateJWT($StaffData);
|
$result = generateJWT($StaffData);
|
||||||
|
|
||||||
|
|||||||
40
app/Helpers/sms_helper.php
Normal file
40
app/Helpers/sms_helper.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use CodeIgniter\Database\BaseConnection;
|
||||||
|
|
||||||
|
if (!function_exists('sendOtpSms')) {
|
||||||
|
|
||||||
|
|
||||||
|
function sendOtpSms(string $mobile, string $otp)
|
||||||
|
{
|
||||||
|
$apiKey = env('SMS_API_KEY');
|
||||||
|
$senderId = env('SMS_SENDER_ID');
|
||||||
|
$templateId = env('SMS_TEMPLATE_ID');
|
||||||
|
$serviceName = env('SMS_SERVICE_NAME');
|
||||||
|
$appName = env('SMS_APP_NAME');
|
||||||
|
|
||||||
|
// Replace variables {#var#}
|
||||||
|
$message = "Hi, Your One Time Code for logging into Nhance {$appName} App is {$otp}. Valid for 3 minutes. Please do not share this with anyone. -NHANCE";
|
||||||
|
|
||||||
|
// Build the API URL
|
||||||
|
$url = "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?" . http_build_query([
|
||||||
|
'APIKEY' => $apiKey,
|
||||||
|
'MobileNo' => $mobile,
|
||||||
|
'SenderID' => $senderId,
|
||||||
|
'Message' => $message,
|
||||||
|
'ServiceName' => $serviceName,
|
||||||
|
'DLTTemplateID' => $templateId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Send request
|
||||||
|
$response = @file_get_contents($url);
|
||||||
|
|
||||||
|
// If response failed
|
||||||
|
if ($response === FALSE) {
|
||||||
|
return ['status' => 'failed', 'message' => 'Failed to send SMS.'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return ['status' => 'success', 'message' => 'OTP sent successfully', 'api_response' => $response];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user