57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Auth;
|
|
|
|
use App\Notifications\ResetPasswordNotification;
|
|
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
|
use Exception;
|
|
use Filament\Auth\Pages\PasswordReset\RequestPasswordReset as BaseRequestPasswordReset;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Notifications\Notification;
|
|
use Illuminate\Contracts\Auth\CanResetPassword;
|
|
use Illuminate\Support\Facades\Password;
|
|
|
|
class RequestPasswordReset extends BaseRequestPasswordReset
|
|
{
|
|
public function request(): void
|
|
{
|
|
try {
|
|
$this->rateLimit(2);
|
|
} catch (TooManyRequestsException $exception) {
|
|
$this->getRateLimitedNotification($exception)?->send();
|
|
|
|
return;
|
|
}
|
|
|
|
$data = $this->form->getState();
|
|
$status = Password::broker(Filament::getAuthPasswordBroker())->sendResetLink(
|
|
$data,
|
|
function (CanResetPassword $user, string $token): void {
|
|
if (! method_exists($user, 'notify')) {
|
|
$userClass = $user::class;
|
|
throw new Exception("Model [{$userClass}] does not have a [notify()] method.");
|
|
}
|
|
|
|
$notification = new ResetPasswordNotification($token);
|
|
$user->notify($notification);
|
|
},
|
|
);
|
|
|
|
if ($status !== Password::RESET_LINK_SENT) {
|
|
Notification::make()
|
|
->title(__($status))
|
|
->danger()
|
|
->send();
|
|
|
|
return;
|
|
}
|
|
|
|
Notification::make()
|
|
->title(__($status))
|
|
->success()
|
|
->send();
|
|
|
|
$this->form->fill();
|
|
}
|
|
}
|