replace manual json headers with laravel response()->json()

better Carbon dependency
rename admin.nodes.configuration-token route
style fixes
This commit is contained in:
Jakob Schrettenbrunner 2017-01-08 15:21:02 +01:00
parent 67bb8fe230
commit 9f2ca17ea4
5 changed files with 8 additions and 11 deletions

View file

@ -27,8 +27,8 @@ namespace Pterodactyl\Http\Controllers\Admin;
use DB; use DB;
use Log; use Log;
use Alert; use Alert;
use Carbon;
use Validator; use Validator;
use Carbon\Carbon;
use Pterodactyl\Models; use Pterodactyl\Models;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Pterodactyl\Exceptions\DisplayException; use Pterodactyl\Exceptions\DisplayException;
@ -296,7 +296,6 @@ class NodesController extends Controller
'expires_at' => $token->expires_at->toDateTimeString(), 'expires_at' => $token->expires_at->toDateTimeString(),
]; ];
return response(json_encode($token_response), 200) return response()->json($token_response, 200);
->header('Content-Type', 'application/json');
} }
} }

View file

@ -116,21 +116,20 @@ class RemoteController extends Controller
$token = Models\NodeConfigurationToken::where('token', $tokenString)->firstOrFail(); $token = Models\NodeConfigurationToken::where('token', $tokenString)->firstOrFail();
$node = Models\Node::findOrFail($token->node); $node = Models\Node::findOrFail($token->node);
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return response(json_encode(['error' => 'token_invalid']), 403) return response()->json(['error' => 'token_invalid'], 403);
->header('Content-Type', 'application/json');
} }
// Check if token is expired // Check if token is expired
if ($token->expires_at->lt(Carbon::now())) { if ($token->expires_at->lt(Carbon::now())) {
$token->delete(); $token->delete();
return response(json_encode(['error' => 'token_expired']), 403) return response()->json(['error' => 'token_expired'], 403);
->header('Content-Type', 'application/json');
} }
// Delete the token, it's one-time use // Delete the token, it's one-time use
$token->delete(); $token->delete();
// Manually as getConfigurationAsJson() returns it in correct format already
return response($node->getConfigurationAsJson(), 200) return response($node->getConfigurationAsJson(), 200)
->header('Content-Type', 'application/json'); ->header('Content-Type', 'application/json');
} }

View file

@ -288,7 +288,7 @@ class AdminRoutes
]); ]);
$router->get('/{id}/configurationtoken', [ $router->get('/{id}/configurationtoken', [
'as' => 'admin.nodes.configurationtoken', 'as' => 'admin.nodes.configuration-token',
'uses' => 'Admin\NodesController@getConfigurationToken', 'uses' => 'Admin\NodesController@getConfigurationToken',
]); ]);
}); });

View file

@ -18,8 +18,7 @@ class CreateNodeConfigurationTokensTable extends Migration
$table->char('token', 32); $table->char('token', 32);
$table->timestamp('expires_at'); $table->timestamp('expires_at');
$table->integer('node')->unsigned(); $table->integer('node')->unsigned();
$table->foreign('node') $table->foreign('node')->references('id')->on('nodes');
->references('id')->on('nodes');
$table->timestamps(); $table->timestamps();
}); });
} }

View file

@ -502,7 +502,7 @@ $(document).ready(function () {
}); });
$('#configTokenBtn').on('click', function (event) { $('#configTokenBtn').on('click', function (event) {
$.getJSON('{{ route('admin.nodes.configurationtoken', $node->id) }}') $.getJSON('{{ route('admin.nodes.configuration-token', $node->id) }}')
.done(function (data) { .done(function (data) {
swal({ swal({
type: 'success', type: 'success',