Show phone number when username doesn't exist. Fixes #213

This commit is contained in:
Tulir Asokan
2018-09-28 02:46:02 +03:00
parent 8d982b4615
commit a32bc2985a
9 changed files with 90 additions and 36 deletions
+11 -8
View File
@@ -75,7 +75,7 @@ class ProvisioningAPI(AuthAPI):
return self.get_error_response(404, "portal_not_found",
"Portal with given Matrix ID not found.")
user, _ = await self.get_user(request.query.get("user_id", None), expect_logged_in=None,
require_puppeting=False)
require_puppeting=False)
return web.json_response({
"mxid": portal.mxid,
"chat_id": get_peer_id(portal.peer),
@@ -102,7 +102,7 @@ class ProvisioningAPI(AuthAPI):
return self.get_error_response(404, "portal_not_found",
"Portal to given Telegram chat not found.")
user, _ = await self.get_user(request.query.get("user_id", None), expect_logged_in=None,
require_puppeting=False)
require_puppeting=False)
return web.json_response({
"mxid": portal.mxid,
"chat_id": get_peer_id(portal.peer),
@@ -380,16 +380,18 @@ class ProvisioningAPI(AuthAPI):
"errcode": errcode,
}, status=status)
def get_mx_login_response(self, status=200, state="", username="", mxid="", message="",
error="", errcode=""):
def get_mx_login_response(self, status=200, state="", username="", phone="", human_tg_id="",
mxid="", message="", error="", errcode=""):
raise NotImplementedError()
def get_login_response(self, status=200, state="", username="", mxid="", message="", error="",
errcode="") -> web.Response:
if username:
def get_login_response(self, status=200, state="", username="", phone: str = "",
human_tg_id: str = "", mxid="", message="", error="", errcode=""
) -> web.Response:
if username or phone:
resp = {
"state": "logged-in",
"username": username,
"phone": phone,
}
elif message:
resp = {
@@ -436,7 +438,8 @@ class ProvisioningAPI(AuthAPI):
if expect_logged_in is not None:
logged_in = await user.is_logged_in()
if not expect_logged_in and logged_in:
return user, self.get_login_response(username=user.username, status=409,
return user, self.get_login_response(username=user.username, phone=user.phone,
status=409,
error="You are already logged in.",
errcode="already_logged_in")
elif expect_logged_in and not logged_in:
+7 -1
View File
@@ -716,6 +716,9 @@ responses:
username:
type: string
description: The Telegram username the user is logged in as.
phone:
type: string
description: The phone number of the account the user is logged into.
BadRequest:
description: Invalid JSON.
schema:
@@ -800,7 +803,7 @@ definitions:
example: A.
phone:
type: string
example: +123456789
example: 123456789
is_bot:
type: boolean
example: false
@@ -858,6 +861,9 @@ definitions:
username:
type: string
description: The Telegram username the user is logged in as. Only applicable if state=logged-in
phone:
type: string
description: The phone number of the account the user logged into. Only applicable if state=logged-in
HumanReadableError:
type: string