Skip to content

Commit c989dd0

Browse files
committed
Send notification when server is created for user
1 parent a115c71 commit c989dd0

File tree

3 files changed

+71
-17
lines changed

3 files changed

+71
-17
lines changed

app/Notifications/AccountCreated.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct($token)
5757
*/
5858
public function via($notifiable)
5959
{
60-
return ['mail', 'database'];
60+
return ['mail'];
6161
}
6262

6363
/**
@@ -74,17 +74,4 @@ public function toMail($notifiable)
7474
->action('Setup Your Account', url('/auth/password/reset/' . $this->token . '?email=' . $notifiable->email));
7575
}
7676

77-
/**
78-
* Get the array representation of the notification.
79-
*
80-
* @param mixed $notifiable
81-
* @return array
82-
*/
83-
public function toArray($notifiable)
84-
{
85-
return [
86-
'email' => $notifiable->email,
87-
'token' => $this->token
88-
];
89-
}
9077
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Pterodactyl\Notifications;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Notifications\Notification;
7+
use Illuminate\Contracts\Queue\ShouldQueue;
8+
use Illuminate\Notifications\Messages\MailMessage;
9+
10+
class ServerCreated extends Notification implements ShouldQueue
11+
{
12+
use Queueable;
13+
14+
public $server;
15+
16+
/**
17+
* Create a new notification instance.
18+
*
19+
* @param array $server
20+
* @return void
21+
*/
22+
public function __construct(array $server)
23+
{
24+
$this->server = (object) $server;
25+
}
26+
27+
/**
28+
* Get the notification's delivery channels.
29+
*
30+
* @param mixed $notifiable
31+
* @return array
32+
*/
33+
public function via($notifiable)
34+
{
35+
return ['mail'];
36+
}
37+
38+
/**
39+
* Get the mail representation of the notification.
40+
*
41+
* @param mixed $notifiable
42+
* @return \Illuminate\Notifications\Messages\MailMessage
43+
*/
44+
public function toMail($notifiable)
45+
{
46+
return (new MailMessage)
47+
->line('A new server as been assigned to your account.')
48+
->line('Server Name: ' . $this->server->name)
49+
->line('Memory: ' . $this->server->memory . ' MB')
50+
->line('Node: ' . $this->server->node)
51+
->line('Type: ' . $this->server->service . ' - ' . $this->server->option)
52+
->action('Peel Off the Protective Wrap', route('server.index', $this->server->uuidShort))
53+
->line('Please let us know if you have any additional questions or concerns!');
54+
}
55+
56+
}

app/Repositories/ServerRepository.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Pterodactyl\Models;
3333
use Pterodactyl\Services\UuidService;
3434
use Pterodactyl\Services\DeploymentService;
35+
use Pterodactyl\Notifications\ServerCreated;
3536

3637
use Pterodactyl\Exceptions\DisplayException;
3738
use Pterodactyl\Exceptions\AccountNotFoundException;
@@ -113,9 +114,9 @@ public function create(array $data)
113114
}
114115

115116
if (is_int($data['owner'])) {
116-
$user = Models\User::select('id')->where('id', $data['owner'])->first();
117+
$user = Models\User::select('id', 'email')->where('id', $data['owner'])->first();
117118
} else {
118-
$user = Models\User::select('id')->where('email', $data['owner'])->first();
119+
$user = Models\User::select('id', 'email')->where('email', $data['owner'])->first();
119120
}
120121

121122
if (!$user) {
@@ -229,7 +230,7 @@ public function create(array $data)
229230
// Add Server to the Database
230231
$server = new Models\Server;
231232
$genUuid = $uuid->generate('servers', 'uuid');
232-
$genShortUuid = $uuid->generateShort('servers', 'uuidShort', $generatedUuid);
233+
$genShortUuid = $uuid->generateShort('servers', 'uuidShort', $genUuid);
233234
$server->fill([
234235
'uuid' => $genUuid,
235236
'uuidShort' => $genShortUuid,
@@ -274,6 +275,16 @@ public function create(array $data)
274275
]);
275276
}
276277

278+
// Queue Notification Email
279+
$user->notify((new ServerCreated([
280+
'name' => $server->name,
281+
'memory' => $server->memory,
282+
'node' => $node->name,
283+
'service' => $service->name,
284+
'option' => $option->name,
285+
'uuidShort' => $server->uuidShort
286+
])));
287+
277288
$client = Models\Node::guzzleRequest($node->id);
278289
$client->request('POST', '/servers', [
279290
'headers' => [

0 commit comments

Comments
 (0)