Jenderal92

Untitled

Aug 23rd, 2022
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6.  
  7. use Auth;
  8.  
  9. use App\Models\User;
  10.  
  11.  
  12. use App\Models\PhoneVerification;
  13.  
  14. use DB;
  15.  
  16. class SMSController extends Controller
  17. {
  18.  
  19.  
  20. function sms_send($mobile,$msg,$lang='EN'){
  21.  
  22.  
  23. // Account details
  24. $apiKey = urlencode('PUT_API_KEY_HERE');
  25.  
  26. // Message details
  27. $numbers = array($mobile);
  28. $sender = urlencode('PUT_SENDER_ID_HERE');
  29. $message = rawurlencode($msg);
  30.  
  31. $numbers = implode(',', $numbers);
  32.  
  33. // Prepare data for POST request
  34. $data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);
  35.  
  36. // Send the POST request with cURL
  37. $ch = curl_init('https://api.textlocal.in/send/');
  38. curl_setopt($ch, CURLOPT_POST, true);
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  40. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  41. $response = curl_exec($ch);
  42. curl_close($ch);
  43.  
  44. // Process your response here
  45. echo $response;
  46.  
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53. function ajax_otp_send_for_login(request $request){
  54. $show_otp_on_login=0;
  55.  
  56. $send_otp=0;
  57. $phone=$request->phone;
  58. $otp=rand(1000,9999);
  59.  
  60.  
  61. $count=PhoneVerification::where('phone',$phone)->count();
  62. if($count>0){
  63.  
  64. DB::table('phone_verification')
  65. ->where('phone',$phone)
  66. ->update(['otp' =>$otp]);
  67.  
  68. }else{
  69.  
  70. DB::table('phone_verification')->insert(
  71. ['phone' =>$phone,'otp'=>$otp]
  72. );
  73.  
  74.  
  75. }
  76.  
  77.  
  78.  
  79.  
  80. $sms_msg="Your OTP to register/access ONLINEGGS is ".$otp;
  81. $this->sms_send($phone,$sms_msg);
  82.  
  83. $status=1;
  84.  
  85. //used for non SMS gateway implemented
  86. if($show_otp_on_login==1){
  87.  
  88. $message="OTP ".$otp." sent to your mobile no. ";
  89.  
  90. }else{
  91. $message="OTP sent to your mobile no. ";
  92.  
  93. }
  94.  
  95.  
  96. return response()->json(array('status'=>$status,'message'=>$message));
  97.  
  98.  
  99.  
  100.  
  101. }
  102.  
  103.  
  104.  
  105.  
  106. function check_otp_for_login_with_phone(request $request){
  107. $phone=$request->phone;
  108. $otp=$request->otp;
  109.  
  110. $status=0;
  111.  
  112. $user=User::where('phone',$phone)->where('status',1)->first();
  113.  
  114. if(!$user){
  115. return response()->json(array('status'=>$status,'message'=>'This phone no. is not registered with us!'));
  116.  
  117. }
  118.  
  119.  
  120. $count=PhoneVerification::where('phone',$phone)->where('otp',$otp)->count();
  121. if($count>0){
  122. $status=1;
  123. $message="This phone no. successfully verified";
  124.  
  125. DB::table('phone_verification')
  126. ->where('phone',$phone)
  127. ->where('otp',$otp)
  128. ->update(['is_verified' =>1]);
  129.  
  130.  
  131.  
  132.  
  133.  
  134. //login the user
  135. Auth::login($user);
  136.  
  137. ///////////
  138.  
  139. }else{
  140. $status=0;
  141. $message="Incorrect OTP";
  142. }
  143.  
  144. return response()->json(array('status'=>$status,'message'=>$message));
  145.  
  146.  
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment