From c0ceb1b2b007ad0f878a4c11ae993e7eb7f59b24 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Thu, 12 Jul 2018 23:45:15 +0300 Subject: [PATCH] Move post_login_token to common/auth_api --- mautrix_telegram/web/common/auth_api.py | 13 +++++++++++++ mautrix_telegram/web/public/__init__.py | 13 ------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mautrix_telegram/web/common/auth_api.py b/mautrix_telegram/web/common/auth_api.py index 9502db53..3ce557ba 100644 --- a/mautrix_telegram/web/common/auth_api.py +++ b/mautrix_telegram/web/common/auth_api.py @@ -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) diff --git a/mautrix_telegram/web/public/__init__.py b/mautrix_telegram/web/public/__init__.py index c08b1bc6..89a76fd7 100644 --- a/mautrix_telegram/web/public/__init__.py +++ b/mautrix_telegram/web/public/__init__.py @@ -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: