openstamanager/app/Providers/FortifyServiceProvider.php

55 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Providers;
use App\Actions\Fortify\ResetUserPassword;
use App\Models\User;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Fortify::authenticateUsing(static function (Request $request) {
2023-05-08 19:31:18 +02:00
$user = User::where('email', $request->input('username'))
->orWhere('username', $request->input('username'))
->first();
if ($user && Hash::check($request->input('password'), $user->password)) {
return $user;
}
return false;
});
// Fortify::createUsersUsing(CreateNewUser::class);
// Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
// Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
RateLimiter::for('login', static function (Request $request) {
$email = (string) $request->input('email');
return Limit::perMinute(5)->by($email.((string) $request->ip()));
});
RateLimiter::for('two-factor', static function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
}
}