Skip to content

Commit b96b811

Browse files
authored
feat: (LAR-77) Mise en place du login avec Breeze livewire (#173)
1 parent e577abf commit b96b811

22 files changed

+495
-707
lines changed

app/Actions/Fortify/CreateNewUser.php

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

app/Actions/Fortify/PasswordValidationRules.php

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

app/Actions/Fortify/ResetUserPassword.php

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

app/Actions/Fortify/UpdateUserPassword.php

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

app/Actions/Fortify/UpdateUserProfileInformation.php

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Controllers\Auth;
6+
7+
use App\Http\Controllers\Controller;
8+
use Illuminate\Auth\Events\Verified;
9+
use Illuminate\Foundation\Auth\EmailVerificationRequest;
10+
use Illuminate\Http\RedirectResponse;
11+
12+
final class VerifyEmailController extends Controller
13+
{
14+
/**
15+
* Mark the authenticated user's email address as verified.
16+
*/
17+
public function __invoke(EmailVerificationRequest $request): RedirectResponse
18+
{
19+
$user = $request->user();
20+
21+
if ($user === null) {
22+
return redirect()->route('login');
23+
}
24+
25+
if ($user->hasVerifiedEmail()) {
26+
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
27+
}
28+
29+
if ($user->markEmailAsVerified()) {
30+
event(new Verified($user));
31+
}
32+
33+
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
34+
}
35+
}

app/Livewire/Forms/LoginForm.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Forms;
6+
7+
use Illuminate\Auth\Events\Lockout;
8+
use Illuminate\Support\Facades\Auth;
9+
use Illuminate\Support\Facades\RateLimiter;
10+
use Illuminate\Support\Str;
11+
use Illuminate\Validation\ValidationException;
12+
use Livewire\Attributes\Validate;
13+
use Livewire\Form;
14+
15+
final class LoginForm extends Form
16+
{
17+
#[Validate('required|string|email')]
18+
public string $email = '';
19+
20+
#[Validate('required|string')]
21+
public string $password = '';
22+
23+
#[Validate('boolean')]
24+
public bool $remember = false;
25+
26+
/**
27+
* Attempt to authenticate the request's credentials.
28+
*
29+
* @throws \Illuminate\Validation\ValidationException
30+
*/
31+
public function authenticate(): void
32+
{
33+
$this->ensureIsNotRateLimited();
34+
35+
if (! Auth::attempt($this->only(['email', 'password']), $this->remember)) {
36+
RateLimiter::hit($this->throttleKey());
37+
38+
throw ValidationException::withMessages([
39+
'form.email' => trans('auth.failed'),
40+
]);
41+
}
42+
43+
RateLimiter::clear($this->throttleKey());
44+
}
45+
46+
/**
47+
* Ensure the authentication request is not rate limited.
48+
*/
49+
protected function ensureIsNotRateLimited(): void
50+
{
51+
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
52+
return;
53+
}
54+
55+
event(new Lockout(request()));
56+
57+
$seconds = RateLimiter::availableIn($this->throttleKey());
58+
59+
throw ValidationException::withMessages([
60+
'form.email' => trans('auth.throttle', [
61+
'seconds' => $seconds,
62+
'minutes' => ceil($seconds / 60),
63+
]),
64+
]);
65+
}
66+
67+
/**
68+
* Get the authentication rate limiting throttle key.
69+
*/
70+
protected function throttleKey(): string
71+
{
72+
return Str::transliterate(Str::lower($this->email).'|'.request()->ip());
73+
}
74+
}

app/Providers/FortifyServiceProvider.php

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

app/Providers/VoltServiceProvider.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Providers;
6+
7+
use Illuminate\Support\ServiceProvider;
8+
use Livewire\Volt\Volt;
9+
10+
final class VoltServiceProvider extends ServiceProvider
11+
{
12+
public function register(): void {}
13+
14+
public function boot(): void
15+
{
16+
Volt::mount([
17+
config('livewire.view_path', resource_path('views/livewire')),
18+
resource_path('views/pages'),
19+
]);
20+
}
21+
}

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"jenssegers/agent": "^2.6.4",
2323
"laravel-notification-channels/telegram": "^4.0",
2424
"laravel-notification-channels/twitter": "^8.0",
25-
"laravel/fortify": "^1.17.4",
2625
"laravel/framework": "^10.0",
2726
"laravel/sanctum": "^3.2.5",
2827
"laravel/slack-notification-channel": "^2.5",
@@ -31,6 +30,7 @@
3130
"laravelcm/laravel-subscriptions": "^1.3",
3231
"laravelcm/livewire-slide-overs": "^1.0",
3332
"livewire/livewire": "^3.0",
33+
"livewire/volt": "^1.6",
3434
"mckenziearts/blade-untitledui-icons": "^1.3",
3535
"notchpay/notchpay-php": "^1.6",
3636
"qcod/laravel-gamify": "1.0.7",
@@ -54,11 +54,12 @@
5454
},
5555
"require-dev": {
5656
"fakerphp/faker": "^1.23.0",
57+
"larastan/larastan": "^2.8",
58+
"laravel/breeze": "^1.29",
5759
"laravel/pint": "^1.10.3",
5860
"laravel/sail": "^1.23.0",
5961
"mockery/mockery": "^1.6.2",
6062
"nunomaduro/collision": "^7.0",
61-
"larastan/larastan": "^2.8",
6263
"pestphp/pest": "^2.32",
6364
"pestphp/pest-plugin-laravel": "^2.1",
6465
"pestphp/pest-plugin-livewire": "^2.1",

0 commit comments

Comments
 (0)