Move post_login_token to common/auth_api

This commit is contained in:
Tulir Asokan
2018-07-12 23:45:15 +03:00
parent f07009d0d2
commit c0ceb1b2b0
2 changed files with 13 additions and 13 deletions
+13
View File
@@ -68,6 +68,19 @@ class AuthAPI(abc.ABC):
return self.get_login_response(mxid=user.mxid, state="request", status=500,
error="Internal server error while requesting code.")
async def post_login_token(self, user, token):
try:
user_info = await user.client.sign_in(bot_token=token)
asyncio.ensure_future(user.post_login(user_info), loop=self.loop)
if user.command_status and user.command_status["action"] == "Login":
user.command_status = None
return self.get_login_response(mxid=user.mxid, state="logged-in", status=200,
username=user_info.username)
except Exception:
self.log.exception("Error sending bot token")
return self.get_login_response(mxid=user.mxid, state="token", status=500,
error="Internal server error while sending token.")
async def post_login_code(self, user, code, password_in_data):
try:
user_info = await user.client.sign_in(code=code)
-13
View File
@@ -62,19 +62,6 @@ class PublicBridgeWebsite(AuthAPI):
text=self.login.render(username=username, state=state, error=error,
message=message, mxid=mxid))
async def post_login_token(self, user, token):
try:
user_info = await user.client.sign_in(bot_token=token)
asyncio.ensure_future(user.post_login(user_info), loop=self.loop)
if user.command_status and user.command_status["action"] == "Login":
user.command_status = None
return self.get_login_response(mxid=user.mxid, state="logged-in", status=200,
username=user_info.username)
except Exception:
self.log.exception("Error sending bot token")
return self.get_login_response(mxid=user.mxid, state="token", status=500,
error="Internal server error while sending token.")
async def post_login(self, request):
data = await request.post()
if "mxid" not in data: