feat: add account inactivity check during login and update related messages
This commit is contained in:
parent
69aff5a8a7
commit
ad6b9e9618
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -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.',
|
||||
|
||||
|
||||
@ -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.',
|
||||
];
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user