Пример #1
0
    if ($token) {
        $db = new dbHandler();
        if ($db->isValidToken($token)) {
            return true;
        } else {
            sendResponse(401, initBody(true, "Bad token"), null);
            $app->stop();
        }
    } else {
        sendResponse(401, initBody(true, "Token is missing"), null);
        $app->stop();
    }
}
$app->get('/users/:id', function ($id) use($app) {
    $db = new dbHandler();
    if ($result = $db->getUser($id)) {
        sendResponse(200, initBody(false, null), $result->fetch_assoc());
    } else {
        sendResponse(400, initBody(true, "An error occurred."), null);
    }
});
$app->get('/users', function () use($app) {
    $db = new dbHandler();
    if ($result = $db->getUsers()) {
        $users = array();
        while ($user = $result->fetch_assoc()) {
            array_push($users, $user);
        }
        sendResponse(200, initBody(false, null), $users);
    } else {
        sendResponse(400, initBody(true, "An error occured."), null);