Skip to content

Commit 9647e17

Browse files
committed
feat: (LAR-107) Modification du formulaire de mot de passe oublié
1 parent 7768503 commit 9647e17

File tree

2 files changed

+112
-4
lines changed

2 files changed

+112
-4
lines changed

resources/views/livewire/pages/auth/forgot-password.blade.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,37 @@
1-
<x-app-layout :title="__('pages/auth.forgot.page_title')">
1+
<?php
2+
3+
use Illuminate\Support\Facades\Password;
4+
use Livewire\Attributes\Layout;
5+
use Livewire\Volt\Component;
6+
7+
new class extends Component
8+
{
9+
public string $email = '';
10+
11+
public function sendPasswordResetLink(): void
12+
{
13+
$this->validate([
14+
'email' => ['required', 'string', 'email'],
15+
]);
16+
17+
$status = Password::sendResetLink(
18+
$this->only('email')
19+
);
20+
21+
if ($status != Password::RESET_LINK_SENT) {
22+
$this->addError('email', __($status));
23+
24+
return;
25+
}
26+
27+
$this->reset('email');
28+
29+
session()->flash('status', __($status));
30+
}
31+
}; ?>
32+
33+
34+
<div>
235
<div class="flex min-h-full items-center justify-center py-16 sm:py-24">
336
<div class="w-full max-w-md">
437
<div>
@@ -12,8 +45,7 @@
1245
</div>
1346
</div>
1447

15-
<form class="mt-8">
16-
@csrf
48+
<form class="mt-8" wire:submit="sendPasswordResetLink">
1749

1850
<div class="block">
1951
<x-filament-forms::field-wrapper.label for="email">
@@ -24,6 +56,7 @@
2456
type="text"
2557
id="email"
2658
name="email"
59+
wire:model="email"
2760
autocomplete="email"
2861
required="true"
2962
:value="old('email')"
@@ -42,4 +75,4 @@
4275
</div>
4376

4477
<x-join-sponsors :title="__('global.sponsor_thanks')" />
45-
</x-app-layout>
78+
</div>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Feature\Auth;
6+
7+
use App\Models\User;
8+
use Illuminate\Auth\Notifications\ResetPassword;
9+
use Illuminate\Support\Facades\Notification;
10+
use Livewire\Volt\Volt;
11+
12+
test('reset password link screen can be rendered', function (): void {
13+
$response = $this->get('/forgot-password');
14+
15+
$response
16+
->assertSeeVolt('pages.auth.forgot-password')
17+
->assertStatus(200);
18+
});
19+
20+
test('reset password link can be requested', function (): void {
21+
Notification::fake();
22+
23+
$user = User::factory()->create();
24+
25+
Volt::test('pages.auth.forgot-password')
26+
->set('email', $user->email)
27+
->call('sendPasswordResetLink');
28+
29+
Notification::assertSentTo($user, ResetPassword::class);
30+
});
31+
32+
test('reset password screen can be rendered', function (): void {
33+
Notification::fake();
34+
35+
$user = User::factory()->create();
36+
37+
Volt::test('pages.auth.forgot-password')
38+
->set('email', $user->email)
39+
->call('sendPasswordResetLink');
40+
41+
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
42+
$response = $this->get('/reset-password/'.$notification->token);
43+
44+
$response
45+
->assertSeeVolt('pages.auth.reset-password')
46+
->assertStatus(200);
47+
48+
return true;
49+
});
50+
});
51+
52+
test('password can be reset with valid token', function (): void {
53+
Notification::fake();
54+
55+
$user = User::factory()->create();
56+
57+
Volt::test('pages.auth.forgot-password')
58+
->set('email', $user->email)
59+
->call('sendPasswordResetLink');
60+
61+
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
62+
$component = Volt::test('pages.auth.reset-password', ['token' => $notification->token])
63+
->set('email', $user->email)
64+
->set('password', 'password')
65+
->set('password_confirmation', 'password');
66+
67+
$component->call('resetPassword');
68+
69+
$component
70+
->assertRedirect('/login')
71+
->assertHasNoErrors();
72+
73+
return true;
74+
});
75+
});

0 commit comments

Comments
 (0)