From 7e149907263f8b0e8de2a2b97ee4cd94ae9d4b17 Mon Sep 17 00:00:00 2001 From: Andre Stein Date: Tue, 8 Mar 2022 13:28:54 -0300 Subject: [PATCH] Ssave settings including custom fields --- routers/auth.py | 11 ++++++----- storages.py | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/routers/auth.py b/routers/auth.py index 0176843..33d682a 100644 --- a/routers/auth.py +++ b/routers/auth.py @@ -18,17 +18,19 @@ def handle_exception(client, e): print("------ Challenge required \n\n") api_path = client.last_json['challenge']['api_path'] user_id = client.last_json['challenge']['user_id'] - settings = client.get_settings(); + settings = client.get_settings() settings.challenge_url = api_path + # Vamos salvar as configurações do usuário que iniciou o challenge - clients: ClientStorage = Depends(get_clients) + clients = ClientStorage() cl = clients.client() - cl.set_settings(json.loads(settings)) + # Mock an session ID sessionid = user_id + ":challenge_required" cl.sessionid = sessionid + # aqui ele vai salvar no tinydb - clients.set(cl) + clients.set_custom(cl) return True @@ -42,7 +44,6 @@ async def auth_login(username: str = Form(...), clients: ClientStorage = Depends(get_clients)) -> str: """Login by username and password with 2FA """ - cl = clients.client() diff --git a/storages.py b/storages.py index 6112c59..b46b143 100644 --- a/storages.py +++ b/storages.py @@ -36,5 +36,14 @@ def set(self, cl: Client) -> bool: self.db.insert(Document({'sessionid': key, 'settings': json.dumps(cl.get_settings())}, doc_id=user_pkid)) return True + def set_custom(self, cl: Client, settings) -> bool: + """Set client settings + """ + key = parse.unquote(cl.sessionid.strip(" \"")) + user_pkid = key.split(":")[0] + + self.db.insert(Document({'sessionid': key, 'settings': settings}, doc_id=user_pkid)) + return True + def close(self): pass