Skip to content

Commit

Permalink
Removed reset password route as it was unnecessary.
Browse files Browse the repository at this point in the history
Renamed PasswordResetController -> PasswordResetService.

Simplified sendResetLink.
  • Loading branch information
GeminiDev1 committed Oct 14, 2024
1 parent c4d1bb4 commit b23255d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 59 deletions.
6 changes: 1 addition & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,7 +20,4 @@
});
}
}
});

// Password reset routes
Route::get('/password/reset', [PasswordResetController::class])->name('password.reset');
});
49 changes: 0 additions & 49 deletions src/Http/Controllers/PasswordResetController.php

This file was deleted.

7 changes: 2 additions & 5 deletions src/Resources/FilamentUserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down
37 changes: 37 additions & 0 deletions src/Services/PasswordResetService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Chiiya\FilamentAccessControl\Services;

use Chiiya\FilamentAccessControl\Models\FilamentUser;
use Filament\Facades\Filament;
use Illuminate\Support\Facades\Password;
use Filament\Notifications\Auth\ResetPassword as ResetPasswordNotification;
use Filament\Notifications\Notification;
use Exception;

class PasswordResetService
{
public function sendResetLink(FilamentUser $user)
{
try {
$token = Password::broker('filament')->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();
}
}
}

0 comments on commit b23255d

Please sign in to comment.