Пример #1
0
 */
$app = new \Slim\Slim();
// JSON-encoded data of all current members with passes
$app->get('/users', function () use($ldap, $database) {
    // Construct required data
    $users = $ldap->getAllUsers();
    $timestamps = $database->getLastEntries();
    $data = array_map(function ($user) use($timestamps) {
        $user['last_entry'] = isset($timestamps[$user['uid']]) ? $timestamps[$user['uid']] : 'Voor 1 september 2015 (of nooit)';
        return $user;
    }, $users);
    echo json_encode($data);
});
// Grant a user access to the door
$app->post('/users/:uid', function ($uid) use($app, $ldap, $error) {
    if ($ldap->grantAccess($uid)) {
        $app->response->setStatus(204);
        // HTTP 204 No Content
    } else {
        $error->send(500, 'internal_error', 'Access grant failed', 'The API cannot grant access to this user. The exact error is unknown.');
    }
});
// Deny a user access to the door
$app->delete('/users/:uid', function ($uid) use($app, $ldap, $error) {
    if ($ldap->denyAccess($uid)) {
        $app->response->setStatus(204);
        // HTTP 204 No Content
    } else {
        $error->send(500, 'internal_error', 'Access grant failed', 'The API cannot deny access to this user. The exact error is unknown.');
    }
});