web.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:livebridge 作者: dpa-newslab 项目源码 文件源码
def login(self, request):
        try:
            assert self.config["auth"]["user"]
            assert self.config["auth"]["password"]
        except AssertionError:
            logger.error("HTTP Auth credentials are missing!")
            return web.json_response({"error": "Auth credentials are missing."}, status=400)

        params = await request.post()
        user = params.get('username', None)
        if (user == self.config["auth"]["user"] and
                params.get('password', None) == self.config["auth"]["password"]):
            # User is in our database, remember their login details
            _tokens[user] = str(uuid.uuid4())
            return web.json_response({"token": _tokens[user]})
        return web.json_response({"error": "Unauthorized"}, status=401)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号