Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisha Witte committed Oct 22, 2024
1 parent 5e47123 commit fe541a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 44 deletions.
13 changes: 6 additions & 7 deletions src/Resources/FilamentUserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Chiiya\FilamentAccessControl\Resources;

use Chiiya\FilamentAccessControl\Services\PasswordResetService;
use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Chiiya\FilamentAccessControl\Contracts\AccessControlUser;
Expand All @@ -13,6 +12,7 @@
use Chiiya\FilamentAccessControl\Resources\FilamentUserResource\Pages\EditFilamentUser;
use Chiiya\FilamentAccessControl\Resources\FilamentUserResource\Pages\ListFilamentUsers;
use Chiiya\FilamentAccessControl\Resources\FilamentUserResource\Pages\ViewFilamentUser;
use Chiiya\FilamentAccessControl\Services\AuthService;
use Chiiya\FilamentAccessControl\Traits\HasExtendableSchema;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Grid;
Expand All @@ -35,7 +35,6 @@
use Illuminate\Database\Eloquent\Builder;
use Livewire\Component;


class FilamentUserResource extends Resource
{
use HasExtendableSchema;
Expand Down Expand Up @@ -118,9 +117,9 @@ public static function table(Table $table): Table
->icon('heroicon-o-key')
->label(__('filament-access-control::default.actions.reset_password'))
->requiresConfirmation()
->action(function ($record) {
return (new PasswordResetService())->sendResetLink($record);
}),
->action(
fn (AccessControlUser $record) => resolve(AuthService::class)->sendResetLink($record),
),
],
Feature::enabled(Feature::ACCOUNT_EXPIRY)
? [
Expand All @@ -130,8 +129,8 @@ public static function table(Table $table): Table
->requiresConfirmation()
->icon('heroicon-o-clock'),
]
: []
))
: [],
)),
])
->bulkActions([
BulkActionGroup::make([
Expand Down
27 changes: 27 additions & 0 deletions src/Services/AuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
use Chiiya\FilamentAccessControl\Exceptions\InvalidCodeException;
use Chiiya\FilamentAccessControl\Exceptions\InvalidUserModelException;
use Chiiya\FilamentAccessControl\Exceptions\UserNotFoundException;
use Exception;
use Filament\Facades\Filament;
use Filament\Notifications\Auth\ResetPassword as ResetPasswordNotification;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Password;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

Expand Down Expand Up @@ -108,6 +112,29 @@ public function performTwoFactorChallenge(string $code): void
$this->login($user, session()->get('filament.remember', false));
}

/**
* Manually send a password reset link to the user.
*/
public function sendResetLink(AccessControlUser $user): void
{
try {
$token = Password::broker('filament')->createToken($user);
$notification = new ResetPasswordNotification($token);
$notification->url = Filament::getResetPasswordUrl($token, $user);
$user->notify($notification);

Notification::make()
->title(__('filament-access-control::default.messages.password_reset_link_sent'))
->success()
->send();
} catch (Exception $e) {
Notification::make()
->title($e->getMessage())
->danger()
->send();
}
}

private function getUserModel(): Model
{
/** @var class-string<Model> $model */
Expand Down
37 changes: 0 additions & 37 deletions src/Services/PasswordResetService.php

This file was deleted.

0 comments on commit fe541a6

Please sign in to comment.