Cleanup node routes, cleanup remote token
This commit is contained in:
parent
287015669a
commit
d38f89a468
6 changed files with 131 additions and 114 deletions
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue