diff --git a/CHANGELOG.md b/CHANGELOG.md index 2172602ea..092ecbfa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * Added support for file copying through the file manager. [#127](https://github.com/Pterodactyl/Panel/issues/127) * Added support for creating new files and folders directly from the right-click dropdown menu. * Added support for setting custom `user_id` when using the API to create users. +* Support for creating a new server through the API by passing a user ID rather than an email. ### Changed * Support for sub-folders within the `getJavascript()` route for servers. diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index da8516ecf..728a7121a 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -77,7 +77,7 @@ class ServerRepository // Validate Fields $validator = Validator::make($data, [ - 'owner' => 'bail|required|email|exists:users,email', + 'owner' => 'bail|required|string', 'name' => 'required|regex:/^([\w -]{4,35})$/', 'memory' => 'required|numeric|min:0', 'swap' => 'required|numeric|min:-1', @@ -114,8 +114,15 @@ class ServerRepository throw new DisplayValidationException($validator->errors()); } - // Get the User ID; user exists since we passed the 'exists:users,email' part of the validation - $user = Models\User::select('id')->where('email', $data['owner'])->first(); + if (is_int($data['owner'])) { + $user = Models\User::select('id')->where('id', $data['owner'])->first(); + } else { + $user = Models\User::select('id')->where('email', $data['owner'])->first(); + } + + if (!$user) { + throw new DisplayValidationException('The user id or email passed to the function was not found on the system.'); + } $autoDeployed = false; if (isset($data['auto_deploy']) && in_array($data['auto_deploy'], [true, 1, "1"])) {