Register page should work
This commit is contained in:
@@ -3,13 +3,16 @@
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\System\Verification;
|
||||
use App\Models\User;
|
||||
use App\Rules\PhoneCodeVerification;
|
||||
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 Laravel\Nova\Nova;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class RegisterController extends Controller
|
||||
@@ -100,8 +103,18 @@ class RegisterController extends Controller
|
||||
/**
|
||||
* Verify sms code
|
||||
*/
|
||||
public function verifySmsCode()
|
||||
public function verifySmsCode(Request $request)
|
||||
{
|
||||
$this->middleware('auth');
|
||||
|
||||
$request->validate([
|
||||
'code' => ['required', 'integer', new PhoneCodeVerification()]
|
||||
]);
|
||||
|
||||
auth()->user()->update([
|
||||
'phone_verified_at' => now()
|
||||
]);
|
||||
|
||||
return redirect(Nova::path());
|
||||
}
|
||||
}
|
||||
|
||||
28
app/Http/Middleware/CheckPhoneVerification.php
Normal file
28
app/Http/Middleware/CheckPhoneVerification.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckPhoneVerification
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (! auth()->check()) {
|
||||
return redirect('/login');
|
||||
}
|
||||
|
||||
if (! auth()->user()->isSystemUser() && is_null(auth()->user()->phone_verified_at)) {
|
||||
return to_route('sms-verification');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ class User extends Authenticatable
|
||||
'email',
|
||||
'phone',
|
||||
'email_verified_at',
|
||||
'phone_verified_at',
|
||||
'password',
|
||||
'locale',
|
||||
'active',
|
||||
@@ -98,6 +99,14 @@ class User extends Authenticatable
|
||||
return $this->hasRole('operator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is System User
|
||||
*/
|
||||
public function isSystemUser(): bool
|
||||
{
|
||||
return $this->isAdmin() || $this->isOperator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user owns loan order.
|
||||
*/
|
||||
|
||||
@@ -45,6 +45,6 @@ class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
Gate::define('isMe', fn ($user) => $user->isMe());
|
||||
Gate::define('isAdmin', fn ($user) => $user->isAdmin());
|
||||
Gate::define('systemUser', fn ($user) => $user->isAdmin() || $user->isOperator());
|
||||
Gate::define('systemUser', fn ($user) => $user->isSystemUser());
|
||||
}
|
||||
}
|
||||
|
||||
25
app/Rules/PhoneCodeVerification.php
Normal file
25
app/Rules/PhoneCodeVerification.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class PhoneCodeVerification implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$verification = Verification::where('username', auth()->user()->phone)
|
||||
->where('code', $request->verification_code)
|
||||
->first();
|
||||
|
||||
if (! $verification) {
|
||||
$fail(__('Write a correct data please'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Middleware\CheckPhoneVerification;
|
||||
use Laravel\Nova\Actions\ActionResource;
|
||||
use Laravel\Nova\Http\Middleware\Authenticate;
|
||||
use Laravel\Nova\Http\Middleware\Authorize;
|
||||
@@ -103,6 +104,7 @@ return [
|
||||
HandleInertiaRequests::class,
|
||||
DispatchServingNovaEvent::class,
|
||||
BootTools::class,
|
||||
CheckPhoneVerification::class,
|
||||
],
|
||||
|
||||
'api_middleware' => [
|
||||
|
||||
@@ -218,5 +218,6 @@
|
||||
"Username": "Ulanyjy ady",
|
||||
"Go to login page": "Login sahypa geç",
|
||||
"Submit": "Tassyklamak",
|
||||
"Verification code": "Tassyklaýyş belgi"
|
||||
"Verification code": "Tassyklaýyş belgi",
|
||||
"Please, verify your phone": "Telefon beligiňizi tassyklamagyňyzy haýyş edýäris."
|
||||
}
|
||||
|
||||
2
lang/vendor/nova/tk.json
vendored
2
lang/vendor/nova/tk.json
vendored
@@ -192,7 +192,7 @@
|
||||
"Haiti": "Gaiti",
|
||||
"Heard Island & Mcdonald Islands": "Heard adasy we Makdonalds adalary",
|
||||
"Hide Content": "Mazmuny gizläň",
|
||||
"Hold Up!": "Saklamak!",
|
||||
"Hold Up!": "Näsazlyk!",
|
||||
"Holy See (Vatican City State)": "Vatican City",
|
||||
"Honduras": "Gonduras",
|
||||
"Hong Kong": "Gonkong",
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<span class="text-4xl">{{ __('Online panel') }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<form class="bg-white dark:bg-gray-800 shadow rounded-lg p-8 max-w-[25rem] mx-auto" method="POST" action="{{ route('login') }}">
|
||||
<form class="bg-white dark:bg-gray-800 shadow rounded-lg p-8 max-w-[25rem] mx-auto" method="POST" action="{{ route('sms-verification') }}">
|
||||
@csrf
|
||||
<h2 class="text-2xl text-center font-normal mb-6">{{ __('Verify Phone Number') }}</h2>
|
||||
<svg class="block mx-auto mb-6" xmlns="http://www.w3.org/2000/svg" width="100" height="2" viewBox="0 0 100 2">
|
||||
|
||||
@@ -16,9 +16,11 @@ use Illuminate\Support\Facades\Route;
|
||||
*/
|
||||
|
||||
Route::get('/register', [RegisterController::class, 'showNovaRegisterpageForm'])->name('register');
|
||||
Route::get('sms-verification', [RegisterController::class, 'smsVerification'])->name('sms-verification');
|
||||
Route::post('/register', [RegisterController::class, 'register']);
|
||||
|
||||
Route::get('sms-verification', [RegisterController::class, 'smsVerification'])->name('sms-verification');
|
||||
Route::post('sms-verification', [RegisterController::class, 'verifySmsCode']);
|
||||
|
||||
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('login');
|
||||
Route::post('/login', [LoginController::class, 'login']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user