Initial validator implementation for server creation
This commit is contained in:
parent
692825e8b6
commit
d0e4592377
3 changed files with 50 additions and 9 deletions
|
@ -54,6 +54,7 @@ class ServersController extends Controller
|
||||||
|
|
||||||
public function postNewServer(Request $request)
|
public function postNewServer(Request $request)
|
||||||
{
|
{
|
||||||
|
Server::addServer($request->all());
|
||||||
return json_encode($request->all());
|
return json_encode($request->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@
|
||||||
namespace Pterodactyl\Models;
|
namespace Pterodactyl\Models;
|
||||||
|
|
||||||
use Auth;
|
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\Permission;
|
||||||
use Pterodactyl\Models\Subuser;
|
use Pterodactyl\Models\Subuser;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,16 +24,16 @@
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="server_name" class="control-label">Server Name</label>
|
<label for="name" class="control-label">Server Name</label>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" autocomplete="off" name="server_name" class="form-control" />
|
<input type="text" autocomplete="off" name="name" class="form-control" />
|
||||||
<p class="text-muted"><small><em>Character limits: <code>a-zA-Z0-9_-</code> and <code>[Space]</code> (max 35 characters)</em></small></p>
|
<p class="text-muted"><small><em>Character limits: <code>a-zA-Z0-9_-</code> and <code>[Space]</code> (max 35 characters)</em></small></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="server_name" class="control-label">Owner Email</label>
|
<label for="owner" class="control-label">Owner Email</label>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" autocomplete="off" name="owner_email" class="form-control" />
|
<input type="text" autocomplete="off" name="owner" class="form-control" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -129,7 +129,7 @@
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="service" class="control-label">Service Type</label>
|
<label for="service" class="control-label">Service Type</label>
|
||||||
<div>
|
<div>
|
||||||
<select name="node" id="getService" class="form-control">
|
<select name="service" id="getService" class="form-control">
|
||||||
<option></option>
|
<option></option>
|
||||||
@foreach($services as $service)
|
@foreach($services as $service)
|
||||||
<option value="{{ $service->id }}">{{ $service->name }}</option>
|
<option value="{{ $service->id }}">{{ $service->name }}</option>
|
||||||
|
@ -139,9 +139,9 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12 hidden">
|
<div class="form-group col-md-12 hidden">
|
||||||
<label for="service_option" class="control-label">Service Option</label>
|
<label for="option" class="control-label">Service Option</label>
|
||||||
<div>
|
<div>
|
||||||
<select name="node" id="getOption" class="form-control">
|
<select name="option" id="getOption" class="form-control">
|
||||||
<option></option>
|
<option></option>
|
||||||
</select>
|
</select>
|
||||||
<p class="text-muted"><small>Select the type of service that this server will be running.</small></p>
|
<p class="text-muted"><small>Select the type of service that this server will be running.</small></p>
|
||||||
|
@ -181,7 +181,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 text-center">
|
<div class="col-md-12 text-center">
|
||||||
{!! csrf_field() !!}
|
{!! csrf_field() !!}
|
||||||
<input type="submit" name="submit" class="btn btn-primary btn-sm" value="Create New Server" />
|
<input type="submit" class="btn btn-primary btn-sm" value="Create New Server" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -350,7 +350,7 @@ $(document).ready(function () {
|
||||||
<div class="form-group col-md-6">\
|
<div class="form-group col-md-6">\
|
||||||
<label for="var_ref_' + item.id + '" class="control-label">' + item.name + '</label> ' + isRequired + '\
|
<label for="var_ref_' + item.id + '" class="control-label">' + item.name + '</label> ' + isRequired + '\
|
||||||
<div>\
|
<div>\
|
||||||
<input type="text" autocomplete="off" name="var_ref_' + item.id + '" class="form-control" value="' + item.default_value + '" />\
|
<input type="text" autocomplete="off" name="env_' + item.env_variable + '" class="form-control" value="' + item.default_value + '" />\
|
||||||
<p class="text-muted"><small>' + item.description + '</small></p>\
|
<p class="text-muted"><small>' + item.description + '</small></p>\
|
||||||
<p class="text-muted"><small>Regex Requirements for Input: <code>' + item.regex + '</code></small></p>\
|
<p class="text-muted"><small>Regex Requirements for Input: <code>' + item.regex + '</code></small></p>\
|
||||||
</div>\
|
</div>\
|
||||||
|
|
Loading…
Reference in a new issue