|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Pterodactyl\Notifications; |
| 4 | + |
| 5 | +use Illuminate\Bus\Queueable; |
| 6 | +use Pterodactyl\Events\Event; |
| 7 | +use Illuminate\Container\Container; |
| 8 | +use Illuminate\Notifications\Notification; |
| 9 | +use Illuminate\Contracts\Queue\ShouldQueue; |
| 10 | +use Pterodactyl\Contracts\Core\ReceivesEvents; |
| 11 | +use Illuminate\Contracts\Notifications\Dispatcher; |
| 12 | +use Illuminate\Notifications\Messages\MailMessage; |
| 13 | + |
| 14 | +class ServerInstalled extends Notification implements ShouldQueue, ReceivesEvents |
| 15 | +{ |
| 16 | + use Queueable; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \Pterodactyl\Models\Server |
| 20 | + */ |
| 21 | + public $server; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var \Pterodactyl\Models\User |
| 25 | + */ |
| 26 | + public $user; |
| 27 | + |
| 28 | + /** |
| 29 | + * Handle a direct call to this notification from the server installed event. This is configured |
| 30 | + * in the event service provider. |
| 31 | + * |
| 32 | + * @param \Pterodactyl\Events\Event|\Pterodactyl\Events\Server\Installed $event |
| 33 | + */ |
| 34 | + public function handle(Event $event): void |
| 35 | + { |
| 36 | + $event->server->loadMissing('user'); |
| 37 | + |
| 38 | + $this->server = $event->server; |
| 39 | + $this->user = $event->server->user; |
| 40 | + |
| 41 | + // Since we are calling this notification directly from an event listener we need to fire off the dispatcher |
| 42 | + // to send the email now. Don't use send() or you'll end up firing off two different events. |
| 43 | + Container::getInstance()->make(Dispatcher::class)->sendNow($this->user, $this); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Get the notification's delivery channels. |
| 48 | + * |
| 49 | + * @return array |
| 50 | + */ |
| 51 | + public function via() |
| 52 | + { |
| 53 | + return ['mail']; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Get the mail representation of the notification. |
| 58 | + * |
| 59 | + * @return \Illuminate\Notifications\Messages\MailMessage |
| 60 | + */ |
| 61 | + public function toMail() |
| 62 | + { |
| 63 | + return (new MailMessage) |
| 64 | + ->greeting('Hello ' . $this->user->username . '.') |
| 65 | + ->line('Your server has finished installing and is now ready for you to use.') |
| 66 | + ->line('Server Name: ' . $this->server->name) |
| 67 | + ->action('Login and Begin Using', route('index')); |
| 68 | + } |
| 69 | +} |
0 commit comments