Skip to content
Snippets Groups Projects
Commit fc62029b authored by Tulir Asokan's avatar Tulir Asokan :cat2:
Browse files

Update provisioning API paths

parent 26fb3a20
Branches unpuppet
No related tags found
No related merge requests found
Pipeline #2827 passed
......@@ -68,16 +68,10 @@ class User(DBUser, BaseUser):
async def is_logged_in(self) -> bool:
try:
return bool(self.client) # and (await self.client.start()).is_logged_in
return bool(self.client) and bool(self.session_data)
except Exception:
return False
async def try_connect(self) -> None:
try:
await self.connect()
except Exception:
self.log.exception("Error while connecting to puppeteer script")
async def connect_double_puppet(self) -> None:
self.log.debug("Trying to log in with shared secret")
try:
......
......@@ -32,8 +32,8 @@ class ProvisioningAPI:
def __init__(self, shared_secret: str) -> None:
self.app = web.Application()
self.shared_secret = shared_secret
self.app.router.add_get("/api/whoami", self.status)
self.app.router.add_get("/api/login", self.login)
self.app.router.add_get("/whoami", self.status)
self.app.router.add_get("/login", self.login)
@property
def _acao_headers(self) -> Dict[str, str]:
......@@ -95,8 +95,9 @@ class ProvisioningAPI:
data = {
"mxid": user.mxid,
"amp": {
"connected": True,
} if await user.is_logged_in() else None,
"has_session": user.session_data is not None,
"connected": await user.is_logged_in(),
},
}
return web.json_response(data, headers=self._acao_headers)
......@@ -109,12 +110,13 @@ class ProvisioningAPI:
ws = web.WebSocketResponse(protocols=["net.maunium.amp.login"])
await ws.prepare(request)
# TODO if already logged in, send "already logged in" as an error
try:
async for url in user.client.login():
self.log.debug("Sending QR URL %s to websocket", url)
await ws.send_json({"url": url})
except Exception:
await ws.send_json({"success": False})
except Exception as e:
await ws.send_json({"success": False, "error": str(e)})
self.log.exception("Error logging in")
else:
await ws.send_json({"success": True})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment