Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php

This file was deleted.

94 changes: 0 additions & 94 deletions app/Http/Requests/Auth/LoginRequest.php

This file was deleted.

12 changes: 9 additions & 3 deletions app/Providers/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Inertia\Inertia;
use Illuminate\Support\Str;
use Laravel\Fortify\Actions\RedirectIfTwoFactorAuthenticatable;
use Laravel\Fortify\Fortify;

class FortifyServiceProvider extends ServiceProvider
Expand All @@ -24,11 +25,16 @@ public function register(): void
*/
public function boot(): void
{
Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/TwoFactorChallenge'));
Fortify::confirmPasswordView(fn () => Inertia::render('auth/ConfirmPassword'));
Fortify::redirectUserForTwoFactorAuthenticationUsing(RedirectIfTwoFactorAuthenticatable::class);

RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});

RateLimiter::for('login', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());

return Limit::perMinute(5)->by($throttleKey);
});
}
}
2 changes: 1 addition & 1 deletion config/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
|
*/

'views' => true,
'views' => false,

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions resources/js/pages/auth/Login.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import AuthenticatedSessionController from '@/actions/App/Http/Controllers/Auth/AuthenticatedSessionController';
import InputError from '@/components/InputError.vue';
import TextLink from '@/components/TextLink.vue';
import { Button } from '@/components/ui/button';
Expand All @@ -8,6 +7,7 @@ import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import AuthBase from '@/layouts/AuthLayout.vue';
import { register } from '@/routes';
import { store } from '@/routes/login';
import { request } from '@/routes/password';
import { Form, Head } from '@inertiajs/vue3';
import { LoaderCircle } from 'lucide-vue-next';
Expand All @@ -33,7 +33,7 @@ defineProps<{
</div>

<Form
v-bind="AuthenticatedSessionController.store.form()"
v-bind="store.form()"
:reset-on-success="['password']"
v-slot="{ errors, processing }"
class="flex flex-col gap-6"
Expand Down
21 changes: 12 additions & 9 deletions routes/auth.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?php

use App\Http\Controllers\Auth\AuthenticatedSessionController;
use App\Http\Controllers\Auth\EmailVerificationNotificationController;
use App\Http\Controllers\Auth\EmailVerificationPromptController;
use App\Http\Controllers\Auth\NewPasswordController;
use App\Http\Controllers\Auth\PasswordResetLinkController;
use App\Http\Controllers\Auth\RegisteredUserController;
use App\Http\Controllers\Auth\VerifyEmailController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;

Route::middleware('guest')->group(function () {
Route::get('login', fn (Request $request) => Inertia::render('auth/Login', [
'canResetPassword' => Route::has('password.request'),
'status' => $request->session()->get('status'),
]))->name('login');

Route::get('register', [RegisteredUserController::class, 'create'])
->name('register');

Route::post('register', [RegisteredUserController::class, 'store'])
->name('register.store');

Route::get('login', [AuthenticatedSessionController::class, 'create'])
->name('login');

Route::post('login', [AuthenticatedSessionController::class, 'store'])
->name('login.store');

Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])
->name('password.request');

Expand All @@ -47,6 +47,9 @@
->middleware('throttle:6,1')
->name('verification.send');

Route::post('logout', [AuthenticatedSessionController::class, 'destroy'])
->name('logout');
Route::get('user/confirm-password', fn () => Inertia::render('auth/ConfirmPassword'))
->name('password.confirm');

Route::get('two-factor-challenge', fn () => Inertia::render('auth/TwoFactorChallenge'))
->name('two-factor.login');
});
19 changes: 0 additions & 19 deletions tests/Feature/Auth/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\RateLimiter;
use Laravel\Fortify\Features;
use Tests\TestCase;

Expand Down Expand Up @@ -82,22 +81,4 @@ public function test_users_can_logout()
$this->assertGuest();
$response->assertRedirect(route('home'));
}

public function test_users_are_rate_limited()
{
$user = User::factory()->create();

RateLimiter::increment(implode('|', [$user->email, '127.0.0.1']), amount: 10);

$response = $this->post(route('login.store'), [
'email' => $user->email,
'password' => 'wrong-password',
]);

$response->assertSessionHasErrors('email');

$errors = session('errors');

$this->assertStringContainsString('Too many login attempts', $errors->first('email'));
}
}
9 changes: 2 additions & 7 deletions tests/Feature/Auth/TwoFactorChallengeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Laravel\Fortify\Features;
use Tests\TestCase;

Expand Down Expand Up @@ -42,15 +41,11 @@ public function test_two_factor_challenge_can_be_rendered(): void
'two_factor_confirmed_at' => now(),
])->save();

$this->post(route('login'), [
$response = $this->post(route('login'), [
'email' => $user->email,
'password' => 'password',
]);

$this->get(route('two-factor.login'))
->assertOk()
->assertInertia(fn (Assert $page) => $page
->component('auth/TwoFactorChallenge')
);
$response->assertRedirect(route('two-factor.login'));
}
}
Loading