65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Instance;
|
|
use App\Services\Mail\MailboxResolver;
|
|
use App\Services\Mail\MailPurpose;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
/**
|
|
* Delivers the initial admin credentials once provisioning completes.
|
|
*
|
|
* Sent SYNCHRONOUSLY from CompleteProvisioning (not queued): the step only
|
|
* records the `credentials_sent` breadcrumb and scrubs the password AFTER the
|
|
* send returns, so a mail failure re-runs the step (password preserved) instead
|
|
* of losing the credential in a failed queue job. Delivery is at-least-once — a
|
|
* crash in the tiny window after send but before the breadcrumb can re-send a
|
|
* duplicate welcome email, which is preferable to a lost credential.
|
|
*/
|
|
class CloudReady extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public Instance $instance,
|
|
public string $adminUser,
|
|
public string $adminPasswordEncrypted, // ciphertext — safe to serialize into the queue
|
|
) {}
|
|
|
|
/** @return array<int, string> */
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['mail'];
|
|
}
|
|
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
$url = 'https://'.$this->instance->subdomain.'.'.config('provisioning.dns.zone');
|
|
|
|
$box = app(MailboxResolver::class)
|
|
->for(MailPurpose::PROVISIONING);
|
|
|
|
$message = (new MailMessage)->mailer('cp_'.MailPurpose::PROVISIONING);
|
|
|
|
if ($box !== null) {
|
|
$message->from($box->address, $box->display_name ?: null);
|
|
|
|
if (! $box->no_reply) {
|
|
$message->replyTo($box->address, $box->display_name ?: null);
|
|
}
|
|
}
|
|
|
|
return $message
|
|
->subject(__('provisioning.mail.ready_subject'))
|
|
->greeting(__('provisioning.mail.ready_greeting'))
|
|
->line(__('provisioning.mail.ready_line'))
|
|
->line(__('provisioning.mail.ready_user', ['user' => $this->adminUser]))
|
|
->line(__('provisioning.mail.ready_password', ['password' => Crypt::decryptString($this->adminPasswordEncrypted)]))
|
|
->action(__('provisioning.mail.ready_action'), $url);
|
|
}
|
|
}
|