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