Skip to content

Commit fbfaec6

Browse files
committed
create server with user ID or email
1 parent 9d10c2a commit fbfaec6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
99
* Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127)
1010
* Added support for creating new files and folders directly from the right-click dropdown menu.
1111
* Added support for setting custom `user_id` when using the API to create users.
12+
* Support for creating a new server through the API by passing a user ID rather than an email.
1213

1314
### Changed
1415
* Support for sub-folders within the `getJavascript()` route for servers.

app/Repositories/ServerRepository.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function create(array $data)
7777

7878
// Validate Fields
7979
$validator = Validator::make($data, [
80-
'owner' => 'bail|required|email|exists:users,email',
80+
'owner' => 'bail|required|string',
8181
'name' => 'required|regex:/^([\w -]{4,35})$/',
8282
'memory' => 'required|numeric|min:0',
8383
'swap' => 'required|numeric|min:-1',
@@ -114,8 +114,15 @@ public function create(array $data)
114114
throw new DisplayValidationException($validator->errors());
115115
}
116116

117-
// Get the User ID; user exists since we passed the 'exists:users,email' part of the validation
118-
$user = Models\User::select('id')->where('email', $data['owner'])->first();
117+
if (is_int($data['owner'])) {
118+
$user = Models\User::select('id')->where('id', $data['owner'])->first();
119+
} else {
120+
$user = Models\User::select('id')->where('email', $data['owner'])->first();
121+
}
122+
123+
if (!$user) {
124+
throw new DisplayValidationException('The user id or email passed to the function was not found on the system.');
125+
}
119126

120127
$autoDeployed = false;
121128
if (isset($data['auto_deploy']) && in_array($data['auto_deploy'], [true, 1, "1"])) {

0 commit comments

Comments
 (0)