clrghouz/app/Notifications/AddressLink.php

104 lines
2.5 KiB
PHP

<?php
namespace App\Notifications;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Log;
use App\Classes\{ANSI,Fonts\Thin,Page};
use App\Classes\Fonts\Thick;
use App\Classes\FTN\Message;
use App\Models\{Address,Netmail,Setup,User};
class AddressLink extends Notification //implements ShouldQueue
{
private const LOGKEY = 'NAL';
use Queueable;
private Address $ao;
private User $uo;
/**
* Create a netmail to enable a sysop to activate an address.
*
* @param Address $ao
* @param User $uo
*/
public function __construct(Address $ao,User $uo)
{
$this->queue = 'netmail';
$this->ao = $ao;
$this->uo = $uo;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['netmail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return Netmail
* @throws \Exception
*/
public function toNetmail($notifiable): Netmail
{
Log::info(sprintf('%s:Sending a link code for address [%s]',self::LOGKEY,$this->ao->ftn));
$so = Setup::findOrFail(config('app.id'))->system;
$o = new Netmail;
$o->to = $this->ao->system->sysop;
$o->from = Setup::PRODUCT_NAME;
$o->subject = 'Address Link Code';
$o->datetime = Carbon::now();
$o->tzoffset = $o->datetime->utcOffset();
$o->fftn_id = $so->match($this->ao->zone)->first()->id;
$o->tftn_id = $this->ao->id;
$o->flags = Message::FLAG_LOCAL|Message::FLAG_PRIVATE|Message::FLAG_CRASH;
$o->cost = 0;
$o->tagline = 'Address Linking...';
$o->tearline = sprintf('%s (%04X)',Setup::PRODUCT_NAME,Setup::PRODUCT_ID);
// Message
$msg = new Page;
$msg->addLogo(new ANSI(base_path('public/logo/netmail.bin')));
$header = new Thick;
$header->addText(ANSI::ansi_code([1,37]).'Clearing Houz');
$msg->addHeader($header,'FTN Mailer and Tosser',TRUE,0xc4);
$lbc = new Thin;
$lbc->addText('#link');
$msg->addLeftBoxContent($lbc);
$msg->addText(sprintf(
"Hi %s,\r\r".
"This message is to link your address [%s] to your user ID in the Clearing Houz web site.\r\r".
"If you didnt start this process, then you can safely ignore this netmail. But if you wanted to link this address, please head over to [%s] and paste in the following:\r\r%s\r",
$this->ao->system->sysop,
$this->ao->ftn3d,
url('/link'),
$this->ao->set_activation($this->uo)
));
$o->msg = $msg->render();
$o->save();
return $o;
}
}