From 9af3bb2c776a208dd971724a45a91901d36afc19 Mon Sep 17 00:00:00 2001 From: Alex Popa Date: Mon, 9 Sep 2024 16:09:18 +0300 Subject: [PATCH] Reset password --- .../Resources/UserResource/Pages/ViewUser.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/Filament/Resources/UserResource/Pages/ViewUser.php b/app/Filament/Resources/UserResource/Pages/ViewUser.php index 64282e0..ca2b471 100644 --- a/app/Filament/Resources/UserResource/Pages/ViewUser.php +++ b/app/Filament/Resources/UserResource/Pages/ViewUser.php @@ -5,9 +5,37 @@ namespace App\Filament\Resources\UserResource\Pages; use App\Filament\Resources\UserResource; +use Filament\Notifications\Notification; +use Filament\Pages\Actions\Action; +use Filament\Pages\Actions\EditAction; use Filament\Resources\Pages\ViewRecord; +use Illuminate\Support\Facades\Password; class ViewUser extends ViewRecord { protected static string $resource = UserResource::class; + + protected function getActions(): array + { + return [ + Action::make('reset_password') + ->label('Reset Password') + ->outlined() + ->action(function () { + $response = Password::broker(config('filament-breezy.reset_broker', config('auth.defaults.passwords')))->sendResetLink(['email' => $this->getRecord()->email]); + if ($response == Password::RESET_LINK_SENT) { + Notification::make()->title(__('filament-breezy::default.reset_password.notification_success'))->success()->send(); + + $this->hasBeenSent = true; + } else { + Notification::make()->title(match ($response) { + 'passwords.throttled' => __('passwords.throttled'), + 'passwords.user' => __('passwords.user') + })->danger()->send(); + } + }), + + EditAction::make(), + ]; + } }