示例#1
0
    // Send answer based on result
    if ($pass === LDAP::ERROR_USER_NOT_FOUND) {
        $error->send(404, $pass, 'The user cannot be found', 'This user does not exist or has been removed.');
    } elseif ($pass === LDAP::ERROR_DOUBLE_PASS) {
        $error->send(409, $pass, 'The user already has a pass', 'This user already has a pass set. A second one cannot be added.');
    } elseif ($pass === LDAP::ERROR_PASS_EXISTS) {
        $error->send(409, $pass, 'This pass is in use', 'Another user has registered this pass. It cannot be added again.');
    } else {
        // Return the new entry of the user
        $app->response->setStatus(200);
        echo json_encode($ldap->getUser($uid));
    }
});
// 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