From adfa6bd2d2b2c9a671ce017eaae659487f97d671 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sun, 28 Apr 2024 10:45:06 +0200 Subject: [PATCH] Add new files --- .../Auth/VerifyEmailController.php | 27 +++++++ app/Livewire/Actions/Logout.php | 20 ++++++ app/Livewire/Forms/LoginForm.php | 72 +++++++++++++++++++ app/Providers/VoltServiceProvider.php | 28 ++++++++ app/View/Components/AppLayout.php | 17 +++++ app/View/Components/GuestLayout.php | 17 +++++ 6 files changed, 181 insertions(+) create mode 100644 app/Http/Controllers/Auth/VerifyEmailController.php create mode 100644 app/Livewire/Actions/Logout.php create mode 100644 app/Livewire/Forms/LoginForm.php create mode 100644 app/Providers/VoltServiceProvider.php create mode 100644 app/View/Components/AppLayout.php create mode 100644 app/View/Components/GuestLayout.php diff --git a/app/Http/Controllers/Auth/VerifyEmailController.php b/app/Http/Controllers/Auth/VerifyEmailController.php new file mode 100644 index 000000000..784765e3a --- /dev/null +++ b/app/Http/Controllers/Auth/VerifyEmailController.php @@ -0,0 +1,27 @@ +user()->hasVerifiedEmail()) { + return redirect()->intended(route('dashboard', absolute: false).'?verified=1'); + } + + if ($request->user()->markEmailAsVerified()) { + event(new Verified($request->user())); + } + + return redirect()->intended(route('dashboard', absolute: false).'?verified=1'); + } +} diff --git a/app/Livewire/Actions/Logout.php b/app/Livewire/Actions/Logout.php new file mode 100644 index 000000000..3ef481d1c --- /dev/null +++ b/app/Livewire/Actions/Logout.php @@ -0,0 +1,20 @@ +logout(); + + Session::invalidate(); + Session::regenerateToken(); + } +} diff --git a/app/Livewire/Forms/LoginForm.php b/app/Livewire/Forms/LoginForm.php new file mode 100644 index 000000000..3c20c3749 --- /dev/null +++ b/app/Livewire/Forms/LoginForm.php @@ -0,0 +1,72 @@ +ensureIsNotRateLimited(); + + if (! Auth::attempt($this->only(['email', 'password']), $this->remember)) { + RateLimiter::hit($this->throttleKey()); + + throw ValidationException::withMessages([ + 'form.email' => trans('auth.failed'), + ]); + } + + RateLimiter::clear($this->throttleKey()); + } + + /** + * Ensure the authentication request is not rate limited. + */ + protected function ensureIsNotRateLimited(): void + { + if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { + return; + } + + event(new Lockout(request())); + + $seconds = RateLimiter::availableIn($this->throttleKey()); + + throw ValidationException::withMessages([ + 'form.email' => trans('auth.throttle', [ + 'seconds' => $seconds, + 'minutes' => ceil($seconds / 60), + ]), + ]); + } + + /** + * Get the authentication rate limiting throttle key. + */ + protected function throttleKey(): string + { + return Str::transliterate(Str::lower($this->email).'|'.request()->ip()); + } +} diff --git a/app/Providers/VoltServiceProvider.php b/app/Providers/VoltServiceProvider.php new file mode 100644 index 000000000..e61d98453 --- /dev/null +++ b/app/Providers/VoltServiceProvider.php @@ -0,0 +1,28 @@ +