2023-04-20 20:00:38 +02:00
|
|
|
<?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'))
|
2023-04-20 20:00:38 +02:00
|
|
|
->first();
|
|
|
|
|
2023-05-07 17:02:00 +02:00
|
|
|
if ($user && Hash::check($request->input('password'), $user->password)) {
|
2023-04-20 20:00:38 +02:00
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
// Fortify::createUsersUsing(CreateNewUser::class);
|
|
|
|
// Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
|
|
|
|
// Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
|
|
|
|
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
|
|
|
|
|
2023-05-07 17:02:00 +02:00
|
|
|
RateLimiter::for('login', static function (Request $request) {
|
|
|
|
$email = (string) $request->input('email');
|
2023-04-20 20:00:38 +02:00
|
|
|
|
2023-05-07 17:02:00 +02:00
|
|
|
return Limit::perMinute(5)->by($email.((string) $request->ip()));
|
2023-04-20 20:00:38 +02:00
|
|
|
});
|
|
|
|
|
2023-05-07 17:02:00 +02:00
|
|
|
RateLimiter::for('two-factor', static function (Request $request) {
|
2023-04-20 20:00:38 +02:00
|
|
|
return Limit::perMinute(5)->by($request->session()->get('login.id'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|