Esempio n. 1
0
    } 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.');
    }
    // Store pass on user
    $pass = $ldap->addPass($uid, $database->getLastRefusedPass());
    // 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()]);
});