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

@ -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');
}