RequestPasswordReset mail wip

This commit is contained in:
salam committed 2025-10-15 16:50:10 +02:00
1 parent c4685b9412
commit b73f22fec2
5 files changed
+241 -1

No files matched your search

@@ -0,0 +1,66 @@
<?php
namespace App\Filament\Pages\Auth;
use App\Notifications\ResetPasswordNotification;
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
use Exception;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use Filament\Pages\Auth\PasswordReset\RequestPasswordReset as BaseRequestPasswordReset;
use Illuminate\Contracts\Auth\CanResetPassword;
use Illuminate\Support\Facades\Password;
class RequestPasswordReset extends BaseRequestPasswordReset
{
public function request(): void
{
try {
$this->rateLimit(2);
} catch (TooManyRequestsException $exception) {
Notification::make()
->title(__('filament-panels::pages/auth/password-reset/request-password-reset.notifications.throttled.title', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]))
->body(array_key_exists('body', __('filament-panels::pages/auth/password-reset/request-password-reset.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/password-reset/request-password-reset.notifications.throttled.body', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]) : null)
->danger()
->send();
return;
}
$data = $this->form->getState();
$status = Password::broker(Filament::getAuthPasswordBroker())->sendResetLink(
$data,
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);
$user->notify($notification);
},
);
if ($status !== Password::RESET_LINK_SENT) {
Notification::make()
->title(__($status))
->danger()
->send();
return;
}
Notification::make()
->title(__($status))
->success()
->send();
$this->form->fill();
}
}
@@ -0,0 +1,56 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ResetPasswordNotification extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject(Lang::get('Benachrichtigung zum Zurücksetzen des Passworts'))
->greeting(Lang::get('Hallo')." {$notifiable->name},")
->line(Lang::get('Sie erhalten diese E-Mail, weil wir eine Anfrage zum Zurücksetzen des Passworts für Ihr Konto erhalten haben.'))
->action(Lang::get('Passwort Zurücksetzen'), $this->resetUrl($notifiable))
->line(Lang::get('Dieser Link zum Zurücksetzen des Passworts läuft in :count Minuten ab.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
->line(Lang::get('Wenn Sie keine Passwortzurücksetzung beantragt haben, sind keine weiteren Maßnahmen erforderlich.'));
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
];
}
}
+114
View File
@@ -0,0 +1,114 @@
<?php
namespace Illuminate\Auth\Notifications;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\URL;
class VerifyEmail extends Notification
{
/**
* The callback that should be used to create the verify email URL.
*
* @var \Closure|null
*/
public static $createUrlCallback;
/**
* The callback that should be used to build the mail message.
*
* @var (\Closure(mixed, string): \Illuminate\Notifications\Messages\MailMessage|\Illuminate\Contracts\Mail\Mailable)|null
*/
public static $toMailCallback;
/**
* Get the notification's channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$verificationUrl = $this->verificationUrl($notifiable);
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
}
return $this->buildMailMessage($verificationUrl);
}
/**
* Get the verify email notification mail message for the given URL.
*
* @param string $url
* @return \Illuminate\Notifications\Messages\MailMessage
*/
protected function buildMailMessage($url)
{
return (new MailMessage)
->subject(Lang::get('Verify Email Address'))
->line(Lang::get('Please click the button below to verify your email address.'))
->action(Lang::get('Verify Email Address'), $url)
->line(Lang::get('If you did not create an account, no further action is required.'));
}
/**
* Get the verification URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function verificationUrl($notifiable)
{
if (static::$createUrlCallback) {
return call_user_func(static::$createUrlCallback, $notifiable);
}
return URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
}
/**
* Set a callback that should be used when creating the email verification URL.
*
* @param \Closure $callback
* @return void
*/
public static function createUrlUsing($callback)
{
static::$createUrlCallback = $callback;
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure(mixed, string): (\Illuminate\Notifications\Messages\MailMessage|\Illuminate\Contracts\Mail\Mailable) $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
}
@@ -4,6 +4,7 @@ namespace App\Providers\Filament;
use Agencetwogether\HooksHelper\HooksHelperPlugin; use Agencetwogether\HooksHelper\HooksHelperPlugin;
use App\Filament\Pages\Auth\Register; use App\Filament\Pages\Auth\Register;
use App\Filament\Pages\Auth\RequestPasswordReset;
use App\Http\Middleware\AppUserAGBMiddleware; use App\Http\Middleware\AppUserAGBMiddleware;
use Awcodes\LightSwitch\Enums\Alignment; use Awcodes\LightSwitch\Enums\Alignment;
use Awcodes\LightSwitch\LightSwitchPlugin; use Awcodes\LightSwitch\LightSwitchPlugin;
@@ -39,7 +40,7 @@ class AdminPanelProvider extends PanelProvider
->id('admin') ->id('admin')
->path('app') ->path('app')
->login() ->login()
->passwordReset() ->passwordReset(RequestPasswordReset::class)
->emailVerification() ->emailVerification()
->emailChangeVerification() ->emailChangeVerification()
->databaseNotifications() ->databaseNotifications()
@@ -0,0 +1,3 @@
<x-filament-panels::page>
{{-- Page content --}}
</x-filament-panels::page>