2023-07-28 08:55:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Notifications\TransactionalEmails;
|
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
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;
|
|
|
|
public static $toMailCallback;
|
2023-08-08 09:51:36 +00:00
|
|
|
public $token;
|
|
|
|
public InstanceSettings $settings;
|
2023-07-28 08:55:26 +00:00
|
|
|
|
|
|
|
public function __construct($token)
|
|
|
|
{
|
|
|
|
$this->settings = InstanceSettings::get();
|
|
|
|
$this->token = $token;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
if (!$type) {
|
|
|
|
throw new \Exception('No email settings found.');
|
2023-07-28 08:55:26 +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-08-08 09:51:36 +00:00
|
|
|
|
2023-07-28 08:55:26 +00:00
|
|
|
protected function buildMailMessage($url)
|
|
|
|
{
|
|
|
|
$mail = new MailMessage();
|
2023-10-10 11:10:43 +00:00
|
|
|
$mail->subject('Coolify: Reset Password');
|
2023-08-08 09:51:36 +00:00
|
|
|
$mail->view('emails.reset-password', ['url' => $url, 'count' => config('auth.passwords.' . config('auth.defaults.passwords') . '.expire')]);
|
2023-07-28 08:55:26 +00:00
|
|
|
return $mail;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
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));
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|