Skip to content

feat: (LAR-77) Mise en place du login avec Breeze livewire #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions app/Actions/Fortify/CreateNewUser.php

This file was deleted.

26 changes: 0 additions & 26 deletions app/Actions/Fortify/PasswordValidationRules.php

This file was deleted.

26 changes: 0 additions & 26 deletions app/Actions/Fortify/ResetUserPassword.php

This file was deleted.

31 changes: 0 additions & 31 deletions app/Actions/Fortify/UpdateUserPassword.php

This file was deleted.

48 changes: 0 additions & 48 deletions app/Actions/Fortify/UpdateUserProfileInformation.php

This file was deleted.

35 changes: 35 additions & 0 deletions app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;

final class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*/
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
$user = $request->user();

if ($user === null) {
return redirect()->route('login');
}

if ($user->hasVerifiedEmail()) {
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}

if ($user->markEmailAsVerified()) {
event(new Verified($user));
}

return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}
}
74 changes: 74 additions & 0 deletions app/Livewire/Forms/LoginForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace App\Livewire\Forms;

use Illuminate\Auth\Events\Lockout;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Livewire\Attributes\Validate;
use Livewire\Form;

final class LoginForm extends Form
{
#[Validate('required|string|email')]
public string $email = '';

#[Validate('required|string')]
public string $password = '';

#[Validate('boolean')]
public bool $remember = false;

/**
* Attempt to authenticate the request's credentials.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function authenticate(): void
{
$this->ensureIsNotRateLimited();

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

throw ValidationException::withMessages([
'form.email' => trans('auth.failed'),
]);
}

RateLimiter::clear($this->throttleKey());
}

/**
* Ensure the authentication request is not rate limited.
*/
protected function ensureIsNotRateLimited(): void
{
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
return;
}

event(new Lockout(request()));

$seconds = RateLimiter::availableIn($this->throttleKey());

throw ValidationException::withMessages([
'form.email' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
]);
}

/**
* Get the authentication rate limiting throttle key.
*/
protected function throttleKey(): string
{
return Str::transliterate(Str::lower($this->email).'|'.request()->ip());
}
}
47 changes: 0 additions & 47 deletions app/Providers/FortifyServiceProvider.php

This file was deleted.

21 changes: 21 additions & 0 deletions app/Providers/VoltServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Livewire\Volt\Volt;

final class VoltServiceProvider extends ServiceProvider
{
public function register(): void {}

public function boot(): void
{
Volt::mount([
config('livewire.view_path', resource_path('views/livewire')),
resource_path('views/pages'),
]);
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"jenssegers/agent": "^2.6.4",
"laravel-notification-channels/telegram": "^4.0",
"laravel-notification-channels/twitter": "^8.0",
"laravel/fortify": "^1.17.4",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2.5",
"laravel/slack-notification-channel": "^2.5",
Expand All @@ -31,6 +30,7 @@
"laravelcm/laravel-subscriptions": "^1.3",
"laravelcm/livewire-slide-overs": "^1.0",
"livewire/livewire": "^3.0",
"livewire/volt": "^1.6",
"mckenziearts/blade-untitledui-icons": "^1.3",
"notchpay/notchpay-php": "^1.6",
"qcod/laravel-gamify": "1.0.7",
Expand All @@ -54,11 +54,12 @@
},
"require-dev": {
"fakerphp/faker": "^1.23.0",
"larastan/larastan": "^2.8",
"laravel/breeze": "^1.29",
"laravel/pint": "^1.10.3",
"laravel/sail": "^1.23.0",
"mockery/mockery": "^1.6.2",
"nunomaduro/collision": "^7.0",
"larastan/larastan": "^2.8",
"pestphp/pest": "^2.32",
"pestphp/pest-plugin-laravel": "^2.1",
"pestphp/pest-plugin-livewire": "^2.1",
Expand Down
Loading
Loading