From a0acf1860fa3a1726708d4f089085a43bfd39bc0 Mon Sep 17 00:00:00 2001 From: Ritikesh yadav Date: Thu, 2 May 2024 17:55:37 +0530 Subject: [PATCH] fixing api or register account and resend otp for email and phone --- app/Http/Controllers/AuthController.php | 105 ++++++++++++++++++------ public/assets/js/FrontendJs/script.js | 2 +- 2 files changed, 82 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 7e91b79..ce2cb5a 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -615,21 +615,30 @@ class AuthController extends Controller // ]); $otp = $this->otpGenerate($request->email); - $mobile_otp = $this->otpGenerate($request->contact_number); + // $mobile_otp = $this->otpGenerate($request->contact_number); $mailData = [ 'title' => 'Mail from ItSolutionStuff.com', 'body' => 'This is for testing email using smtp.' ]; Mail::to($request->email)->send(new OtpMail($mailData, $otp)); - $this->thirdPartyOTP($request->contact_number, $mobile_otp); + // $this->thirdPartyOTP($request->contact_number, $mobile_otp); //here we are storing mobile and contact in UserOTp table - $insertOtp = UserOtp::create([ - 'contact_number' => $request->contact_number, - 'email' => $request->email, //emai - 'expire_at' => Carbon::now()->addMinutes('5'), - 'otp' => $otp, //email otp - 'contact_otp' => $mobile_otp //contact OTP + // $insertOtp = UserOtp::create([ + // 'contact_number' => $request->contact_number, + // 'email' => $request->email, //emai + // 'expire_at' => Carbon::now()->addMinutes('5'), + // 'otp' => $otp, //email otp + // 'contact_otp' => $mobile_otp //contact OTP + // ]); + + $insertOtp = RegistrationOtp::create([ + 'contact_number'=>$request->contact_number, + // 'contact_otp'=>$mobile_otp, + // 'contact_expire_at'=>Carbon::now()->addMinutes('4'), + 'email'=>$request->email, + 'email_otp'=>$otp, + 'email_expire_at'=>Carbon::now()->addMinutes('2'), ]); return response()->json(['status' => 200, 'message' => 'OTP has been sent to your Email & Contact no.']); @@ -706,19 +715,28 @@ class AuthController extends Controller // } $otp = $this->otpGenerate($request->email2); - $mobile_otp = $this->otpGenerate($request->contact_number2); + // $mobile_otp = $this->otpGenerate($request->contact_number2); $mailData = [ 'title' => 'Mail from ItSolutionStuff.com', 'body' => 'This is for testing email using smtp.' ]; Mail::to($request->email2)->send(new OtpMail($mailData, $otp)); - $this->thirdPartyOTP($request->contact_number2, $mobile_otp); - $insertOtp = UserOtp::create([ - 'contact_number' => $request->contact_number2, - 'email' => $request->email2, //emai - 'expire_at' => Carbon::now()->addMinutes('5'), - 'otp' => $otp, //email otp - 'contact_otp' => $mobile_otp //contact OTP + // $this->thirdPartyOTP($request->contact_number2, $mobile_otp); + // $insertOtp = UserOtp::create([ + // 'contact_number' => $request->contact_number2, + // 'email' => $request->email2, //emai + // 'expire_at' => Carbon::now()->addMinutes('5'), + // 'otp' => $otp, //email otp + // 'contact_otp' => $mobile_otp //contact OTP + // ]); + + $insertOtp = RegistrationOtp::create([ + 'contact_number'=>$request->contact_number2, + // 'contact_otp'=>$mobile_otp, + // 'contact_expire_at'=>Carbon::now()->addMinutes('4'), + 'email'=>$request->email2, + 'email_otp'=>$otp, + 'email_expire_at'=>Carbon::now()->addMinutes('2'), ]); return response()->json(['status' => 200, 'message' => 'OTP has been sent to your Email & Contact no.']); @@ -781,14 +799,17 @@ class AuthController extends Controller $emailOtp = $request->email_otp; $emailToAdd = $request->email; - $userEmailOtpData = UserOtp::where('email', $emailToAdd)->where('otp', $emailOtp)->first(); // checking user email otp data + $userEmailOtpData = RegistrationOtp::where('email', $emailToAdd)->where('email_otp', $emailOtp)->first(); // checking user email otp data if (!$userEmailOtpData) { return response()->json(['status' => 400, 'message' => 'Email OTP Did Not Matched!'], 400); } - if (now() > $userEmailOtpData->expire_at) { + if (now() > $userEmailOtpData->email_expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } if ($userEmailOtpData) { + $otp = rand(1000,9999); + $this->thirdPartyOTP($userEmailOtpData->contact_number, $otp); + RegistrationOtp::where('email', $emailToAdd)->update(['contact_otp'=>$otp,'contact_expire_at'=>Carbon::now()->addMinutes(2)]); return response()->json(['status' => 200, 'message' => 'Email OTP verified Successfully']); } } @@ -797,11 +818,11 @@ class AuthController extends Controller $contactOtp = $request->contact_otp; $contactToAdd = $request->contact_number; - $userContactOtpData = UserOtp::where('contact_number', $contactToAdd)->where('contact_otp', $contactOtp)->first(); + $userContactOtpData = RegistrationOtp::where('contact_number', $contactToAdd)->where('contact_otp', $contactOtp)->first(); if (!$userContactOtpData) { return response()->json(['status' => 400, 'message' => 'Contact OTP Did Not Matched!'], 400); } - if (now() > $userContactOtpData->expire_at) { + if (now() > $userContactOtpData->contact_expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } @@ -842,15 +863,18 @@ class AuthController extends Controller $emailToAdd = $request->email2; - $userEmailOtpData = UserOtp::where('email', $emailToAdd)->where('otp', $emailOtp)->first(); // checking user email otp data + $userEmailOtpData = RegistrationOtp::where('email', $emailToAdd)->where('email_otp', $emailOtp)->first(); // checking user email otp data // dd($userEmailOtpData); if (!$userEmailOtpData) { return response()->json(['status' => 400, 'message' => 'Email OTP Did Not Matched!'], 400); } - if (now() > $userEmailOtpData->expire_at) { + if (now() > $userEmailOtpData->email_expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } if ($userEmailOtpData) { + $otp = rand(1000,9999); + $this->thirdPartyOTP($userEmailOtpData->contact_number, $otp); + RegistrationOtp::where('email', $emailToAdd)->update(['contact_otp'=>rand(1000,9999),'contact_expire_at'=>Carbon::now()->addMinutes(2)]); return response()->json(['status' => 200, 'message' => 'Email OTP verified Successfully']); } } @@ -858,12 +882,12 @@ class AuthController extends Controller $contactOtp = $request->contact_otp; $contactToAdd = $request->contact_number2; - $userContactOtpData = UserOtp::where('contact_number', $contactToAdd)->where('contact_otp', $contactOtp)->first(); + $userContactOtpData = RegistrationOtp::where('contact_number', $contactToAdd)->where('contact_otp', $contactOtp)->first(); if (!$userContactOtpData) { return response()->json(['status' => 400, 'message' => 'Contact OTP Did Not Matched!'], 400); } - if (now() > $userContactOtpData->expire_at) { + if (now() > $userContactOtpData->contact_expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } @@ -888,6 +912,39 @@ class AuthController extends Controller } } + public function resendOtp(Request $request) + { + try{ + // Type 1 for email, 2 for mobile + $type = $request->type; + $credential = $request->credential; + $otp = rand(1000,9999); + if($type == 1) + { + // resend otp for email + $mailData = [ + 'title' => 'Mail from ItSolutionStuff.com', + 'body' => 'This is for testing email using smtp.' + ]; + Mail::to($credential)->send(new OtpMail($mailData, $otp)); + RegistrationOtp::where('email',$credential)->update(['email_otp'=>$otp,'email_expire_at'=>Carbon::now()->addMinutes(2)]); + } + else if($type == 2){ + // resend otp for mobile + $this->thirdPartyOTP($credential, $otp); + RegistrationOtp::where('contact_number',$credential)->update(['contact_otp'=>$otp,'contact_expire_at'=>Carbon::now()->addMinutes(2)]); + } + return response()->json([ + 'status' => 200, + 'message' => 'OTP resend successfull', + ]); + + } catch (\Exception $e) + { + return response()->json(['status' => 500,'exception' => $e, 500]); + } + } + public function getUser(Request $request) { try { diff --git a/public/assets/js/FrontendJs/script.js b/public/assets/js/FrontendJs/script.js index ecee1d7..0d1decb 100644 --- a/public/assets/js/FrontendJs/script.js +++ b/public/assets/js/FrontendJs/script.js @@ -37,7 +37,7 @@ window.$('#currently').DataTable({ $("#recipes-popbtn-four").on("click", function () { var investNowUrl = "{{route('investNow')}}"; $.ajax({ - url : '/jericho_28_march/invest-now', + url : '/invest-now', // url : "{{route('investNow')}}", // url : investNowUrl, type: 'get',