Reimplement password reset (#1182)

* add password reset to all panels

* remove old leftovers

* fix reset url in account created mail
This commit is contained in:
Boy132 2025-03-28 23:51:42 +01:00 committed by GitHub
parent 7471347b55
commit a768fadaea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 5 additions and 49 deletions

View File

@ -31,7 +31,6 @@ use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use App\Notifications\SendPasswordReset as ResetPasswordNotification;
use ResourceBundle;
use Spatie\Permission\Traits\HasRoles;
@ -201,21 +200,6 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
return $rules;
}
/**
* Send the password reset notification.
*
* @param string $token
*/
public function sendPasswordResetNotification($token): void
{
Activity::event('auth:reset-password')
->withRequestMetadata()
->subject($this)
->log('sending password reset email');
$this->notify(new ResetPasswordNotification($token));
}
public function username(): Attribute
{
return Attribute::make(

View File

@ -3,6 +3,7 @@
namespace App\Notifications;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
@ -29,7 +30,7 @@ class AccountCreated extends Notification implements ShouldQueue
->line('Email: ' . $notifiable->email);
if (!is_null($this->token)) {
return $message->action('Setup Your Account', url('/auth/password/reset/' . $this->token . '?email=' . urlencode($notifiable->email)));
return $message->action('Setup Your Account', Filament::getResetPasswordUrl($this->token, $notifiable));
}
return $message;

View File

@ -1,31 +0,0 @@
<?php
namespace App\Notifications;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class SendPasswordReset extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(public string $token) {}
/** @return string[] */
public function via(): array
{
return ['mail'];
}
public function toMail(User $notifiable): MailMessage
{
return (new MailMessage())
->subject('Reset Password')
->line('You are receiving this email because we received a password reset request for your account.')
->action('Reset Password', url('/auth/password/reset/' . $this->token . '?email=' . urlencode($notifiable->email)))
->line('If you did not request a password reset, no further action is required.');
}
}

View File

@ -39,6 +39,7 @@ class AdminPanelProvider extends PanelProvider
->topNavigation(config('panel.filament.top-navigation', true))
->maxContentWidth(config('panel.filament.display-width', 'screen-2xl'))
->login(Login::class)
->passwordReset()
->userMenuItems([
'profile' => MenuItem::make()
->label(fn () => trans('filament-panels::pages/auth/edit-profile.label'))

View File

@ -37,6 +37,7 @@ class AppPanelProvider extends PanelProvider
->navigation(false)
->profile(EditProfile::class, false)
->login(Login::class)
->passwordReset()
->userMenuItems([
MenuItem::make()
->label('Admin')

View File

@ -42,6 +42,7 @@ class ServerPanelProvider extends PanelProvider
->topNavigation(config('panel.filament.top-navigation', true))
->maxContentWidth(config('panel.filament.display-width', 'screen-2xl'))
->login(Login::class)
->passwordReset()
->userMenuItems([
'profile' => MenuItem::make()
->label(fn () => trans('filament-panels::pages/auth/edit-profile.label'))

View File

@ -11,7 +11,6 @@ return [
'fail' => 'Failed log in',
'success' => 'Logged in',
'password-reset' => 'Password reset',
'reset-password' => 'Requested password reset',
'checkpoint' => 'Two-factor authentication requested',
'recovery-token' => 'Used two-factor recovery token',
'token' => 'Solved two-factor challenge',