diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index ba5b61e..88b9dee 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -524,6 +524,7 @@ class AuthController extends Controller // dd($request->all()); if (!$request->has('g-recaptcha-response')) { + // $userCreated = User::create([ // 'name' => $request->name, // 'email' => $request->email, @@ -531,6 +532,7 @@ class AuthController extends Controller // 'password' => bcrypt($request->password), // 'user_type' => 'Investor', // ]); + $otp = $this->otpGenerate($request->email); $mobile_otp = $this->otpGenerate($request->contact_number); $mailData = [ @@ -687,41 +689,52 @@ class AuthController extends Controller public function verifyContactAndEmailForInvestorApi(Request $request) { try { - $emailOtp = $request->email_otp; - $emailToAdd = $request->email; + $isOtpVerificationFor = $request->isOtpVerificationFor; + // 1= email ,2=contact - $userEmailOtpData = UserOtp::where('email', $emailToAdd)->where('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) { - return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); + if ($isOtpVerificationFor == 1) { + $emailOtp = $request->email_otp; + $emailToAdd = $request->email; + + $userEmailOtpData = UserOtp::where('email', $emailToAdd)->where('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) { + return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); + } + if ($userEmailOtpData) { + return response()->json(['status' => 200, 'message' => 'Email OTP verified Successfully']); + } } - $contactOtp = $request->contact_otp; - $contactToAdd = $request->contact_number; + if ($isOtpVerificationFor == 2) { + $contactOtp = $request->contact_otp; + $contactToAdd = $request->contact_number; - $userContactOtpData = UserOtp::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) { - return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); - } + $userContactOtpData = UserOtp::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) { + return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); + } - $userCreated = User::create([ - 'name' => $request->name, - 'email' => $request->email, - 'contact_number' => $request->contact_number, - 'password' => bcrypt($request->password), - 'user_type' => 'Investor', - ]); - if (!$userCreated) { - return response()->json(['status' => 400, 'message' => 'Error creating user!'])->setStatusCode(400); - } else { - $user = User::where('email', $request->email)->first(); - $userToken = $user->createToken('apiToken')->plainTextToken; - return response()->json(['status' => 200, 'message' => 'User Created', 'token' => $userToken, 'data' => $user]); + $userCreated = User::create([ + 'name' => $request->name, + 'email' => $request->email, + 'contact_number' => $request->contact_number, + 'password' => bcrypt($request->password), + 'user_type' => 'Investor', + ]); + + if (!$userCreated) { + return response()->json(['status' => 400, 'message' => 'Error creating user!'])->setStatusCode(400); + } else { + $user = User::where('email', $request->email)->first(); + $userToken = $user->createToken('apiToken')->plainTextToken; + return response()->json(['status' => 200, 'message' => 'User Created', 'token' => $userToken, 'data' => $user]); + } } @@ -730,7 +743,7 @@ class AuthController extends Controller } } - //mobile app email and contact no otp verification for both + //mobile app email and contact no otp verification for both //created on 11-04-2024 //by hritik //use - It will verify the OTPs of Asset Manager Registration @@ -738,8 +751,9 @@ class AuthController extends Controller public function verifyContactAndEmailForAssetManagerApi(Request $request) { try { + $isOtpVerificationFor = $request->isOtpVerificationFor; $validated = $request->validated(); - + if ($isOtpVerificationFor == 1) { $emailOtp = $request->email_otp; $emailToAdd = $request->email2; @@ -750,7 +764,11 @@ class AuthController extends Controller if (now() > $userEmailOtpData->expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } - + if ($userEmailOtpData) { + return response()->json(['status' => 200, 'message' => 'Email OTP verified Successfully']); + } + } + if ($isOtpVerificationFor == 2) { $contactOtp = $request->contact_otp; $contactToAdd = $request->contact_number2; @@ -778,12 +796,13 @@ class AuthController extends Controller $userToken = $user->createToken('apiToken')->plainTextToken; return response()->json(['status' => 200, 'message' => 'User Created', 'token' => $userToken, 'data' => $user]); } + } } catch (\Exception $e) { return response()->json(['status' => 400, 'message' => 'Error While Registation Details!'], 400); } } - + public function getUser(Request $request) { try {