}); // Remove the pass of a user $app->delete('/users/:uid/pass', function ($uid) use($app, $ldap, $error) { if ($ldap->removePass($uid)) { $app->response->setStatus(204); // HTTP 204 No Content } else { $error->send(500, 'internal_error', 'Pass removal failed', 'The API cannot remove the pass of this user. The exact error is unknown.'); } }); // Check the last scanned pass was valid $app->get('/deur/checkpass', function () use($app, $ldap, $database, $error) { echo json_encode(['check' => $database->validatePassAttempt()]); }); // Check whether a specific pass can gain entry $app->get('/deur/access/:pass', function ($cardID) use($app, $ldap, $error, $database) { // Find card information in LDAP $info = $ldap->infoOnPassAttempt($cardID); // Log attempt $database->logAttempt($cardID, $info['access'], $info['username'], $info['reason']); // Send appropriate response if ($info['access'] === true) { // No answer is needed $app->response->setStatus(204); // HTTP 204 No Content } else { $error->send(403, 'access_denied', 'Access denied', 'This pass may not open the door at this time.'); } }); // Run the application $app->run();