Very rough go at getting API back into operational state.

Not spending a lot of time on this as its a pre-release and I have
plans to overhaul the API to actually work and be easy to maintain.
This commit is contained in:
Dane Everitt 2017-03-19 13:20:33 -04:00
parent 4e916cbf08
commit 5e27772fef
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
7 changed files with 189 additions and 333 deletions

View File

@ -27,26 +27,15 @@ namespace Pterodactyl\Http\Controllers\API;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\Location; use Pterodactyl\Models\Location;
/**
* @Resource("Servers")
*/
class LocationController extends BaseController class LocationController extends BaseController
{ {
public function __construct()
{
//
}
/** /**
* List All Locations.
*
* Lists all locations currently on the system. * Lists all locations currently on the system.
* *
* @Get("/locations") * @param Request $request
* @Versions({"v1"}) * @return array
* @Response(200)
*/ */
public function lists(Request $request) public function index(Request $request)
{ {
return Location::with('nodes')->get()->map(function ($item) { return Location::with('nodes')->get()->map(function ($item) {
$item->nodes->transform(function ($item) { $item->nodes->transform(function ($item) {

View File

@ -25,8 +25,9 @@
namespace Pterodactyl\Http\Controllers\API; namespace Pterodactyl\Http\Controllers\API;
use Log; use Log;
use Pterodactyl\Models;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Allocation;
use Dingo\Api\Exception\ResourceException; use Dingo\Api\Exception\ResourceException;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\NodeRepository; use Pterodactyl\Repositories\NodeRepository;
@ -35,106 +36,66 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
/**
* @Resource("Servers")
*/
class NodeController extends BaseController class NodeController extends BaseController
{ {
public function __construct()
{
//
}
/** /**
* List All Nodes.
*
* Lists all nodes currently on the system. * Lists all nodes currently on the system.
* *
* @Get("/nodes/{?page}") * @param Request $request
* @Versions({"v1"}) * @return array
* @Parameters({
* @Parameter("page", type="integer", description="The page of results to view.", default=1)
* })
* @Response(200)
*/ */
public function lists(Request $request) public function index(Request $request)
{ {
return Models\Node::all()->toArray(); return Node::all()->toArray();
} }
/** /**
* Create a New Node. * Create a new node.
* *
* @Post("/nodes") * @param Request $request
* @Versions({"v1"}) * @return array
* @Transaction({ *
* @Request({ * @throws \Pterodactyl\Exceptions\DisplayException
* 'name' => 'My API Node', * @throws \Pterodactyl\Exceptions\DisplayValidationException
* 'location' => 1,
* 'public' => 1,
* 'fqdn' => 'daemon.wuzzle.woo',
* 'scheme' => 'https',
* 'memory' => 10240,
* 'memory_overallocate' => 100,
* 'disk' => 204800,
* 'disk_overallocate' => -1,
* 'daemonBase' => '/srv/daemon-data',
* 'daemonSFTP' => 2022,
* 'daemonListen' => 8080
* }, headers={"Authorization": "Bearer <jwt-token>"}),
* @Response(200),
* @Response(422, body={
* "message": "A validation error occured.",
* "errors": {},
* "status_code": 422
* }),
* @Response(503, body={
* "message": "There was an error while attempting to add this node to the system.",
* "status_code": 503
* })
* })
*/ */
public function create(Request $request) public function create(Request $request)
{ {
try { $repo = new NodeRepository;
$repo = new NodeRepository;
$node = $repo->create($request->only([
'name', 'location_id', 'public', 'fqdn',
'scheme', 'memory', 'memory_overallocate',
'disk', 'disk_overallocate', 'daemonBase',
'daemonSFTP', 'daemonListen',
]));
return ['id' => $repo->id]; try {
$node = $repo->create(array_merge(
$request->only([
'public', 'disk_overallocate', 'memory_overallocate',
]),
$request->intersect([
'name', 'location_id', 'fqdn',
'scheme', 'memory', 'disk',
'daemonBase', 'daemonSFTP', 'daemonListen',
])
));
return ['id' => $node->id];
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
throw new ResourceException($ex->getMessage()); throw new ResourceException($ex->getMessage());
} catch (\Exception $ex) { } catch (\Exception $ex) {
Log::error($ex); Log::error($ex);
throw new BadRequestHttpException('There was an error while attempting to add this node to the system.'); throw new BadRequestHttpException('There was an error while attempting to add this node to the system. This error has been logged.');
} }
} }
/** /**
* List Specific Node.
*
* Lists specific fields about a server or all fields pertaining to that node. * Lists specific fields about a server or all fields pertaining to that node.
* *
* @Get("/nodes/{id}/{?fields}") * @param Request $request
* @Versions({"v1"}) * @param int $id
* @Parameters({ * @param string $fields
* @Parameter("id", type="integer", required=true, description="The ID of the node to get information on."), * @return array
* @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.")
* })
* @Response(200)
*/ */
public function view(Request $request, $id, $fields = null) public function view(Request $request, $id, $fields = null)
{ {
$node = Models\Node::with('allocations')->where('id', $id)->first(); $node = Node::with('allocations')->findOrFail($id);
if (! $node) {
throw new NotFoundHttpException('No node by that ID was found.');
}
$node->allocations->transform(function ($item) { $node->allocations->transform(function ($item) {
return collect($item)->only([ return collect($item)->only([
@ -142,69 +103,64 @@ class NodeController extends BaseController
]); ]);
}); });
if (! is_null($request->input('fields'))) { if (! empty($request->input('fields'))) {
$fields = explode(',', $request->input('fields')); $fields = explode(',', $request->input('fields'));
if (! empty($fields) && is_array($fields)) { if (! empty($fields) && is_array($fields)) {
return collect($node)->only($fields); return collect($node)->only($fields);
} }
} }
return $node; return $node->toArray();
} }
/**
* Returns a configuration file for a given node.
*
* @param Request $request
* @param int $id
* @return array
*/
public function config(Request $request, $id) public function config(Request $request, $id)
{ {
$node = Models\Node::where('id', $id)->first(); $node = Node::findOrFail($id);
if (! $node) {
throw new NotFoundHttpException('No node by that ID was found.');
}
return $node->getConfigurationAsJson(); return $node->getConfigurationAsJson();
} }
/** /**
* List all Node Allocations.
*
* Returns a listing of all allocations for every node. * Returns a listing of all allocations for every node.
* *
* @Get("/nodes/allocations") * @param Request $request
* @Versions({"v1"}) * @return array
* @Response(200)
*/ */
public function allocations(Request $request) public function allocations(Request $request)
{ {
return Models\Allocation::all()->toArray(); return Allocation::all()->toArray();
} }
/** /**
* List Node Allocation based on assigned to ID.
*
* Returns a listing of the allocation for the specified server id. * Returns a listing of the allocation for the specified server id.
* *
* @Get("/nodes/allocations/{id}") * @param Request $request
* @Versions({"v1"}) * @return array
* @Response(200)
*/ */
public function allocationsView(Request $request, $id) public function allocationsView(Request $request, $id)
{ {
return Models\Allocation::where('server_id', $id)->get()->toArray(); return Allocation::where('server_id', $id)->get()->toArray();
} }
/** /**
* Delete Node. * Delete a node.
* *
* @Delete("/nodes/{id}") * @param Request $request
* @Versions({"v1"}) * @param int $id
* @Parameters({ * @return void
* @Parameter("id", type="integer", required=true, description="The ID of the node."),
* })
* @Response(204)
*/ */
public function delete(Request $request, $id) public function delete(Request $request, $id)
{ {
$repo = new NodeRepository;
try { try {
$node = new NodeRepository; $repo->delete($id);
$node->delete($id);
return $this->response->noContent(); return $this->response->noContent();
} catch (DisplayException $ex) { } catch (DisplayException $ex) {

View File

@ -25,8 +25,8 @@
namespace Pterodactyl\Http\Controllers\API; namespace Pterodactyl\Http\Controllers\API;
use Log; use Log;
use Pterodactyl\Models;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
use Dingo\Api\Exception\ResourceException; use Dingo\Api\Exception\ResourceException;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\ServerRepository; use Pterodactyl\Repositories\ServerRepository;
@ -35,44 +35,30 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
/**
* @Resource("Servers")
*/
class ServerController extends BaseController class ServerController extends BaseController
{ {
public function __construct()
{
//
}
/** /**
* List All Servers.
*
* Lists all servers currently on the system. * Lists all servers currently on the system.
* *
* @Get("/servers/{?page}") * @param Request $request
* @Versions({"v1"}) * @return array
* @Parameters({
* @Parameter("page", type="integer", description="The page of results to view.", default=1)
* })
* @Response(200)
*/ */
public function lists(Request $request) public function index(Request $request)
{ {
return Models\Server::all()->toArray(); return Server::all()->toArray();
} }
/** /**
* Create Server. * Create Server.
* *
* @Post("/servers") * @param Request $request
* @Versions({"v1"}) * @return array
* @Response(201)
*/ */
public function create(Request $request) public function create(Request $request)
{ {
$repo = new ServerRepository;
try { try {
$repo = new ServerRepository;
$server = $repo->create($request->all()); $server = $repo->create($request->all());
return ['id' => $server->id]; return ['id' => $server->id];
@ -89,22 +75,13 @@ class ServerController extends BaseController
/** /**
* List Specific Server. * List Specific Server.
* *
* Lists specific fields about a server or all fields pertaining to that server. * @param Request $request
* * @param int $id
* @Get("/servers/{id}{?fields}") * @return array
* @Versions({"v1"})
* @Parameters({
* @Parameter("id", type="integer", required=true, description="The ID of the server to get information on."),
* @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.")
* })
* @Response(200)
*/ */
public function view(Request $request, $id) public function view(Request $request, $id)
{ {
$server = Models\Server::with('node', 'allocations', 'pack')->where('id', $id)->first(); $server = Server::with('node', 'allocations', 'pack')->where('id', $id)->firstOrFail();
if (! $server) {
throw new NotFoundHttpException('No server by that ID was found.');
}
if (! is_null($request->input('fields'))) { if (! is_null($request->input('fields'))) {
$fields = explode(',', $request->input('fields')); $fields = explode(',', $request->input('fields'));
@ -138,32 +115,20 @@ class ServerController extends BaseController
/** /**
* Update Server configuration. * Update Server configuration.
* *
* Updates display information on panel. * @param Request $request
* * @param int $id
* @Patch("/servers/{id}/config") * @return array
* @Versions({"v1"})
* @Transaction({
* @Request({
* "owner": "new@email.com",
* "name": "New Name",
* "reset_token": true
* }, headers={"Authorization": "Bearer <token>"}),
* @Response(200, body={"name": "New Name"}),
* @Response(422)
* })
* @Parameters({
* @Parameter("id", type="integer", required=true, description="The ID of the server to modify.")
* })
*/ */
public function config(Request $request, $id) public function config(Request $request, $id)
{ {
$repo = new ServerRepository;
try { try {
$server = new ServerRepository; $server = $repo->updateDetails($id, $request->intersect([
$server->updateDetails($id, $request->only([ 'owner_id', 'name', 'reset_token',
'owner', 'name', 'reset_token',
])); ]));
return Models\Server::findOrFail($id); return ['id' => $id];
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
@ -176,42 +141,21 @@ class ServerController extends BaseController
/** /**
* Update Server Build Configuration. * Update Server Build Configuration.
* *
* Updates server build information on panel and on node. * @param Request $request
* * @param int $id
* @Patch("/servers/{id}/build") * @return array
* @Versions({"v1"})
* @Transaction({
* @Request({
* "default": "192.168.0.1:25565",
* "add_additional": [
* "192.168.0.1:25566",
* "192.168.0.1:25567",
* "192.168.0.1:25568"
* ],
* "remove_additional": [],
* "memory": 1024,
* "swap": 0,
* "io": 500,
* "cpu": 0,
* "disk": 1024
* }, headers={"Authorization": "Bearer <token>"}),
* @Response(200, body={"name": "New Name"}),
* @Response(422)
* })
* @Parameters({
* @Parameter("id", type="integer", required=true, description="The ID of the server to modify.")
* })
*/ */
public function build(Request $request, $id) public function build(Request $request, $id)
{ {
$repo = new ServerRepository;
try { try {
$server = new ServerRepository; $server = $repo->changeBuild($id, $request->intersect([
$server->changeBuild($id, $request->only([ 'allocation_id', 'add_allocations', 'remove_allocations',
'default', 'add_additional', 'remove_additional', 'memory', 'swap', 'io', 'cpu',
'memory', 'swap', 'io', 'cpu', 'disk',
])); ]));
return Models\Server::findOrFail($id); return ['id' => $id];
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
@ -224,18 +168,15 @@ class ServerController extends BaseController
/** /**
* Suspend Server. * Suspend Server.
* *
* @Post("/servers/{id}/suspend") * @param Request $request
* @Versions({"v1"}) * @param int $id
* @Parameters({ * @return void
* @Parameter("id", type="integer", required=true, description="The ID of the server."),
* })
* @Response(204)
*/ */
public function suspend(Request $request, $id) public function suspend(Request $request, $id)
{ {
try { try {
$server = new ServerRepository; $repo = new ServerRepository;
$server->suspend($id); $repo->suspend($id);
return $this->response->noContent(); return $this->response->noContent();
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
@ -248,18 +189,15 @@ class ServerController extends BaseController
/** /**
* Unsuspend Server. * Unsuspend Server.
* *
* @Post("/servers/{id}/unsuspend") * @param Request $request
* @Versions({"v1"}) * @param int $id
* @Parameters({ * @return void
* @Parameter("id", type="integer", required=true, description="The ID of the server."),
* })
* @Response(204)
*/ */
public function unsuspend(Request $request, $id) public function unsuspend(Request $request, $id)
{ {
try { try {
$server = new ServerRepository; $repo = new ServerRepository;
$server->unsuspend($id); $repo->unsuspend($id);
return $this->response->noContent(); return $this->response->noContent();
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
@ -272,19 +210,17 @@ class ServerController extends BaseController
/** /**
* Delete Server. * Delete Server.
* *
* @Delete("/servers/{id}/{force}") * @param Request $request
* @Versions({"v1"}) * @param int $id
* @Parameters({ * @param string|null $force
* @Parameter("id", type="integer", required=true, description="The ID of the server."), * @return void
* @Parameter("force", type="string", required=false, description="Use 'force' if the server should be removed regardless of daemon response."),
* })
* @Response(204)
*/ */
public function delete(Request $request, $id, $force = null) public function delete(Request $request, $id, $force = null)
{ {
$repo = new ServerRepository;
try { try {
$server = new ServerRepository; $repo->deleteServer($id, $force);
$server->deleteServer($id, $force);
return $this->response->noContent(); return $this->response->noContent();
} catch (DisplayException $ex) { } catch (DisplayException $ex) {

View File

@ -24,31 +24,20 @@
namespace Pterodactyl\Http\Controllers\API; namespace Pterodactyl\Http\Controllers\API;
use Pterodactyl\Models;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\Service;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @Resource("Services")
*/
class ServiceController extends BaseController class ServiceController extends BaseController
{ {
public function __construct() public function index(Request $request)
{ {
// return Service::all()->toArray();
}
public function lists(Request $request)
{
return Models\Service::all()->toArray();
} }
public function view(Request $request, $id) public function view(Request $request, $id)
{ {
$service = Models\Service::with('options.variables', 'options.packs')->find($id); $service = Service::with('options.variables', 'options.packs')->findOrFail($id);
if (! $service) {
throw new NotFoundHttpException('No service by that ID was found.');
}
return $service->toArray(); return $service->toArray();
} }

View File

@ -25,15 +25,15 @@
namespace Pterodactyl\Http\Controllers\API\User; namespace Pterodactyl\Http\Controllers\API\User;
use Log; use Log;
use Pterodactyl\Models;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\Server;
use Pterodactyl\Http\Controllers\API\BaseController; use Pterodactyl\Http\Controllers\API\BaseController;
class ServerController extends BaseController class ServerController extends BaseController
{ {
public function info(Request $request, $uuid) public function info(Request $request, $uuid)
{ {
$server = Models\Server::byUuid($uuid)->load('allocations'); $server = Server::byUuid($uuid)->load('allocations');
try { try {
$response = $server->guzzleClient()->request('GET', '/server'); $response = $server->guzzleClient()->request('GET', '/server');
@ -82,8 +82,14 @@ class ServerController extends BaseController
public function power(Request $request, $uuid) public function power(Request $request, $uuid)
{ {
$server = Models\Server::byUuid($uuid); $server = Server::byUuid($uuid);
Auth::user()->can('power-' . $request->input('action'), $server); $request->user()->can('power-' . $request->input('action'), $server);
if (empty($request->input('action'))) {
return $this->response()->error([
'error' => 'An action must be passed to this request.',
], 422);
}
$res = $server->guzzleClient()->request('PUT', '/server/power', [ $res = $server->guzzleClient()->request('PUT', '/server/power', [
'exceptions' => false, 'exceptions' => false,
@ -98,4 +104,29 @@ class ServerController extends BaseController
return $this->response->noContent(); return $this->response->noContent();
} }
public function command(Request $request, $uuid)
{
$server = Server::byUuid($uuid);
$request->user()->can('send-command', $server);
if (empty($request->input('command'))) {
return $this->response()->error([
'error' => 'A command must be passed to this request.',
], 422);
}
$res = $server->guzzleClient()->request('POST', '/server/command', [
'exceptions' => false,
'json' => [
'command' => $request->input('command'),
],
]);
if ($res->getStatusCode() !== 204) {
return $this->response->error(json_decode($res->getBody())->error, $res->getStatusCode());
}
return $this->response->noContent();
}
} }

View File

@ -24,8 +24,8 @@
namespace Pterodactyl\Http\Controllers\API; namespace Pterodactyl\Http\Controllers\API;
use Pterodactyl\Models;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Models\User;
use Dingo\Api\Exception\ResourceException; use Dingo\Api\Exception\ResourceException;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
use Pterodactyl\Repositories\UserRepository; use Pterodactyl\Repositories\UserRepository;
@ -33,51 +33,29 @@ use Pterodactyl\Exceptions\DisplayValidationException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
/**
* @Resource("Users")
*/
class UserController extends BaseController class UserController extends BaseController
{ {
public function __construct()
{
}
/** /**
* List All Users.
*
* Lists all users currently on the system. * Lists all users currently on the system.
* *
* @Get("/users/{?page}") * @param Request $request
* @Versions({"v1"}) * @return array
* @Parameters({
* @Parameter("page", type="integer", description="The page of results to view.", default=1)
* })
* @Response(200)
*/ */
public function lists(Request $request) public function index(Request $request)
{ {
return Models\User::all()->toArray(); return User::all()->toArray();
} }
/** /**
* List Specific User.
*
* Lists specific fields about a user or all fields pertaining to that user. * Lists specific fields about a user or all fields pertaining to that user.
* *
* @Get("/users/{id}/{fields}") * @param Request $request
* @Versions({"v1"}) * @param int $id
* @Parameters({ * @return array
* @Parameter("id", type="integer", required=true, description="The ID of the user to get information on."),
* @Parameter("fields", type="string", required=false, description="A comma delimidated list of fields to include.")
* })
* @Response(200)
*/ */
public function view(Request $request, $id) public function view(Request $request, $id)
{ {
$user = Models\User::with('servers')->where((is_numeric($id) ? 'id' : 'email'), $id)->first(); $user = User::with('servers')->where((is_numeric($id) ? 'id' : 'email'), $id)->firstOrFail();
if (! $user->first()) {
throw new NotFoundHttpException('No user by that ID was found.');
}
$user->servers->transform(function ($item) { $user->servers->transform(function ($item) {
return collect($item)->only([ return collect($item)->only([
@ -100,31 +78,20 @@ class UserController extends BaseController
/** /**
* Create a New User. * Create a New User.
* *
* @Post("/users") * @param Request $request
* @Versions({"v1"}) * @return array
* @Transaction({
* @Request({
* "email": "foo@example.com",
* "password": "foopassword",
* "admin": false,
* "custom_id": 123
* }, headers={"Authorization": "Bearer <token>"}),
* @Response(201),
* @Response(422)
* })
*/ */
public function create(Request $request) public function create(Request $request)
{ {
try { $repo = new UserRepository;
$user = new UserRepository;
$create = $user->create($request->only([
'email', 'username', 'name_first',
'name_last', 'password',
'root_admin', 'custom_id',
]));
$create = $user->create($request->input('email'), $request->input('password'), $request->input('admin'), $request->input('custom_id'));
return ['id' => $create]; try {
$user = $user->create($request->only([
'email', 'password', 'name_first',
'name_last', 'username', 'root_admin',
]));
return ['id' => $user->id];
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
@ -137,32 +104,21 @@ class UserController extends BaseController
/** /**
* Update an Existing User. * Update an Existing User.
* *
* The data sent in the request will be used to update the existing user on the system. * @param Request $request
* * @param int $id
* @Patch("/users/{id}") * @return array
* @Versions({"v1"})
* @Transaction({
* @Request({
* "email": "new@email.com"
* }, headers={"Authorization": "Bearer <token>"}),
* @Response(200, body={"email": "new@email.com"}),
* @Response(422)
* })
* @Parameters({
* @Parameter("id", type="integer", required=true, description="The ID of the user to modify.")
* })
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$repo = new UserRepository;
try { try {
$user = new UserRepository; $user = $repo->update($id, $request->only([
$user->update($id, $request->only([ 'email', 'password', 'name_first',
'username', 'email', 'name_first', 'name_last', 'username', 'root_admin',
'name_last', 'password',
'root_admin', 'language',
])); ]));
return Models\User::findOrFail($id); return ['id' => $id];
} catch (DisplayValidationException $ex) { } catch (DisplayValidationException $ex) {
throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true));
} catch (DisplayException $ex) { } catch (DisplayException $ex) {
@ -175,22 +131,16 @@ class UserController extends BaseController
/** /**
* Delete a User. * Delete a User.
* *
* @Delete("/users/{id}") * @param Request $request
* @Versions({"v1"}) * @param int $id
* @Transaction({ * @return void
* @Request(headers={"Authorization": "Bearer <token>"}),
* @Response(204),
* @Response(422)
* })
* @Parameters({
* @Parameter("id", type="integer", required=true, description="The ID of the user to delete.")
* })
*/ */
public function delete(Request $request, $id) public function delete(Request $request, $id)
{ {
$repo = new UserRepository;
try { try {
$user = new UserRepository; $repo->delete($id);
$user->delete($id);
return $this->response->noContent(); return $this->response->noContent();
} catch (DisplayException $ex) { } catch (DisplayException $ex) {

View File

@ -42,10 +42,15 @@ class APIRoutes
'uses' => 'Pterodactyl\Http\Controllers\API\User\ServerController@info', 'uses' => 'Pterodactyl\Http\Controllers\API\User\ServerController@info',
]); ]);
$api->put('/server/{uuid}', [ $api->post('/server/{uuid}/power', [
'as' => 'api.user.server.power', 'as' => 'api.user.server.power',
'uses' => 'Pterodactyl\Http\Controllers\API\User\ServerController@power', 'uses' => 'Pterodactyl\Http\Controllers\API\User\ServerController@power',
]); ]);
$api->post('/server/{uuid}/command', [
'as' => 'api.user.server.command',
'uses' => 'Pterodactyl\Http\Controllers\API\User\ServerController@command',
]);
}); });
$api->version('v1', ['prefix' => 'api', 'middleware' => 'api.auth'], function ($api) { $api->version('v1', ['prefix' => 'api', 'middleware' => 'api.auth'], function ($api) {
@ -55,7 +60,7 @@ class APIRoutes
*/ */
$api->get('users', [ $api->get('users', [
'as' => 'api.admin.users.list', 'as' => 'api.admin.users.list',
'uses' => 'Pterodactyl\Http\Controllers\API\UserController@lists', 'uses' => 'Pterodactyl\Http\Controllers\API\UserController@index',
]); ]);
$api->post('users', [ $api->post('users', [
@ -83,7 +88,7 @@ class APIRoutes
*/ */
$api->get('servers', [ $api->get('servers', [
'as' => 'api.admin.servers.list', 'as' => 'api.admin.servers.list',
'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@lists', 'uses' => 'Pterodactyl\Http\Controllers\API\ServerController@index',
]); ]);
$api->post('servers', [ $api->post('servers', [
@ -126,7 +131,7 @@ class APIRoutes
*/ */
$api->get('nodes', [ $api->get('nodes', [
'as' => 'api.admin.nodes.list', 'as' => 'api.admin.nodes.list',
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@lists', 'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@index',
]); ]);
$api->post('nodes', [ $api->post('nodes', [
@ -150,7 +155,7 @@ class APIRoutes
]); ]);
$api->get('nodes/{id}/config', [ $api->get('nodes/{id}/config', [
'as' => 'api.admin.nodes.view', 'as' => 'api.admin.nodes.view.config',
'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@config', 'uses' => 'Pterodactyl\Http\Controllers\API\NodeController@config',
]); ]);
@ -164,7 +169,7 @@ class APIRoutes
*/ */
$api->get('locations', [ $api->get('locations', [
'as' => 'api.admin.locations.list', 'as' => 'api.admin.locations.list',
'uses' => 'Pterodactyl\Http\Controllers\API\LocationController@lists', 'uses' => 'Pterodactyl\Http\Controllers\API\LocationController@index',
]); ]);
/* /*
@ -172,7 +177,7 @@ class APIRoutes
*/ */
$api->get('services', [ $api->get('services', [
'as' => 'api.admin.services.list', 'as' => 'api.admin.services.list',
'uses' => 'Pterodactyl\Http\Controllers\API\ServiceController@lists', 'uses' => 'Pterodactyl\Http\Controllers\API\ServiceController@index',
]); ]);
$api->get('services/{id}', [ $api->get('services/{id}', [