-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31af2c5
commit 51f9c2e
Showing
6 changed files
with
96 additions
and
63 deletions.
There are no files selected for viewing
57 changes: 0 additions & 57 deletions
57
app/Filament/Organizations/Resources/UserResource/Actions/ResetPassword.php
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
app/Filament/Organizations/Resources/UserResource/Actions/ResetPasswordAction.php
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,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Organizations\Resources\UserResource\Actions; | ||
|
||
use App\Models\User; | ||
use Exception; | ||
use Filament\Actions\Action; | ||
use Filament\Facades\Filament; | ||
use Filament\Notifications\Auth\ResetPassword as ResetPasswordNotification; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Contracts\Auth\CanResetPassword; | ||
use Illuminate\Support\Facades\Password; | ||
|
||
class ResetPasswordAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'reset-password'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->visible(fn (User $record) => $record->userStatus->isActive() && ! Filament::auth()->user()->is($record)); | ||
|
||
$this->label(__('user.actions.reset_password')); | ||
|
||
$this->icon('heroicon-o-lock-open'); | ||
|
||
$this->outlined(); | ||
|
||
$this->modalHeading(__('user.action_reset_password_confirm.title')); | ||
|
||
$this->modalSubmitActionLabel(__('user.action_reset_password_confirm.title')); | ||
|
||
$this->modalWidth('md'); | ||
|
||
$this->action(function (User $record) { | ||
$status = Password::broker(Filament::getAuthPasswordBroker()) | ||
->sendResetLink( | ||
['email' => $record->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); | ||
} | ||
); | ||
|
||
if ($status !== Password::RESET_LINK_SENT) { | ||
$this->failureNotificationTitle(__($status)); | ||
$this->failure(); | ||
|
||
return; | ||
} | ||
|
||
$this->successNotificationTitle(__($status)); | ||
$this->success(); | ||
}); | ||
|
||
$this->successNotificationTitle(__('user.action_reset_password_confirm.success')); | ||
|
||
$this->failureNotification( | ||
fn (Notification $notification) => $notification | ||
->danger() | ||
->title(__('user.action_reset_password_confirm.failure_title')) | ||
->body(__('user.action_reset_password_confirm.failure_body')) | ||
); | ||
} | ||
} |
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
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
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
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