-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature to send reset password links in admin panel.
- Loading branch information
1 parent
ffabc67
commit eff9f21
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Chiiya\FilamentAccessControl\Http\Controllers; | ||
|
||
use Exception; | ||
use Filament\Facades\Filament; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Password; | ||
use Filament\Notifications\Auth\ResetPassword as ResetPasswordNotification; | ||
use Filament\Notifications\Notification; | ||
use Illuminate\Contracts\Auth\CanResetPassword; | ||
|
||
class PasswordResetController | ||
{ | ||
public function sendResetLink(Request $request) | ||
{ | ||
// Validate the incoming request data | ||
$request->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(); | ||
} | ||
} | ||
} |
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