URL Shortener 1.0
A Laravel-based URL shortener application
Chargement...
Recherche...
Aucune correspondance
LoginRequest.php
Aller à la documentation de ce fichier.
1<?php
2
4
5use Illuminate\Auth\Events\Lockout;
6use Illuminate\Foundation\Http\FormRequest;
7use Illuminate\Support\Facades\Auth;
8use Illuminate\Support\Facades\RateLimiter;
9use Illuminate\Support\Str;
10use Illuminate\Validation\ValidationException;
11
12class LoginRequest extends FormRequest
13{
17 public function authorize(): bool
18 {
19 return true;
20 }
21
27 public function rules(): array
28 {
29 return [
30 'email' => ['required', 'string', 'email'],
31 'password' => ['required', 'string'],
32 ];
33 }
34
40 public function authenticate(): void
41 {
43
44 if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
45 RateLimiter::hit($this->throttleKey());
46
47 throw ValidationException::withMessages([
48 'email' => trans('auth.failed'),
49 ]);
50 }
51
52 RateLimiter::clear($this->throttleKey());
53 }
54
60 public function ensureIsNotRateLimited(): void
61 {
62 if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
63 return;
64 }
65
66 event(new Lockout($this));
67
68 $seconds = RateLimiter::availableIn($this->throttleKey());
69
70 throw ValidationException::withMessages([
71 'email' => trans('auth.throttle', [
72 'seconds' => $seconds,
73 'minutes' => ceil($seconds / 60),
74 ]),
75 ]);
76 }
77
81 public function throttleKey(): string
82 {
83 return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
84 }
85}
rules()
Get the validation rules that apply to the request.
ensureIsNotRateLimited()
Ensure the login request is not rate limited.
authenticate()
Attempt to authenticate the request's credentials.
authorize()
Determine if the user is authorized to make this request.
throttleKey()
Get the rate limiting throttle key for the request.