Skip to content

Commit 54d4378

Browse files
committed
feat: (LAR-77) Ajout du message d'erreur sur l'interface de connexion et refractoring du code
1 parent 9ff7777 commit 54d4378

File tree

5 files changed

+57
-107
lines changed

5 files changed

+57
-107
lines changed

app/Livewire/Forms/LoginForm.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,30 @@
77
use Illuminate\Support\Facades\RateLimiter;
88
use Illuminate\Support\Str;
99
use Illuminate\Validation\ValidationException;
10+
use Livewire\Attributes\Validate;
1011
use Livewire\Form;
11-
use Livewire\Component;
1212

1313
class LoginForm extends Form
1414
{
15+
#[Validate('required|string|email')]
1516
public string $email = '';
17+
18+
#[Validate('required|string')]
1619
public string $password = '';
17-
public bool $remember = false;
1820

19-
public function __construct(Component $component = null, string $name = 'form')
20-
{
21-
$component = $component ?? app(Component::class);
22-
parent::__construct($component, $name);
23-
}
21+
#[Validate('boolean')]
22+
public bool $remember = false;
2423

24+
/**
25+
* Attempt to authenticate the request's credentials.
26+
*
27+
* @throws \Illuminate\Validation\ValidationException
28+
*/
2529
public function authenticate(): void
2630
{
2731
$this->ensureIsNotRateLimited();
2832

29-
if (!Auth::attempt(['email' => $this->email, 'password' => $this->password], $this->remember)) {
33+
if (! Auth::attempt($this->only(['email', 'password']), $this->remember)) {
3034
RateLimiter::hit($this->throttleKey());
3135

3236
throw ValidationException::withMessages([
@@ -37,9 +41,12 @@ public function authenticate(): void
3741
RateLimiter::clear($this->throttleKey());
3842
}
3943

44+
/**
45+
* Ensure the authentication request is not rate limited.
46+
*/
4047
protected function ensureIsNotRateLimited(): void
4148
{
42-
if (!RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
49+
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
4350
return;
4451
}
4552

@@ -55,8 +62,11 @@ protected function ensureIsNotRateLimited(): void
5562
]);
5663
}
5764

65+
/**
66+
* Get the authentication rate limiting throttle key.
67+
*/
5868
protected function throttleKey(): string
5969
{
60-
return Str::transliterate(Str::lower($this->email) . '|' . request()->ip());
70+
return Str::transliterate(Str::lower($this->email).'|'.request()->ip());
6171
}
62-
}
72+
}

app/Livewire/Pages/Auth/Login.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

resources/views/components/input-label.blade.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

resources/views/components/text-input.blade.php

Lines changed: 0 additions & 3 deletions
This file was deleted.

resources/views/livewire/pages/auth/login.blade.php

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Livewire\Attributes\Layout;
88
use Livewire\Volt\Component;
99
10-
new #[Layout('layouts.guest')] class extends Component
10+
new class extends Component
1111
{
1212
public LoginForm $form;
1313
@@ -22,74 +22,62 @@ public function login(): void
2222
$this->redirectIntended(default: route('dashboard', absolute: false), navigate: true);
2323
}
2424
}; ?>
25+
2526
<div>
2627
<x-container class="flex min-h-full items-center justify-center py-16 sm:pt-24">
2728
<div class="w-full max-w-md space-y-8">
2829
<div>
30+
<x-validation-errors />
2931
<h2 class="text-center font-heading text-3xl font-extrabold text-gray-900 dark:text-white">
3032
{{ __('pages/auth.login.title') }}
3133
</h2>
3234
</div>
33-
<form class="space-y-6" wire:submit.prevent="login">
35+
<form class="space-y-6" wire:submit="login">
3436
@csrf
3537
<div class="space-y-4">
36-
<div class="space-y-1">
37-
<label for="email" class="block text-sm font-medium text-gray-700 dark:text-gray-300">
38-
{{ __('validation.attributes.email') }}
39-
</label>
40-
<x-text-input
41-
type="email"
42-
id="email"
43-
wire:model="form.email"
44-
name="email"
45-
required
46-
placeholder="{{ __('validation.attributes.email') }}"
47-
class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white"
38+
<x-filament::input.wrapper>
39+
<x-filament::input
40+
type="text"
41+
id="email-address"
42+
name="email"
43+
autocomplete="email"
44+
required="true"
45+
wire:model="form.email"
46+
aria-label="{{ __('validation.attributes.email') }}"
47+
:placeholder="__('validation.attributes.email')"
4848
/>
49-
@error('form.email')
50-
<span class="text-sm text-red-500">{{ $message }}</span>
51-
@enderror
52-
</div>
53-
54-
<div class="space-y-1">
55-
<label for="password" class="block text-sm font-medium text-gray-700 dark:text-gray-300">
56-
{{ __('validation.attributes.password') }}
57-
</label>
58-
<x-text-input
59-
type="password"
60-
id="password"
49+
</x-filament::input.wrapper>
50+
<x-filament::input.wrapper>
51+
<x-filament::input
52+
type="password"
53+
id="password"
54+
name="password"
55+
required="true"
6156
wire:model="form.password"
62-
name="password"
63-
required
64-
placeholder="{{ __('validation.attributes.password') }}"
65-
class="block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white"
57+
aria-label="{{ __('validation.attributes.password') }}"
58+
:placeholder="__('validation.attributes.password')"
6659
/>
67-
@error('form.password')
68-
<span class="text-sm text-red-500">{{ $message }}</span>
69-
@enderror
70-
</div>
60+
</x-filament::input.wrapper>
7161
</div>
72-
62+
7363
<div class="flex items-center justify-between">
7464
<div class="flex items-center">
75-
<input
76-
type="checkbox"
77-
id="remember_me"
78-
wire:model="form.remember"
79-
class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded"
80-
/>
81-
<label for="remember_me" class="ml-2 block text-sm text-gray-500 dark:text-gray-400">
65+
<label class="inline-flex items-center gap-2 cursor-pointer text-sm text-gray-500 dark:text-gray-400">
66+
<x-filament::input.checkbox id="remember_me" name="remember_me" />
8267
{{ __('pages/auth.login.remember_me') }}
8368
</label>
8469
</div>
85-
70+
8671
<div class="text-sm">
87-
<a href="{{ route('password.request') }}" class="font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-white">
72+
<x-link
73+
:href="route('password.request')"
74+
class="font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-white"
75+
>
8876
{{ __('pages/auth.login.forgot_password') }}
89-
</a>
77+
</x-link>
9078
</div>
9179
</div>
92-
80+
9381
<div>
9482
<x-buttons.primary type="submit" class="group relative w-full">
9583
<span class="absolute pointer-events-none inset-y-0 left-0 flex items-center pl-3">
@@ -99,10 +87,11 @@ class="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded"
9987
</x-buttons.primary>
10088
</div>
10189
</form>
90+
10291
@include('partials._socials-link')
10392
</div>
10493
</x-container>
105-
94+
10695
<x-join-sponsors :title="__('global.sponsor_thanks')" />
10796
</div>
10897

0 commit comments

Comments
 (0)