Sms verification ok

This commit is contained in:
2023-12-02 13:36:50 +05:00
parent d6fd71e0dd
commit d9ea58608b
25 changed files with 692 additions and 169 deletions

View File

@@ -0,0 +1,121 @@
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Laravel\Nova\Nova;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers, ValidatesRequests;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('nova.guest:'.config('nova.guard'))->except('logout');
}
/**
* Show the application's login form.
*
* @return \Inertia\Response|\Symfony\Component\HttpFoundation\Response
*/
public function showLoginForm()
{
return view('vendor.nova.pages.login');
}
/**
* The user has been authenticated.
*
* @param mixed $user
* @return mixed
*/
protected function authenticated(Request $request, $user)
{
$redirect = redirect()->intended($this->redirectPath());
return $request->wantsJson()
? new JsonResponse([
'redirect' => $redirect->getTargetUrl(),
], 200)
: $redirect;
}
/**
* Log the user out of the application.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return redirect()->intended($this->redirectPath());
}
/**
* Get the post register / login redirect path.
*
* @return string
*/
public function redirectPath()
{
return Nova::url(Nova::$initialPath);
}
/**
* Get the guard to be used during authentication.
*
* @return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard(config('nova.guard'));
}
/**
* Get the login username to be used by the controller.
*/
public function username(): string
{
return 'username';
}
/**
* Validate the user login request.
*
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function validateLogin(Request $request)
{
$request->validate([
$this->username() => ['required', 'string', 'max:250', 'exists:users,username'],
'password' => ['required', 'string', 'max:250'],
]);
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
/**
* Show registration page
*/
public function showNovaRegisterpageForm(): View
{
return view('vendor.nova.pages.register');
}
/**
* Handle a registration request for the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
public function register(Request $request)
{
$this->middleware('guest');
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
Auth::guard()->login($user);
sendSMSVerification($user->phone);
return to_route('sms-verification');
}
/**
* Get a validator for an incoming registration request.
*
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
$data['phone'] = substr(str_replace(['+', '(', ')', '-', '_'], '', $data['phone']), 3);
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'phone' => ['required', 'integer', 'between:61000000,671999999', 'unique:users,phone'],
'username' => ['required', 'string', 'alpha_dash:ascii', 'max:255', 'unique:users,username'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @return \App\Models\User
*/
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'phone' => $data['phone'],
'username' => $data['username'],
'password' => Hash::make($data['password']),
'active' => true,
]);
return $user;
}
/**
* Sms verification
*/
public function smsVerification()
{
return view('vendor.nova.pages.sms-verification');
}
/**
* Verify sms code
*/
public function verifySmsCode()
{
}
}