diff --git a/app/Providers/FortifyServiceProvider.php b/app/Providers/FortifyServiceProvider.php index d44d9f6..1a3a114 100644 --- a/app/Providers/FortifyServiceProvider.php +++ b/app/Providers/FortifyServiceProvider.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; +use Illuminate\Validation\ValidationException; use Inertia\Inertia; use Laravel\Fortify\Features; use Laravel\Fortify\Fortify; @@ -46,6 +47,12 @@ private function configureActions(): void ->first(); if ($user && Hash::check($request->password, $user->password)) { + if (! $user->is_active) { + throw ValidationException::withMessages([ + Fortify::username() => __('auth.inactive'), + ]); + } + return $user; } }); diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 7ca4261..fae6bd3 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -27,7 +27,7 @@ public function definition(): array 'username' => fake()->userName(), 'email' => fake()->unique()->safeEmail(), 'password' => static::$password ??= Hash::make('password'), - 'is_active' => fake()->boolean(80), + 'is_active' => true, ]; } diff --git a/lang/en/auth.php b/lang/en/auth.php index 6598e2c..ed22f3a 100644 --- a/lang/en/auth.php +++ b/lang/en/auth.php @@ -14,6 +14,7 @@ */ 'failed' => 'These credentials do not match our records.', + 'inactive' => 'Your account is inactive. Please contact the administrator.', 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', diff --git a/lang/id/auth.php b/lang/id/auth.php index 38931c7..bcee738 100644 --- a/lang/id/auth.php +++ b/lang/id/auth.php @@ -4,6 +4,7 @@ return [ 'failed' => 'Identitas tersebut tidak cocok dengan data kami.', + 'inactive' => 'Akun Anda sudah tidak aktif. Silakan hubungi administrator.', 'password' => 'Kata sandi salah.', - 'throttle' => 'Terlalu banyak upaya masuk. Silahkan coba lagi dalam :seconds detik.', + 'throttle' => 'Terlalu banyak upaya masuk. Silakan coba lagi dalam :seconds detik.', ]; diff --git a/tests/Feature/Auth/LoginTest.php b/tests/Feature/Auth/LoginTest.php index 754982f..0edc87a 100644 --- a/tests/Feature/Auth/LoginTest.php +++ b/tests/Feature/Auth/LoginTest.php @@ -61,6 +61,21 @@ assertGuest(); }); + it('cannot login if account is inactive', function () { + $user = User::factory()->create([ + 'email' => 'inactive@example.com', + 'password' => bcrypt('password123'), + 'is_active' => false, + ]); + + post(route('login'), [ + 'login' => 'inactive@example.com', + 'password' => 'password123', + ])->assertSessionHasErrors(['login' => __('auth.inactive')]); + + assertGuest(); + }); + it('cannot login with non-existent email', function () { post(route('login'), [ 'login' => 'notfound@example.com',