lasthourcloud/app/Notifications/TransactionalEmails/ResetPassword.php

75 lines
1.9 KiB
PHP
Raw Normal View History

2023-07-28 08:55:26 +00:00
<?php
namespace App\Notifications\TransactionalEmails;
use App\Models\InstanceSettings;
2023-07-28 08:55:26 +00:00
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ResetPassword extends Notification
{
public static $createUrlCallback;
2024-06-10 20:43:34 +00:00
2023-07-28 08:55:26 +00:00
public static $toMailCallback;
2024-06-10 20:43:34 +00:00
public $token;
2024-06-10 20:43:34 +00:00
public InstanceSettings $settings;
2023-07-28 08:55:26 +00:00
public function __construct($token)
{
2024-07-12 13:45:36 +00:00
$this->settings = \App\Models\InstanceSettings::get();
2023-07-28 08:55:26 +00:00
$this->token = $token;
}
public static function createUrlUsing($callback)
{
static::$createUrlCallback = $callback;
}
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
2023-07-28 08:55:26 +00:00
public function via($notifiable)
{
2023-08-31 13:00:59 +00:00
$type = set_transanctional_email_settings();
2024-07-25 20:04:05 +00:00
if (!$type) {
2023-08-31 13:00:59 +00:00
throw new \Exception('No email settings found.');
2023-07-28 08:55:26 +00:00
}
2024-06-10 20:43:34 +00:00
2023-08-31 13:00:59 +00:00
return ['mail'];
2023-07-28 08:55:26 +00:00
}
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
return $this->buildMailMessage($this->resetUrl($notifiable));
}
2023-07-28 08:55:26 +00:00
protected function buildMailMessage($url)
{
2024-07-24 12:27:21 +00:00
$mail = new MailMessage;
2024-07-25 20:04:05 +00:00
$mail->subject('Last Hour: Reset Password');
$mail->view('emails.reset-password', ['url' => $url, 'count' => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire')]);
2024-06-10 20:43:34 +00:00
2023-07-28 08:55:26 +00:00
return $mail;
}
2023-07-28 08:55:26 +00:00
protected function resetUrl($notifiable)
{
if (static::$createUrlCallback) {
return call_user_func(static::$createUrlCallback, $notifiable, $this->token);
}
return url(route('password.reset', [
'token' => $this->token,
'email' => $notifiable->getEmailForPasswordReset(),
], false));
}
}