Files
Investidor-V2/app/Providers/FortifyServiceProvider.php
T
nala 250ac35fd1
tests / ci (push) Canceled after 0s
first commit
2026-09-28 10:01:09 +02:00

118 lines
3.6 KiB
PHP

<?php
namespace App\Providers;
/* @chisel-registration */
use App\Actions\Fortify\CreateNewUser;
/* @end-chisel-registration */
use App\Actions\Fortify\ResetUserPassword;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules\Password;
use Inertia\Inertia;
use Laravel\Fortify\Features;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
$this->configureActions();
$this->configureViews();
$this->configureRateLimiting();
}
/**
* Configure Fortify actions.
*/
private function configureActions(): void
{
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
/* @chisel-registration */
Fortify::createUsersUsing(CreateNewUser::class);
/* @end-chisel-registration */
}
/**
* Configure Fortify views.
*/
private function configureViews(): void
{
Fortify::loginView(fn (Request $request) => Inertia::render('auth/login', [
'canResetPassword' => Features::enabled(Features::resetPasswords()),
'status' => $request->session()->get('status'),
]));
Fortify::resetPasswordView(fn (Request $request) => Inertia::render('auth/reset-password', [
'email' => $request->email,
'token' => $request->route('token'),
'passwordRules' => Password::defaults()->toPasswordRulesString(),
]));
Fortify::requestPasswordResetLinkView(fn (Request $request) => Inertia::render('auth/forgot-password', [
'status' => $request->session()->get('status'),
]));
/* @chisel-email-verification */
Fortify::verifyEmailView(fn (Request $request) => Inertia::render('auth/verify-email', [
'status' => $request->session()->get('status'),
]));
/* @end-chisel-email-verification */
/* @chisel-registration */
Fortify::registerView(fn () => Inertia::render('auth/register', [
'passwordRules' => Password::defaults()->toPasswordRulesString(),
]));
/* @end-chisel-registration */
/* @chisel-2fa */
Fortify::twoFactorChallengeView(fn () => Inertia::render('auth/two-factor-challenge'));
/* @end-chisel-2fa */
/* @chisel-password-confirmation */
Fortify::confirmPasswordView(fn () => Inertia::render('auth/confirm-password'));
/* @end-chisel-password-confirmation */
}
/**
* Configure rate limiting.
*/
private function configureRateLimiting(): void
{
/* @chisel-2fa */
RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
/* @end-chisel-2fa */
RateLimiter::for('login', function (Request $request) {
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
return Limit::perMinute(5)->by($throttleKey);
});
/* @chisel-passkeys */
RateLimiter::for('passkeys', function (Request $request) {
return Limit::perMinute(10)->by(
($request->input('credential.id') ?: $request->session()->getId()).'|'.$request->ip(),
);
});
/* @end-chisel-passkeys */
}
}