51 lines
1.8 KiB
PHP
51 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Instance;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
/**
|
|
* Delivers the initial admin credentials once provisioning completes. Queued for
|
|
* durable delivery; the password is passed transiently and never persisted in
|
|
* plaintext.
|
|
*
|
|
* Delivery is at-least-once: a worker crash in the tiny window between sending
|
|
* and recording the `credentials_sent` breadcrumb can re-send (a duplicate
|
|
* welcome email). Exactly-once would need a transactional outbox (v1.1); a
|
|
* duplicate is preferred over locking the customer out with a lost credential.
|
|
*/
|
|
class CloudReady extends Notification implements ShouldQueue
|
|
{
|
|
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');
|
|
|
|
return (new MailMessage)
|
|
->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);
|
|
}
|
|
}
|