diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index dd375ce..68e478c 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -28,25 +28,23 @@ class LoginRequest extends FormRequest public function rules(): array { return [ - 'email' => ['required', 'string', 'email'], + 'login' => ['required', 'string'], 'password' => ['required', 'string'], ]; } - /** - * Attempt to authenticate the request's credentials. - * - * @throws ValidationException - */ public function authenticate(): void { $this->ensureIsNotRateLimited(); - if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { + $login = $this->string('login')->toString(); + $field = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'name'; + + if (! Auth::attempt([$field => $login, 'password' => $this->string('password')->toString()], $this->boolean('remember'))) { RateLimiter::hit($this->throttleKey()); throw ValidationException::withMessages([ - 'email' => trans('auth.failed'), + 'login' => trans('auth.failed'), ]); } @@ -55,18 +53,13 @@ class LoginRequest extends FormRequest RateLimiter::hit($this->throttleKey()); throw ValidationException::withMessages([ - 'email' => 'Votre compte est désactivé. Contactez un administrateur.', + 'login' => 'Votre compte est désactivé. Contactez un administrateur.', ]); } RateLimiter::clear($this->throttleKey()); } - /** - * Ensure the login request is not rate limited. - * - * @throws ValidationException - */ public function ensureIsNotRateLimited(): void { if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { @@ -78,18 +71,15 @@ class LoginRequest extends FormRequest $seconds = RateLimiter::availableIn($this->throttleKey()); throw ValidationException::withMessages([ - 'email' => trans('auth.throttle', [ + 'login' => trans('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), ]); } - /** - * Get the rate limiting throttle key for the request. - */ public function throttleKey(): string { - return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip()); + return Str::transliterate(Str::lower($this->string('login')).'|'.$this->ip()); } } diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 8dc34e2..1c20eed 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -5,11 +5,11 @@
@csrf - +
- - - + + +