diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index a5bcae5b2..e7f53fa7f 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -27,8 +27,8 @@ namespace Pterodactyl\Http\Controllers\Admin; use DB; use Log; use Alert; +use Carbon; use Validator; -use Carbon\Carbon; use Pterodactyl\Models; use Illuminate\Http\Request; use Pterodactyl\Exceptions\DisplayException; @@ -296,7 +296,6 @@ class NodesController extends Controller 'expires_at' => $token->expires_at->toDateTimeString(), ]; - return response(json_encode($token_response), 200) - ->header('Content-Type', 'application/json'); + return response()->json($token_response, 200); } } diff --git a/app/Http/Controllers/Remote/RemoteController.php b/app/Http/Controllers/Remote/RemoteController.php index b762a38b2..600e3d0d0 100644 --- a/app/Http/Controllers/Remote/RemoteController.php +++ b/app/Http/Controllers/Remote/RemoteController.php @@ -116,21 +116,20 @@ class RemoteController extends Controller $token = Models\NodeConfigurationToken::where('token', $tokenString)->firstOrFail(); $node = Models\Node::findOrFail($token->node); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { - return response(json_encode(['error' => 'token_invalid']), 403) - ->header('Content-Type', 'application/json'); + return response()->json(['error' => 'token_invalid'], 403); } // Check if token is expired if ($token->expires_at->lt(Carbon::now())) { $token->delete(); - return response(json_encode(['error' => 'token_expired']), 403) - ->header('Content-Type', 'application/json'); + return response()->json(['error' => 'token_expired'], 403); } // Delete the token, it's one-time use $token->delete(); + // Manually as getConfigurationAsJson() returns it in correct format already return response($node->getConfigurationAsJson(), 200) ->header('Content-Type', 'application/json'); } diff --git a/app/Http/Routes/AdminRoutes.php b/app/Http/Routes/AdminRoutes.php index 6a1cc8400..3b94b2aeb 100644 --- a/app/Http/Routes/AdminRoutes.php +++ b/app/Http/Routes/AdminRoutes.php @@ -288,7 +288,7 @@ class AdminRoutes ]); $router->get('/{id}/configurationtoken', [ - 'as' => 'admin.nodes.configurationtoken', + 'as' => 'admin.nodes.configuration-token', 'uses' => 'Admin\NodesController@getConfigurationToken', ]); }); diff --git a/database/migrations/2017_01_07_154228_create_node_configuration_tokens_table.php b/database/migrations/2017_01_07_154228_create_node_configuration_tokens_table.php index e86a87979..905d28a46 100644 --- a/database/migrations/2017_01_07_154228_create_node_configuration_tokens_table.php +++ b/database/migrations/2017_01_07_154228_create_node_configuration_tokens_table.php @@ -18,8 +18,7 @@ class CreateNodeConfigurationTokensTable extends Migration $table->char('token', 32); $table->timestamp('expires_at'); $table->integer('node')->unsigned(); - $table->foreign('node') - ->references('id')->on('nodes'); + $table->foreign('node')->references('id')->on('nodes'); $table->timestamps(); }); } diff --git a/resources/views/admin/nodes/view.blade.php b/resources/views/admin/nodes/view.blade.php index f4f6b6ba8..c6befed5b 100644 --- a/resources/views/admin/nodes/view.blade.php +++ b/resources/views/admin/nodes/view.blade.php @@ -502,7 +502,7 @@ $(document).ready(function () { }); $('#configTokenBtn').on('click', function (event) { - $.getJSON('{{ route('admin.nodes.configurationtoken', $node->id) }}') + $.getJSON('{{ route('admin.nodes.configuration-token', $node->id) }}') .done(function (data) { swal({ type: 'success',