From 7de2a637c4be4ad699063604f5763a6e0aa683f3 Mon Sep 17 00:00:00 2001 From: Exynox Date: Sat, 29 Jul 2023 11:43:34 +0300 Subject: [PATCH] Added blocking, started e-mail validation, fixed locale strings --- app/Http/Controllers/LoginController.php | 43 +++-- .../Middleware/RedirectIfAuthenticated.php | 2 +- app/Models/Account.php | 62 ++++++- app/Models/Enums/AccountStatusEnum.php | 22 +++ .../registration/progress.blade.php | 18 ++ resources/views/layouts/app.blade.php | 158 +++++------------- .../main/howto/createcharacter.blade.php | 2 +- resources/views/user/login.blade.php | 2 +- .../registration/activation-pending.blade.php | 45 +++++ .../{ => registration}/register.blade.php | 2 +- .../registration-failed.blade.php | 0 .../{ => registration}/resendack.blade.php | 0 routes/web.php | 20 ++- 13 files changed, 237 insertions(+), 139 deletions(-) create mode 100644 app/Models/Enums/AccountStatusEnum.php create mode 100644 resources/views/components/registration/progress.blade.php create mode 100644 resources/views/user/registration/activation-pending.blade.php rename resources/views/user/{ => registration}/register.blade.php (99%) rename resources/views/user/{ => registration}/registration-failed.blade.php (100%) rename resources/views/user/{ => registration}/resendack.blade.php (100%) diff --git a/app/Http/Controllers/LoginController.php b/app/Http/Controllers/LoginController.php index 398adf5..07594b5 100644 --- a/app/Http/Controllers/LoginController.php +++ b/app/Http/Controllers/LoginController.php @@ -16,8 +16,8 @@ class LoginController extends Controller public function login(Request $request): RedirectResponse { $validator = Validator::make($request->all(), [ - 'login' => ['required'], - 'password' => ['required'], + 'login' => 'required|string', + 'password' => 'required|string', ]); if ($validator->fails()) @@ -25,19 +25,36 @@ public function login(Request $request): RedirectResponse $credentials = $validator->validated(); - if (Auth::attempt($credentials)) { - $request->session()->regenerate(); - - $user = Auth::user(); - $user->ip = $request->ip(); - $user->saveOrFail(); - - return redirect()->intended('user/administration'); + // Validate the credentials + if (!Auth::once($credentials)) { + return redirect('user/login')->withErrors([ + 'login' => 'The provided credentials do not match our records.', + ])->onlyInput('login'); } - return redirect('user/login')->withErrors([ - 'login' => 'The provided credentials do not match our records.', - ])->onlyInput('login'); + // The user is now available + $user = Auth::user(); + + // Check if the user is banned + if ($user->status->isBlocked()) { + Auth::logout(); + + $request->session()->invalidate(); + + return redirect('user/login')->withErrors([ + 'login' => 'Your account is blocked.', + ])->onlyInput('login'); + } + + // Authenticate user + Auth::login($user); + $request->session()->regenerate(); + + // Save user's IP address + $user->ip = $request->ip(); + $user->saveOrFail(); + + return redirect()->intended('user/administration'); } diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index afc78c4..8b5a9ed 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -21,7 +21,7 @@ public function handle(Request $request, Closure $next, string ...$guards): Resp foreach ($guards as $guard) { if (Auth::guard($guard)->check()) { - return redirect(RouteServiceProvider::HOME); + return redirect('user/administration'); } } diff --git a/app/Models/Account.php b/app/Models/Account.php index c46b997..5a6ab7e 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -2,13 +2,15 @@ namespace App\Models; -// use Illuminate\Contracts\Auth\MustVerifyEmail; +use App\Models\Enums\AccountStatusEnum; +use Illuminate\Auth\Notifications\VerifyEmail; +use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User; use Illuminate\Notifications\Notifiable; use Laravel\Sanctum\HasApiTokens; -class Account extends User +class Account extends User implements MustVerifyEmail { use HasApiTokens, HasFactory, Notifiable; @@ -26,9 +28,20 @@ class Account extends User */ protected $table = 'account'; - const UPDATED_AT = null; + /** + * The name of the "created at" column. + * + * @var string|null + */ const CREATED_AT = 'create_time'; + /** + * The name of the "updated at" column. + * + * @var string|null + */ + const UPDATED_AT = null; + /** * The attributes that are mass assignable. * @@ -59,5 +72,48 @@ class Account extends User protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', + 'status' => AccountStatusEnum::class ]; + + /** + * Determine if the user has verified their email address. + * + * @return bool + */ + public function hasVerifiedEmail(): bool + { + return $this->status != AccountStatusEnum::NOT_AVAILABLE; + } + + /** + * Mark the given user's email as verified. + * + * @return bool + */ + public function markEmailAsVerified(): bool + { + return $this->forceFill([ + 'status' => AccountStatusEnum::OK, + ])->save(); + } + + /** + * Send the email verification notification. + * + * @return void + */ + public function sendEmailVerificationNotification(): void + { + $this->notify(new VerifyEmail); + } + + /** + * Get the email address that should be used for verification. + * + * @return string + */ + public function getEmailForVerification(): string + { + return $this->email; + } } diff --git a/app/Models/Enums/AccountStatusEnum.php b/app/Models/Enums/AccountStatusEnum.php new file mode 100644 index 0000000..d6fc4ba --- /dev/null +++ b/app/Models/Enums/AccountStatusEnum.php @@ -0,0 +1,22 @@ + true, + default => false, + }; + } +} diff --git a/resources/views/components/registration/progress.blade.php b/resources/views/components/registration/progress.blade.php new file mode 100644 index 0000000..09869f2 --- /dev/null +++ b/resources/views/components/registration/progress.blade.php @@ -0,0 +1,18 @@ +
+ @php($progressTexts = [ + 1 => 'Înregistrare', + 2 => 'Activează și descarcă', + 3 => 'Instalează și joacă-te', + ]) + + @for ($i = 1; $i <= 3; $i++) +
$step < $i, + 'active' => $step == $i, + 'passed' => $step > $i, + ])> +
{{ $i }}
+

{{ $progressTexts[$i] }}

+
+ @endfor +
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 9689d21..95ac4e1 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -175,37 +175,47 @@ function () {
 
@guest -
-
-
-

Logare

-
- @csrf +
+
+
+

Logare

+ + @csrf -
-
+
+ +
+
+
+

Descărcare

+ +
+
+
@else
@@ -216,27 +226,17 @@ function () {
-
 
-
-
-
-

Magazinul de item-uri

- + @if (Auth::user()->status == \App\Models\Enums\AccountStatusEnum::OK) +
+
+
+
+

Magazinul de item-uri

+ +
-
- @endguest - - @guest -
 
-
-
-
-

Descărcare

- -
-
-
+ @endif @endguest {{-- @@ -251,7 +251,7 @@ function () {
--}} -
 
+
@@ -261,74 +261,8 @@ function () {
-  
- -
-
-
-

Jucatori

-
-
-
    - "; - } else { - $i = 0; - echo "
  • "; - } - - echo '' . $rank . ' - ' . $row['name'] .'
  • '; - $rank++; - } - ?> -
- Tot Clasamentul -
-
-
-
-
-
-
-
-
-

Bresle

-
-
-
    - "; - } else { - $i = 0; - echo "
  • "; - } - - echo '' . $rank . ' - ' . $row['name'] . '
  • '; - - $rank++; - } - ?> -
- Tot Clasamentul -
-
-
-
-
-
*/ ?>
 
+
diff --git a/resources/views/main/howto/createcharacter.blade.php b/resources/views/main/howto/createcharacter.blade.php index 9e171c8..3bc1568 100644 --- a/resources/views/main/howto/createcharacter.blade.php +++ b/resources/views/main/howto/createcharacter.blade.php @@ -24,7 +24,7 @@

4/ 4

Exista 4 clase diferite in joc, fiecare cu caracteristici individuale.
- Poti sa te folosesti de sageti pentru a alege clasa. Cand caracterul tau este afisat in fata, poti folosi linkul din cutie (cu verde marcat) pentru a schimba aspectul caracterului prin alegerea intre 1 si 2. Intr-un final caracterul tau are nevoie de un nume. Dupa ce ai ales numele apasa pe " Creaza " pentru a da viata caracterului. Acum poti apasa pe Start pentru a intra in joc.

+ Poti sa te folosesti de sageti pentru a alege clasa. Cand caracterul tau este afisat in fata, poti folosi linkul din cutie (cu verde marcat) pentru a schimba aspectul caracterului prin alegerea intre 1 si 2. Intr-un final caracterul tau are nevoie de un nume. Dupa ce ai ales numele apasa pe " Creeaza " pentru a da viata caracterului. Acum poti apasa pe Start pentru a intra in joc.

diff --git a/resources/views/user/login.blade.php b/resources/views/user/login.blade.php index 95e9708..c6a052b 100644 --- a/resources/views/user/login.blade.php +++ b/resources/views/user/login.blade.php @@ -40,7 +40,7 @@

Încă nu ai cont?

Crearea unui jucător (cont) este rapidă, usoară și gratis.

- Crează un cont + Creează un cont
diff --git a/resources/views/user/registration/activation-pending.blade.php b/resources/views/user/registration/activation-pending.blade.php new file mode 100644 index 0000000..bebab84 --- /dev/null +++ b/resources/views/user/registration/activation-pending.blade.php @@ -0,0 +1,45 @@ +@extends('layouts.app') + +@section('content') + +
+
+
+
+

Contul tău

+ + + +
+
+
+
+

Activează-ți contul!

+
+
+

+ Pentru finalizarea înregistrării tale, trebuie să îți verificăm adresa + de e-mail. Accesează-ți căsuța de e-mail și urmează link-ul din mesaj pentru activare. +

+

+ + Nu ai primit un e-mail? Retrimite mailul de activare + +

+
+

Descarcă jocul

+
+ + Descarcă
jocul acum +
+
+
+
+
+
+
+
+
+
 
+
+@endsection diff --git a/resources/views/user/register.blade.php b/resources/views/user/registration/register.blade.php similarity index 99% rename from resources/views/user/register.blade.php rename to resources/views/user/registration/register.blade.php index 2461a5e..5518a85 100644 --- a/resources/views/user/register.blade.php +++ b/resources/views/user/registration/register.blade.php @@ -23,7 +23,7 @@
-

sau la autentificareCrează un cont

+

sau la autentificareCreează un cont

diff --git a/resources/views/user/registration-failed.blade.php b/resources/views/user/registration/registration-failed.blade.php similarity index 100% rename from resources/views/user/registration-failed.blade.php rename to resources/views/user/registration/registration-failed.blade.php diff --git a/resources/views/user/resendack.blade.php b/resources/views/user/registration/resendack.blade.php similarity index 100% rename from resources/views/user/resendack.blade.php rename to resources/views/user/registration/resendack.blade.php diff --git a/routes/web.php b/routes/web.php index 4b2b55f..bba57d8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -49,18 +49,24 @@ }); Route::prefix('user')->group(function() { - Route::get('/register', fn () => view('user/register')); - Route::get('/login', fn () => view('user/login'))->name('login'); - Route::post('/login', [LoginController::class, 'login']); - // will autocomplete the username - Route::get('/login/{username}', fn ($username) => view('user/login')); + # Registration + Route::get('/register', fn () => view('user/registration/register'))->middleware('guest'); + Route::get('/activate', fn () => view('user/registration/activation-pending'))->name('verification.notice'); + Route::get('/resendack', fn () => view('user/registration/resendack')); + + # Authentication + Route::middleware('guest')->group(function() { + Route::get('/login', fn () => view('user/login'))->name('login'); + Route::post('/login', [LoginController::class, 'login']); + // will autocomplete the username + Route::get('/login/{username}', fn ($username) => view('user/login')); + }); Route::get('/logout', [LoginController::class, 'logout']); Route::get('/passwordlostrequest', fn () => view('user/passwordlostrequest')); Route::get('/passwordlost/{username}/{hash}', fn ($username, $hash) => view('user/passwordlost-expired')); - Route::get('/resendack', fn () => view('user/resendack')); - Route::middleware('auth')->group(function() { + Route::middleware(['auth', 'verified'])->group(function() { Route::get('/administration', fn () => view('user/administration')); Route::get('/characters', fn () => view('user/characters'));