105 lines
3.2 KiB
PHP
105 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Actions\Fortify\CreateNewUser;
|
|
use App\Actions\Fortify\ResetUserPassword;
|
|
use App\Services\EvaluationNavigation;
|
|
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);
|
|
Fortify::createUsersUsing(CreateNewUser::class);
|
|
}
|
|
|
|
/**
|
|
* Configure Fortify views.
|
|
*/
|
|
private function configureViews(): void
|
|
{
|
|
Fortify::loginView(fn (Request $request) => EvaluationNavigation::local($request) ? redirect('/avaliar') : 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'),
|
|
]));
|
|
|
|
Fortify::registerView(fn () => Inertia::render('auth/register', [
|
|
'passwordRules' => Password::defaults()->toPasswordRulesString(),
|
|
]));
|
|
|
|
Fortify::twoFactorChallengeView(function () {
|
|
Inertia::encryptHistory();
|
|
$response = Inertia::render('auth/two-factor-challenge')->toResponse(request());
|
|
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
|
|
|
return $response;
|
|
});
|
|
Fortify::confirmPasswordView(function () {
|
|
Inertia::encryptHistory();
|
|
|
|
$response = Inertia::render('auth/confirm-password')->toResponse(request());
|
|
$response->headers->set('Cache-Control', 'private, no-store, max-age=0');
|
|
|
|
return $response;
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
* Configure rate limiting.
|
|
*/
|
|
private function configureRateLimiting(): void
|
|
{
|
|
|
|
RateLimiter::for('login', function (Request $request) {
|
|
$throttleKey = Str::transliterate(Str::lower($request->input(Fortify::username())).'|'.$request->ip());
|
|
|
|
return Limit::perMinute(5)->by($throttleKey);
|
|
});
|
|
|
|
RateLimiter::for('two-factor', fn (Request $request) => Limit::perMinute(5)->by((string) $request->session()->get('login.id').'|'.$request->ip()));
|
|
|
|
}
|
|
}
|