diff --git a/app/Http/Controllers/Auth/AuthenticatedSessionController.php b/app/Http/Controllers/Auth/AuthenticatedSessionController.php new file mode 100644 index 0000000..339fae7 --- /dev/null +++ b/app/Http/Controllers/Auth/AuthenticatedSessionController.php @@ -0,0 +1,53 @@ +authenticate(); + + $request->session()->regenerate(); + + return redirect()->intended(RouteServiceProvider::HOME); + } + + /** + * Destroy an authenticated session. + * + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(Request $request) + { + Auth::guard('web')->logout(); + + $request->session()->invalidate(); + + $request->session()->regenerateToken(); + + return redirect('/'); + } +} diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php deleted file mode 100644 index 5f8b22c..0000000 --- a/app/Http/Controllers/Auth/LoginController.php +++ /dev/null @@ -1,41 +0,0 @@ - 'required|string|email', + 'password' => 'required|string', + ]; + } + + /** + * Attempt to authenticate the request's credentials. + * + * @return void + * + * @throws \Illuminate\Validation\ValidationException + */ + public function authenticate() + { + $this->ensureIsNotRateLimited(); + + if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { + RateLimiter::hit($this->throttleKey()); + + throw ValidationException::withMessages([ + 'email' => __('auth.failed'), + ]); + } + + RateLimiter::clear($this->throttleKey()); + } + + /** + * Ensure the login request is not rate limited. + * + * @return void + * + * @throws \Illuminate\Validation\ValidationException + */ + public function ensureIsNotRateLimited() + { + if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { + return; + } + + event(new Lockout($this)); + + $seconds = RateLimiter::availableIn($this->throttleKey()); + + throw ValidationException::withMessages([ + 'email' => trans('auth.throttle', [ + 'seconds' => $seconds, + 'minutes' => ceil($seconds / 60), + ]), + ]); + } + + /** + * Get the rate limiting throttle key for the request. + * + * @return string + */ + public function throttleKey() + { + return Str::lower($this->input('email')).'|'.$this->ip(); + } +} diff --git a/composer.json b/composer.json index 4f05e6e..6e2ee87 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,6 @@ "inertiajs/inertia-laravel": "^0.4", "laravel/framework": "^8.40", "laravel/tinker": "^2.5", - "laravel/ui": "^2.0", "league/glide-laravel": "^1.0", "tightenco/ziggy": "^0.8.0" }, diff --git a/composer.lock b/composer.lock index 4e49108..7cf4dcc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3b6210b9a1903f968a3c773d9a60aad9", + "content-hash": "669badae23389c95a5f7e1890b965ae9", "packages": [ { "name": "asm89/stack-cors", @@ -1299,65 +1299,6 @@ }, "time": "2021-03-02T16:53:12+00:00" }, - { - "name": "laravel/ui", - "version": "v2.3.0", - "source": { - "type": "git", - "url": "https://github.com/laravel/ui.git", - "reference": "2ccaa3b821ea8ac7e05393b946d0578bdb46099b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laravel/ui/zipball/2ccaa3b821ea8ac7e05393b946d0578bdb46099b", - "reference": "2ccaa3b821ea8ac7e05393b946d0578bdb46099b", - "shasum": "" - }, - "require": { - "illuminate/console": "^7.0|^8.0", - "illuminate/filesystem": "^7.0|^8.0", - "illuminate/support": "^7.0|^8.0", - "php": "^7.2.5" - }, - "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^8.0|^9.0" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Laravel\\Ui\\UiServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "Laravel\\Ui\\": "src/", - "Illuminate\\Foundation\\Auth\\": "auth-backend/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylor@laravel.com" - } - ], - "description": "Laravel UI utilities and presets.", - "keywords": [ - "laravel", - "ui" - ], - "support": { - "issues": "https://github.com/laravel/ui/issues", - "source": "https://github.com/laravel/ui/tree/v2.3.0" - }, - "time": "2020-09-09T12:07:59+00:00" - }, { "name": "league/commonmark", "version": "1.6.1", diff --git a/resources/js/Pages/Auth/Login.vue b/resources/js/Pages/Auth/Login.vue index c3a1a6c..e1aa524 100644 --- a/resources/js/Pages/Auth/Login.vue +++ b/resources/js/Pages/Auth/Login.vue @@ -13,9 +13,8 @@ Remember Me -
@@ -45,12 +44,7 @@ export default { }, methods: { login() { - this.form - .transform(data => ({ - ...data, - remember: data.remember ? 'on' : '', - })) - .post(this.route('login.attempt')) + this.form.post(this.route('login.store')) }, }, } diff --git a/resources/js/Shared/Layout.vue b/resources/js/Shared/Layout.vue index a8c0e52..46a2c4a 100644 --- a/resources/js/Shared/Layout.vue +++ b/resources/js/Shared/Layout.vue @@ -28,7 +28,7 @@