Cleanup node routes, cleanup remote token

This commit is contained in:
Dane Everitt 2017-03-03 23:14:23 -05:00
parent 287015669a
commit d38f89a468
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 131 additions and 114 deletions

View file

@ -105,27 +105,26 @@ class RemoteController extends Controller
return response('', 201);
}
public function getConfiguration(Request $request, $tokenString)
public function getConfiguration(Request $request, $token)
{
// Try to query the token and the node from the database
try {
$token = Models\NodeConfigurationToken::where('token', $tokenString)->firstOrFail();
$node = Models\Node::findOrFail($token->node);
$model = Models\NodeConfigurationToken::with('node')->where('token', $token)->firstOrFail();
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return response()->json(['error' => 'token_invalid'], 403);
}
// Check if token is expired
if ($token->expires_at->lt(Carbon::now())) {
$token->delete();
if ($model->created_at->lt(Carbon::now())) {
$model->delete();
return response()->json(['error' => 'token_expired'], 403);
}
// Delete the token, it's one-time use
$token->delete();
$model->delete();
// Manually as getConfigurationAsJson() returns it in correct format already
return response($node->getConfigurationAsJson())->header('Content-Type', 'text/json');
return response($model->node->getConfigurationAsJson())->header('Content-Type', 'text/json');
}
}