diff --git a/routes/web.php b/routes/web.php index d9c485e..ef1b390 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,7 +2,6 @@ use Chiiya\FilamentAccessControl\Http\Livewire\AccountExpired; use Chiiya\FilamentAccessControl\Http\Livewire\TwoFactorChallenge; -use Chiiya\FilamentAccessControl\Http\Controllers\PasswordResetController; use Filament\Facades\Filament; use Illuminate\Support\Facades\Route; @@ -21,7 +20,4 @@ }); } } -}); - -// Password reset routes -Route::get('/password/reset', [PasswordResetController::class])->name('password.reset'); +}); \ No newline at end of file diff --git a/src/Http/Controllers/PasswordResetController.php b/src/Http/Controllers/PasswordResetController.php deleted file mode 100644 index fbe7299..0000000 --- a/src/Http/Controllers/PasswordResetController.php +++ /dev/null @@ -1,49 +0,0 @@ -validate([ - 'email' => 'required|email', - ]); - - // Attempt to send the reset link - $response = Password::sendResetLink($request->only('email'), 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); - $notification->url = Filament::getResetPasswordUrl($token, $user); - - $user->notify($notification); - }); - - // Check the response status - if ($response === Password::RESET_LINK_SENT) { - Notification::make() - ->title(__('Password reset link sent!')) - ->success() - ->send(); - } else { - Notification::make() - ->title(__('Failed to send password reset link.')) - ->danger() - ->send(); - } - } -} diff --git a/src/Resources/FilamentUserResource.php b/src/Resources/FilamentUserResource.php index fa0b352..5907d98 100644 --- a/src/Resources/FilamentUserResource.php +++ b/src/Resources/FilamentUserResource.php @@ -2,7 +2,7 @@ namespace Chiiya\FilamentAccessControl\Resources; -use Chiiya\FilamentAccessControl\Http\Controllers\PasswordResetController; +use Chiiya\FilamentAccessControl\Services\PasswordResetService; use Carbon\Carbon; use Carbon\CarbonImmutable; use Chiiya\FilamentAccessControl\Contracts\AccessControlUser; @@ -111,10 +111,7 @@ public static function table(Table $table): Table ]) ->actions([EditAction::make(), ViewAction::make(), Action::make('reset_password') ->action(function ($record) { - // Call the method to send reset link - return (new PasswordResetController())->sendResetLink(new Request([ - 'email' => $record->email, // Pass the user's email - ])); + return (new PasswordResetService())->sendResetLink($record); })]) ->bulkActions([ BulkActionGroup::make([ diff --git a/src/Services/PasswordResetService.php b/src/Services/PasswordResetService.php new file mode 100644 index 0000000..449cb09 --- /dev/null +++ b/src/Services/PasswordResetService.php @@ -0,0 +1,37 @@ +createToken($user); + + // Create the notification and set the URL + $notification = new ResetPasswordNotification($token); + $notification->url = Filament::getResetPasswordUrl($token, $user); + + // Send the notification + $user->notify($notification); + + Notification::make() + ->title(__('Password reset link sent!')) + ->success() + ->send(); + } catch (Exception $e) { + Notification::make() + ->title($e->getMessage()) + ->danger() + ->send(); + } + } +}