Skip to content

Commit

Permalink
Ssave settings including custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Stiveknx committed Mar 8, 2022
1 parent 6684058 commit 7e14990
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

Expand Down
9 changes: 9 additions & 0 deletions storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7e14990

Please sign in to comment.