-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from riodwanto/feature/forgot-password
Feature/forgot password
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace App\Filament\Pages\Auth; | ||
|
||
use App\Settings\MailSettings; | ||
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException; | ||
use Exception; | ||
use Filament\Facades\Filament; | ||
use Filament\Forms\Form; | ||
use Filament\Notifications\Auth\ResetPassword as ResetPasswordNotification; | ||
use Filament\Notifications\Notification; | ||
use Filament\Pages\Auth\PasswordReset\RequestPasswordReset as BaseRequestPasswordReset; | ||
use Illuminate\Contracts\Auth\CanResetPassword; | ||
use Illuminate\Support\Facades\Password; | ||
|
||
class RequestPasswordReset extends BaseRequestPasswordReset | ||
{ | ||
protected static string $view = 'filament-panels::pages.auth.password-reset.request-password-reset'; | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
$this->getEmailFormComponent()->label('Email'), | ||
]); | ||
} | ||
|
||
public function request(): void | ||
{ | ||
try { | ||
$this->rateLimit(3); | ||
} catch (TooManyRequestsException $exception) { | ||
Notification::make() | ||
->title(__('filament-panels::pages/auth/password-reset/request-password-reset.notifications.throttled.title', [ | ||
'seconds' => $exception->secondsUntilAvailable, | ||
'minutes' => ceil($exception->secondsUntilAvailable / 60), | ||
])) | ||
->body(array_key_exists('body', __('filament-panels::pages/auth/password-reset/request-password-reset.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/password-reset/request-password-reset.notifications.throttled.body', [ | ||
'seconds' => $exception->secondsUntilAvailable, | ||
'minutes' => ceil($exception->secondsUntilAvailable / 60), | ||
]) : null) | ||
->danger() | ||
->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."); | ||
} | ||
|
||
$settings = app(MailSettings::class); | ||
$notification = new ResetPasswordNotification($token); | ||
$notification->url = Filament::getResetPasswordUrl($token, $user); | ||
|
||
$settings->loadMailSettingsToConfig(); | ||
|
||
$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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters