
- fix(email): transactional emails are all not sent if `Use system wide (transactional) email settings` is disabled and no other email provide is setup on the Notifications page - fix(email): no emails are sent if SMTP username and SMTP password are empty (which is the case in dev for example) - fix(email): Wrong test email notification is used, causing the transactional email test notification to fail if no email provider is set up on the Notifications page.
77 lines
1.9 KiB
PHP
77 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications\TransactionalEmails;
|
|
|
|
use App\Models\InstanceSettings;
|
|
use Exception;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class ResetPassword extends Notification
|
|
{
|
|
public static $createUrlCallback;
|
|
|
|
public static $toMailCallback;
|
|
|
|
public $token;
|
|
|
|
public InstanceSettings $settings;
|
|
|
|
public function __construct($token, public bool $isTransactionalEmail)
|
|
{
|
|
$this->settings = instanceSettings();
|
|
$this->token = $token;
|
|
$this->isTransactionalEmail = true;
|
|
}
|
|
|
|
public static function createUrlUsing($callback)
|
|
{
|
|
static::$createUrlCallback = $callback;
|
|
}
|
|
|
|
public static function toMailUsing($callback)
|
|
{
|
|
static::$toMailCallback = $callback;
|
|
}
|
|
|
|
public function via($notifiable)
|
|
{
|
|
$type = set_transanctional_email_settings();
|
|
if (blank($type)) {
|
|
throw new Exception('No email settings found.');
|
|
}
|
|
|
|
return ['mail'];
|
|
}
|
|
|
|
public function toMail($notifiable)
|
|
{
|
|
if (static::$toMailCallback) {
|
|
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
|
|
}
|
|
|
|
return $this->buildMailMessage($this->resetUrl($notifiable));
|
|
}
|
|
|
|
protected function buildMailMessage($url)
|
|
{
|
|
$mail = new MailMessage;
|
|
$mail->subject('Coolify: Reset Password');
|
|
$mail->view('emails.reset-password', ['url' => $url, 'count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]);
|
|
|
|
return $mail;
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|