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.'); } }); // Add a pass to a user $app->post('/users/:uid/pass', function ($uid) use($app, $ldap, $database, $error) { // Check the scanned pass, returning errors when not acceptable $scan = $database->validatePassAttempt(); if ($scan === Database::ERROR_ENTRIES_TOO_OLD) { $error->send(403, $scan, 'Pass scan has expired', 'The last pass was scanned more than 10 minutes ago.'); } elseif ($scan === Database::ERROR_PASS_MISMATCH) { $error->send(403, $scan, 'Last two passes are not identical', 'The last two passes that were scanned are not the same pass.'); }