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)
评论列表
文章目录