authService = $authService; } public function registernumber(Request $request) { $this->data = $this->authService->registernumber($request); return $this->data; } public function register(Request $request) { try { $this->data = $this->authService->userRegistration($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function user_pin(Request $request) { try { $this->data = $this->authService->user_pin($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function postFingerPrintStatus(Request $request) { try { $this->data = $this->authService->postFingerPrintStatus($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function getFingerPrintStatus(Request $request) { try { $this->data = $this->authService->getFingerPrintStatus($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 201); } } public function resetPassword(Request $request) { try { $this->data = $this->authService->resetPassword($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 201); } } public function mobileExists(Request $request) { try { $this->data = $this->authService->mobileExists($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 201); } } // get user details public function user() { try { $this->data = $this->authService->user(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } // logout user public function logout(Request $request) { try { $this->data = $this->authService->logout($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function sendsms(Request $request) { try { $this->data = $this->authService->sendsms($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function isverified() { try { $this->data = $this->authService->isverified(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function isotpverified() { try { $this->data = $this->authService->isotpverified(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function isecurityquestion() { try { $this->data = $this->authService->isecurityquestion(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function verifyotp(Request $request) { try { $this->data = $this->authService->verifyotp($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function verifyotpWithoutToken(Request $request) { try { $this->data = $this->authService->verifyotpWithoutToken($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function securityQuestions() { try { $this->data = $this->authService->getSecurityQuestions(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function security_answers(Request $request) { try { $this->data = $this->authService->security_answers($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function check_pin_exist(Request $request) { try { $this->data = $this->authService->check_pin_exist($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function pin_match(Request $request) { try { $this->data = $this->authService->pin_match($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function UserForgotPasswordPin(Request $request) { try { $this->data = $this->authService->userforgotpasswordpin($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function resetPin(Request $request) { try { $this->data = $this->authService->resetPin($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function login(Request $request) { try { $this->data = $this->authService->login($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function createorder(Request $request) { try { $this->data = $this->authService->createorder($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function storeKycDetails(Request $request) { try { $this->data = $this->authService->storeKycDetails($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function storeBasicKycUserDetails(Request $request) { try { $this->data = $this->authService->storeBasicKycUserDetails($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function fetchKYCstatus(Request $request) { try { $this->data = $this->authService->fetchKYCstatus($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function storeFamilyDetails(Request $request) { try { $this->data = $this->authService->storeFamilyDetails($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function getFamilyDetails(Request $request) { try { $this->data = $this->authService->getFamilyDetails($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function storePersonalProfileDetails(Request $request) { try { $this->data = $this->authService->storePersonalProfileDetails($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function storeBankDetails(Request $request) { try { $this->data = $this->authService->storeBankDetails($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function storeGoals(Request $request) { try { $this->data = $this->authService->storeGoals($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function getBasicKycUserDetails() { try { $this->data = $this->authService->getBasicKycUserDetails(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function password_reset(Request $request) { try { $this->data = $this->authService->password_reset($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function getPersonalProfileDetails() { try { $this->data = $this->authService->getPersonalProfileDetails(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function getBankDetails() { try { $this->data = $this->authService->getBankDetails(); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function payment_verification(Request $request) { try { $this->data = $this->authService->payment_verification($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function createPlans(Request $request) { try { $this->data = $this->authService->createPlans($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function storeSubscriptionPlan(Request $request) { try { $this->data = $this->authService->storeSubscriptionPlan($request); return $this->data; } catch (\Exception $e) { return response()->json(['message' => $e->getMessage()], 500); } } public function resendOtpForMobile() { // dd(Session::get('user-registration')); if(!Session::has('user-registration')) { return response()->json(['status' => 401, 'message' => 'Something error!, Please fill the form again']); } else{ $mailData = [ 'title' => 'Mail from ItSolutionStuff.com', 'body' => 'This is for testing email using smtp.' ]; $otp = rand(1000,9999); // Mail::to(Session::get('user-registration')['email'])->send(new OtpMail($mailData, $otp)); $this->thirdPartyOTP(Session::get('user-registration')['contact_number'], $otp); $oldSession = Session::get('user-registration'); $oldSession['mobile_otp'] = $otp; Session::put('user-registration',$oldSession); RegistrationOtp::where('contact_number',Session::get('user-registration')['contact_number'])->update(['contact_otp'=>$otp,'contact_expire_at'=>Carbon::now()->addMinutes('2')]); return response()->json(['status' => 200, 'message' => 'OTP has been resend to your mobile number']); } } public function resendOtpForEmail() { if(!Session::has('user-registration')) { return response()->json(['status' => 401, 'message' => 'Something error!, Please fill the form again']); } else{ $mailData = [ 'title' => 'Mail from ItSolutionStuff.com', 'body' => 'This is for testing email using smtp.' ]; $otp = rand(1000,9999); Mail::to(Session::get('user-registration')['email'])->send(new OtpMail($mailData, $otp)); $oldSession = Session::get('user-registration'); $oldSession['otp'] = $otp; Session::put('user-registration',$oldSession); RegistrationOtp::where('email',Session::get('user-registration')['email'])->update(['email_otp'=>$otp,'email_expire_at'=>Carbon::now()->addMinutes('2')]); return response()->json(['status' => 200, 'message' => 'OTP has been resend to your email']); } } public function enteredEmailOTP(Request $request) { // dd((int)$request->otp, Session::get('user-registration')['otp']); $validator = Validator::make($request->post(), [ 'otp' => 'required|min:4|max:4', // 'contact_number' => 'required|exists:users,contact_number|min:10|max:10' ], [ 'required' => 'The :attribute field is required', // 'exists' => 'Contact Number has not been registered.', 'min' => 'The :attribute field must be 4 digits', 'max' => 'The :attribute field must be 4 digits', ]); $validationMessage = $this->validationError($validator); // dd($validationMessage); if ($validationMessage) { return response()->json(['status' => 401, 'message' => $validationMessage]); } if (strlen($request->otp) < 4) { return response()->json(['status' => 401, 'message' => 'Please enter 4 digit OTP']); } $otp = (int) $request->otp; if (Session::has('user-registration')) { // $user = Session::get('user-registration'); $registrationOtpData = RegistrationOtp::where('email', Session::get('user-registration')['email'])->first(); if (now() > $registrationOtpData->email_expire_at) { //email otp has expired return response()->json(['status' => 401, 'message' => 'Your Email OTP has been Expired']); } if ($registrationOtpData->email_otp == $otp) { // if (Session::get('user-registration')['otp'] == $otp) { $mobile_otp = $this->otpGenerate(Session::get('user-registration')['contact_number']); $this->thirdPartyOTP(Session::get('user-registration')['contact_number'], $mobile_otp); $userRegistration = Session::get('user-registration'); // Add the new value to the session data $userRegistration['mobile_otp'] = $mobile_otp; // Put the updated session data back into the session Session::put('user-registration', $userRegistration); //here we have to update the entry of Registration_otps RegistrationOtp::where('email',Session::get('user-registration')['email'])->update([ 'contact_number'=>(int)Session::get('user-registration')['contact_number'], 'contact_otp'=>$mobile_otp, 'contact_expire_at'=>Carbon::now()->addMinutes('2'), ]); // $userCreated = Session::put('user-registration'['mobile_otp'], $mobile_otp); //here i have to send mobile OTP in this session //updated by hritik on 17-04-2024 return response()->json(['status' => 200, 'message' => 'OTP verified']); } return response()->json(['status' => 401, 'message' => 'Invalid OTP!']); } return response()->json(['status' => 401, 'message' => 'OTP Expired!']); } public function signUp(Request $request) { $validator = Validator::make($request->all(), [ 'name' => [ 'required', 'regex:/^[a-zA-Z\s]+$/', ], 'email' => [ 'required', 'unique:users', 'regex:/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/', ], 'password' => [ 'required', 'min:8', 'regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%@]).*$/', 'confirmed', ], 'contact_number' => [ 'required', 'unique:users', 'min:10', 'max:12', 'regex:/^(\+\d{1,3}[- ]?)?\d{10,12}$/', ], 'g-recaptcha-response' => 'sometimes|required' ], [ 'contact_number.min' => 'Contact Number should be minimum 10 numbers', 'contact_number.max' => 'Contact Number should be maximum 12 numbers', 'contact_number.regex' => "Mobile number should be number not alphabets", 'password.regex' => 'Password does not follow regex', 'password.min' => 'Password should be minimum 8 characters', 'password.confirmed' => 'Password Confirmation Does Not Match Password', 'unique' => 'The :attribute field should be unique.', 'required' => 'The :attribute field is required.', 'name.regex' => 'The :attribute field contain only alphabets', ]); $validationMessage = $this->validationError($validator); if ($validationMessage) { return response()->json(['status' => 400, 'message' => $validationMessage], 400); } // dd($request->all()); if (!$request->has('g-recaptcha-response')) { // $userCreated = User::create([ // 'name' => $request->name, // 'email' => $request->email, // 'contact_number' => $request->contact_number, // 'password' => bcrypt($request->password), // 'user_type' => 'Investor', // ]); $otp = $this->otpGenerate($request->email); // $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); //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 = 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.']); // 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]); // } } else { Session::forget('user-registration'); $otp = $this->otpGenerate($request->email); // $mobile_otp = $this->otpGenerate($request->contact_number); $userRegistration = [ 'name' => $request->name, 'user_type' => 'Investor', 'authorized_representative_name' => $request->authorized_representative_name ?? null, 'email' => $request->email, 'password' => bcrypt($request->password), 'contact_number' => $request->contact_number, 'otp' => $otp, // 'mobile_otp' => $mobile_otp, ]; $userCreated = Session::put('user-registration', $userRegistration); $mailData = [ 'title' => 'Mail from ItSolutionStuff.com', 'body' => 'This is for testing email using smtp.' ]; RegistrationOtp::updateOrCreate(['email' => $request->email],['email' => $request->email, 'email_otp' => $otp, 'email_expire_at' => Carbon::now()->addMinutes('2')]); Mail::to($request->email)->send(new OtpMail($mailData, $otp)); // $this->thirdPartyOTP($request->contact_number, $mobile_otp); } // $name = $request->name; // $email = $request->email; // $password = $request->password; // $number = $request->contact_number; // $userCreated = User::create([ // 'name' => $name, // 'email' => $email, // 'contact_number' => $number, // 'password' => bcrypt($password), // ]); // if (!$userCreated) { // return response()->json(['status' => 400, 'message' => 'Error creating user!'], 400); // } // $token = $userCreated->createToken('apiToken')->plainTextToken; return response()->json(['status' => 200, 'message' => 'User Created']); } public function signUp2(StoreAssetManagerRegistrationRequest $request) { // dd($request->all()); $validated = $request->validated(); if (!$request->has('g-recaptcha-response')) { // $userCreated = User::create([ // 'name' => $validated['name2'], // 'user_type' => 'Asset Manager', // 'authorized_representative_name' => $validated['authorized_representative_name'], // 'email' => $validated['email2'], // 'contact_number' => $validated['contact_number2'], // 'password' => bcrypt($validated['password2']), // ]); // if (!$userCreated) { // return response()->json(['status' => 400, 'message' => 'Error creating user!'])->setStatusCode(400); // } else { // $user = User::where('email', $request->email2)->first(); // $userToken = $user->createToken('apiToken')->plainTextToken; // return response()->json(['status' => 200, 'message' => 'User Created', 'token' => $userToken, 'data' => $user]); // } $otp = $this->otpGenerate($request->email2); // $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 // ]); $insertOtp = RegistrationOtp::insertGetId([ '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'), ]); // dd($insertOtp); return response()->json(['status' => 200, 'message' => 'OTP has been sent to your Email & Contact no.']); } else { Session::forget('user-registration'); $otp = $this->otpGenerate($request->email2); // $mobile_otp = $this->otpGenerate($validated['contact_number2']); $userRegistration = [ 'name' => $validated['name2'], 'user_type' => 'Asset Manager', 'authorized_representative_name' => $validated['authorized_representative_name'], 'email' => $validated['email2'], 'contact_number' => $validated['contact_number2'], 'password' => bcrypt($validated['password2']), 'otp' => $otp, // 'mobile_otp' => $mobile_otp, ]; $userCreated = Session::put('user-registration', $userRegistration); $mailData = [ 'title' => 'Mail from ItSolutionStuff.com', 'body' => 'This is for testing email using smtp.' ]; Mail::to($validated['email2'])->send(new OtpMail($mailData, $otp)); $insertOtp = RegistrationOtp::insertGetId([ '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'), ]); // $this->thirdPartyOTP($validated['contact_number2'], $mobile_otp); // Mail::to('yadavritikesh29@gmail.com')->send(new OtpMail($mailData, $otp)); return response()->json(['status' => 200, 'message' => 'OTP has been sent to your email']); } // $name = $request->name; // $email = $request->email; // $password = $request->password; // $number = $request->contact_number; // $userCreated = User::create([ // 'name' => $name, // 'email' => $email, // 'contact_number' => $number, // 'password' => bcrypt($password), // ]); // if (!$userCreated) { // return response()->json(['status' => 400, 'message' => 'Error creating user!'], 400); // } // $token = $userCreated->createToken('apiToken')->plainTextToken; // return response()->json(['status' => 200, 'message' => 'User Created']); return response()->json(['status' => 200, 'message' => 'OTP has been sent to your email']); } //mobile app email and contact no otp verification for both //created on 11-04-2024 //by hritik //use - It will verify the OTPs of investor Registration public function verifyContactAndEmailForInvestorApi(Request $request) { try { $isOtpVerificationFor = $request->isOtpVerificationFor; // 1= email ,2=contact if ($isOtpVerificationFor == 1) { $emailOtp = $request->email_otp; $emailToAdd = $request->email; $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->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']); } } if ($isOtpVerificationFor == 2) { $contactOtp = $request->contact_otp; $contactToAdd = $request->contact_number; $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->contact_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 { //sending notifications $name = $request->name; $notify['message'] = "$name has registered to Jericho Alternatives Website and App!"; $type = "New Users"; $users = User::admins()->get(); foreach ($users as $data) { $data->notify(new UserAdmin($notify, $type)); } $user = User::where('email', $request->email)->first(); $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); } } //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 public function verifyContactAndEmailForAssetManagerApi(Request $request) { try { $isOtpVerificationFor = $request->isOtpVerificationFor; // $validated = $request->validated(); if ($isOtpVerificationFor == 1) { $emailOtp = $request->email_otp; $emailToAdd = $request->email2; $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->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']); } } if ($isOtpVerificationFor == 2) { $contactOtp = $request->contact_otp; $contactToAdd = $request->contact_number2; $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->contact_expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } $userCreated = User::create([ 'name' => $request->name2, 'user_type' => 'Asset Manager', 'authorized_representative_name' => $request->authorized_representative_name, 'email' => $request->email2, 'contact_number' => $request->contact_number2, 'password' => bcrypt($request->password2), ]); if (!$userCreated) { return response()->json(['status' => 400, 'message' => 'Error creating user!'])->setStatusCode(400); } else { //sending notifications $name = $request->name2; $notify['message'] = "$name has registered to Jericho Alternatives Website and App!"; $type = "New Users"; $users = User::admins()->get(); foreach ($users as $data) { $data->notify(new UserAdmin($notify, $type)); } $user = User::where('email', $request->email2)->first(); $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!' . $e->getMessage()], 400); } } 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 { // $hashedTooken = $request->bearerToken(); // $token = PersonalAccessToken::findToken($hashedTooken); // if (!$hashedTooken) { // return response()->json(['status' => 200, 'message' => 'No User Found!'], 200); // } // $user = User::find(auth()->user()->id); $user = $request->user(); // if (!$user) { // return response()->json(['status' => 400, 'message' => 'Error finding user!']); // } return response()->json(['status' => 200, 'user' => $user], 200); } catch (\Exception $ex) { return response()->json(['status' => 500, 'exception' => $ex, 500]); } // return response()->json(['status'=>200,'user'=>$token->tokenab le]); } public function userLogin(Request $request) { $validator = Validator::make($request->all(), [ 'user' => 'required', 'password' => [ 'required', // 'min:8', // 'regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%@]).*$/' ], ]); // if ($validator->fails()) { // $errors = $validator->errors(); // return response()->json([ // 'error' => $errors // ], 400); // } $validationMessage = $this->validationError($validator); if ($validationMessage) { return response()->json(['status' => 400, 'message' => $validationMessage], 400); } $credentials = $request->user; $password = $request->password; $user = User::where('email', $credentials)->orWhere('contact_number', $credentials)->first(); if (!$user) { return response()->json(['status' => 500, 'message' => 'No User Found'], 500); } if (!\Hash::check($password, $user->password)) { return response()->json(['status' => 400, 'message' => 'Invalid Credentials!'], 400); }; // $hashedTooken = $request->bearerToken(); $userToken = $user->createToken('apiToken')->plainTextToken; $token = PersonalAccessToken::findToken($userToken); if (!$token) { return response()->json(['status' => 500, 'message' => 'Inaccurate Token'], 500); } return response()->json(['status' => 200, 'message' => 'User Found', 'token' => $userToken, 'data' => $token->tokenable], 200); } public function sendOTP(Request $request) { $validator = Validator::make($request->post(), [ 'contact_number' => 'required|exists:users,contact_number|min:10|max:10', ], [ 'required' => 'The :attribute field is required', 'exists' => 'Contact Number has not been registered.', 'min' => 'The :attribute field must be 10 digits', 'max' => 'The :attribute field must be 10 digits', ]); $validationMessage = $this->validationError($validator); if ($validationMessage) { return response()->json(['status' => 400, 'message' => $validationMessage], 400); } $contactNumber = $request->contact_number; $otp = rand(1000, 9999); session()->put('contact_number', $contactNumber); $sendOTP = $this->thirdPartyOTP($contactNumber, $otp); // $insertOtp = UserOtp::create([ // 'contact_number' => $contactNumber, // 'expire_at' => Carbon::now()->addMinutes('5'), // 'otp' => $otp // ]); $insertOtp = User::where('contact_number', $contactNumber)->update([ 'expire_at' => Carbon::now()->addMinutes('2'), 'otp' => $otp ]); if (!$insertOtp) { return response()->json(['status' => 500, 'otp' => $otp, 'message' => 'Error inserting OTP'], 500); } return response()->json(['status' => 200, 'otp' => $otp, 'message' => 'OTP has been sent successfully!']); } public function getConvertedIntoDate(Request $request) { $date = $request->date; return getConvertedDate($date); } public function enteredOtp(Request $request) { // dd($request->all(),Session::get('user-registration')); $validator = Validator::make($request->post(), [ 'otp' => 'required|min:4|max:4', // 'contact_number' => 'required|exists:users,contact_number|min:10|max:10' ], [ 'required' => 'The OTP field is required', 'exists' => 'Contact Number has not been registered.', 'min' => 'The OTP field must be 4 digits', 'max' => 'The OTP field must be 4 digits', ]); $validationMessage = $this->validationError($validator); if ($validationMessage) { return response()->json(['status' => 401, 'message' => $validationMessage]); } if (strlen($request->otp) < 4) { return response()->json(['status' => 401, 'message' => 'Please enter 4 digit OTP']); } $otp = (int) $request->otp; if (Session::has('user-registration')) { $userDetails = Session::get('user-registration'); $registrationOtp = RegistrationOtp::where('contact_number',$userDetails['contact_number'])->first(); // dd($userDetails); if(now() > $registrationOtp->contact_expire_at) { return response()->json(['status' => 401, 'message' => 'Mobile OTP has been expired!']); // return } if ($userDetails['mobile_otp'] !== $otp) { return response()->json(['status' => 400, 'message' => 'OTP Did Not Matched!']); } $userCreated = User::create([ 'name' => $userDetails['name'], 'authorized_representative_name' => $userDetails['authorized_representative_name'] ?? null, 'user_type' => $userDetails['user_type'], 'email' => $userDetails['email'], 'contact_number' => $userDetails['contact_number'], 'password' => $userDetails['password'], ]); Mail::to($userDetails['email'])->send(new RegisteredMail()); Auth::guard('users')->login($userCreated); //sending notifications $name = $userDetails['name']; $notify['message'] = "$name has registered to Jericho Alternatives Website and App!"; $type = "New Users"; $users = User::admins()->get(); foreach ($users as $data) { $data->notify(new UserAdmin($notify, $type)); } Session::forget('user-registration'); // Auth::guard('users')->login($userCreated); return response()->json(['status' => 200, 'message' => 'OTP has been matched and User has been created!'], 200); // return response()->json(['status' => 200, 'message' => 'OTP has been matched'], 200); } $checkOTP = User::where(['contact_number' => $request->contact_number, 'otp' => $request->otp])->first(); if ($checkOTP) { if (!$checkOTP) { return response()->json(['status' => 400, 'message' => 'OTP Did Not Matched!'], 400); } if (now() > $checkOTP->expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } $userToken = $checkOTP->createToken('apiToken')->plainTextToken; $token = PersonalAccessToken::findToken($userToken); return response()->json(['status' => 200, 'token' => $userToken, 'data' => $token->tokenable, 'message' => 'OTP has been matched!'], 200); } else { return response()->json(['status' => 400, 'message' => 'Record Does Not Exist!'], 400); } $contactNumber = session('contact_number'); if (!$contactNumber) { return response()->json(['status' => 201, 'message' => 'Contact number not found!'], 201); } $otp = $request->otp; $checkNumberWithOtp = UserOtp::where(['contact_number' => $contactNumber, 'otp' => $otp])->first(); if (!$checkNumberWithOtp) { return response()->json(['status' => 400, 'message' => 'OTP Did Not Matched!'], 400); } if (now() > $checkNumberWithOtp->expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } $contactNumberSession = Session::get('contact_number'); $user = User::where('contact_number', $contactNumberSession)->first(); $userToken = $user->createToken('apiToken')->plainTextToken; $token = PersonalAccessToken::findToken($userToken); return response()->json(['status' => 200, 'token' => $userToken, 'data' => $token->tokenable, 'message' => 'OTP has been matched!'], 200); } public function loginByMobile(Request $request) { // validating data $validator = Validator::make($request->all(), [ 'contact_number' => 'required|exists:users,contact_number', ]); // validation fail handling if ($validator->fails()) { return response()->json(['error' => 'Mobile number is not registered', 'status' => 204]); } $user = User::where('contact_number', $request->contact_number)->first(); try { if ($user) { $user->otp = rand(1234, 9999); $user->expire_at = Carbon::now('Asia/colombo')->addMinutes(2); $user->update(); return response()->json(['message' => 'OTP has been sent to your mail and phone', 'user_id' => $user->id, 'otp' => $user->otp, 'status' => 200]); } } catch (\Exception $e) { return response()->json(['error' => 'Netwrok Error! Please try again after sometime.', 'status' => 500]); } } public function userLogout(Request $request) { try { $userLoggedOut = $request->user()->currentAccessToken()->delete(); return response()->json(['status' => 200, 'message' => 'User Logged Out!!'], 200); } catch (\Exception $ex) { return response()->json(['status' => 500, 'message' => $ex]); } } public function validationError($validator) { if ($validator->fails()) { $errors = $validator->errors(); $messages = ""; foreach ($errors->all() as $message) { $messages .= $message; } return $messages; } } public function otpGenerate($email) { $otp = rand(1000, 9999); return $otp; } public function forgotPasswordStepOne(Request $request) { $validator = Validator::make($request->all(), [ 'contact_number' => 'required|exists:users,contact_number', ], [ 'contact_number.exists' => 'Please Enter Registered Number', ]); $validationMessage = $this->validationError($validator); if ($validationMessage) { return response()->json(['status' => 400, 'message' => $validationMessage], 400); } $otp = rand(1000, 9999); $sendOTP = $this->thirdPartyOTP($request->contact_number, $otp); $insertOtp = User::where('contact_number', $request->contact_number)->update([ 'expire_at' => Carbon::now()->addMinutes('5'), 'otp' => $otp ]); if ($insertOtp) { return response()->json(['message' => 'OTP Sent Succesfully', 'otp' => $otp, 'status' => 200]); } return response()->json(['message' => 'Error Sending OTP', 'status' => 400]); } public function forgotPasswordStepTwo(Request $request) { $validator = Validator::make($request->all(), [ 'contact_number' => 'required|exists:users,contact_number', 'otp' => 'required', ]); $validationMessage = $this->validationError($validator); if ($validationMessage) { return response()->json(['status' => 400, 'message' => $validationMessage], 400); } $checkOTP = User::where(['contact_number' => $request->contact_number, 'otp' => $request->otp])->first(); if ($checkOTP) { if (!$checkOTP) { return response()->json(['status' => 400, 'message' => 'OTP Did Not Matched!'], 400); } if (now() > $checkOTP->expire_at) { return response()->json(['status' => 400, 'message' => 'OTP has been expired!'], 400); } return response()->json(['status' => 200, 'message' => 'OTP has been matched!'], 200); } return response()->json(['message' => 'OTP Not Matched', 'status' => 400], 400); } public function forgotPasswordStepThree(Request $request) { $validator = Validator::make($request->all(), [ 'contact_number' => 'required|exists:users,contact_number', 'password' => [ 'required', 'min:8', 'regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%@&]).*$/', 'confirmed', ], ], [ 'password.regex' => 'Password does not follow regex', 'password.min' => 'Password should be minimum 8 characters', 'password.confirmed' => 'Password Confirmation Does Not Match Password', ]); $validationMessage = $this->validationError($validator); if ($validationMessage) { return response()->json(['status' => 400, 'message' => $validationMessage], 400); } $user = User::where(['contact_number' => $request->contact_number])->first(); if (Hash::check($request->password, $user->password)) { return response()->json(['message' => 'New Password Cannot be Same as Old Password!', 'status' => 400], 400); } $changePassword = User::where(['contact_number' => $request->contact_number])->update([ 'password' => bcrypt($request->password) ]); if ($changePassword) { return response()->json(['message' => 'Password Changed Succesfully!', 'status' => 200]); } return response()->json(['message' => 'Error Changing Password', 'status' => 400]); } public function thirdPartyOTP($number, $otp) { $curl = curl_init(); curl_setopt_array( $curl, array( CURLOPT_URL => 'https://restapi.smscountry.com/v0.1/Accounts/4F7T5SbGyV7HBrEHxmX4/SMSes/', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ "Text": "Dear Investor, Your login OTP is ' . $otp . '. - Blue Feather Ventures Pvt Ltd.", "Number": "91' . $number . '", "SenderId": "BLUFVL", "DRNotifyUrl": "https://www.domainname.com/notifyurl", "DRNotifyHttpMethod": "POST", "Tool": "API" }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Authorization: Basic NEY3VDVTYkd5VjdIQnJFSHhtWDQ6emFXdFEyTlV3ZlZROHB6dGRvVlRZUFdibG01Y1AxRldsbWl2WlVrbg==' ), ) ); $response = curl_exec($curl); curl_close($curl); return $response; // return true; } }