为什么 find_one 返回我案例中的所有文件?

Why find_one is returning all documents in my case?

我正在尝试使用 BCryptAuth 来保护资源以及登录系统。 我试图根据在登录页面输入的用户电子邮件仅获取一个文档。

class BCryptAuth(BasicAuth):
def check_auth(self, email, password, allowed_roles, resource, method):
    account = app.data.driver.db['users'].find_one({'email': email})
    return account and \
            bcrypt.hashpw(password.encode('utf-8'),account['salt'].encode('utf-8')) == account['password']

但是当我尝试通过邮递员访问用户端点时,它实际上验证了 returns 所有文档。我有点困惑。如果我的方法有误,请提供一个。

您提到的 Auth class 将只允许或不允许访问 API。它对资源过滤没有任何作用。

如果想在获取users时进行资源过滤,可以创建一个事件钩子,做一个pre-GET动态过滤。检查documentation,应该会有帮助。