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 @@ +
{{ $progressTexts[$i] }}
++ 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 + +
+