diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index dafab153e..443244148 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -54,6 +54,7 @@ class ServersController extends Controller public function postNewServer(Request $request) { + Server::addServer($request->all()); return json_encode($request->all()); } diff --git a/app/Models/Server.php b/app/Models/Server.php index 2ef4c38ca..fa59c50fb 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -3,6 +3,12 @@ namespace Pterodactyl\Models; use Auth; +use Validator; +use Debugbar; + +use Pterodactyl\Exceptions\DisplayException; +use Pterodactyl\Exceptions\AccountNotFoundException; +use Pterodactyl\Models\User; use Pterodactyl\Models\Permission; use Pterodactyl\Models\Subuser; use Illuminate\Database\Eloquent\Model; @@ -138,4 +144,38 @@ class Server extends Model } + /** + * Adds a new server to the system. + * @param array $data An array of data descriptors for creating the server. These should align to the columns in the database. + */ + public static function addServer(array $data) + { + + // Validate Fields + $validator = Validator::make($data, [ + 'owner' => 'required|email|exists:users,email', + 'node' => 'required|numeric|min:1', + 'name' => 'required|regex:([\w -]{4,35})', + 'memory' => 'required|numeric|min:1', + 'disk' => 'required|numeric|min:1', + 'cpu' => 'required|numeric|min:0', + 'io' => 'required|numeric|min:10|max:1000', + 'ip' => 'required|ip', + 'port' => 'required|numeric|min:1|max:65535', + 'service' => 'required|numeric|min:1|exists:services,id', + 'option' => 'required|numeric|min:1|exists:service_options,id', + 'custom_image_name' => 'required_if:use_custom_image,on', + ]); + + // @TODO: Have this return a JSON response. + if ($validator->fails()) { + foreach($validator->errors()->all() as $error) { + Debugbar::info($error); + } + } + + return; + + } + } diff --git a/resources/views/admin/servers/new.blade.php b/resources/views/admin/servers/new.blade.php index 0669364b3..2e48a838d 100644 --- a/resources/views/admin/servers/new.blade.php +++ b/resources/views/admin/servers/new.blade.php @@ -24,16 +24,16 @@
Character limits: a-zA-Z0-9_-
and [Space]
(max 35 characters)