From bd9742816623e0c4582d631a0b56e1532071a8da Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Sat, 2 Mar 2024 17:48:48 -0500 Subject: [PATCH] frontend: fix account and owner creation (fixes #108) --- core/data/database.py | 2 +- core/frontend.py | 15 ++++++++------- dbutils.py | 1 - 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/data/database.py b/core/data/database.py index 1d2793b..83863a8 100644 --- a/core/data/database.py +++ b/core/data/database.py @@ -127,7 +127,7 @@ class Data: ) hash = bcrypt.hashpw(pw.encode(), bcrypt.gensalt()) - user_id = await self.user.create_user("sysowner", email, hash.decode(), 255) + user_id = await self.user.create_user(username="sysowner", email=email, password=hash.decode(), permission=255) if user_id is None: self.logger.error(f"Failed to create owner with email {email}") return diff --git a/core/frontend.py b/core/frontend.py index 7fcea56..8e480b0 100644 --- a/core/frontend.py +++ b/core/frontend.py @@ -310,7 +310,7 @@ class FE_Gate(FE_Base): sesh = await self.data.user.check_password(uid) if sesh is not None: - return RedirectResponse(f"/gate/create?ac={access_code}") + return RedirectResponse(f"/gate/create?ac={access_code}", 303) return RedirectResponse("/gate/?e=1", 303) @@ -334,10 +334,11 @@ class FE_Gate(FE_Base): async def render_create(self, request: Request): ip = Utils.get_ip_addr(request) - access_code: str = request.query_params.get("access_code", "") - username: str = request.query_params.get("username", "") - email: str = request.query_params.get("email", "") - passwd: bytes = request.query_params.get("passwd", "").encode() + frm = await request.form() + access_code: str = frm.get("access_code", "") + username: str = frm.get("username", "") + email: str = frm.get("email", "") + passwd: bytes = frm.get("passwd", "").encode() if not access_code or not username or not email or not passwd: return RedirectResponse("/gate/?e=1", 303) @@ -365,13 +366,13 @@ class FE_Gate(FE_Base): usr_sesh = self.encode_session(sesh) self.logger.debug(f"Created session with JWT {usr_sesh}") - resp = RedirectResponse("/user", 303) + resp = RedirectResponse("/user/", 303) resp.set_cookie("DIANA_SESH", usr_sesh) return resp async def render_create_get(self, request: Request): - ac = request.query_params.get(b"ac", [b""])[0].decode() + ac = request.query_params.get("ac", "") if len(ac) != 20: return RedirectResponse("/gate/?e=2", 303) diff --git a/dbutils.py b/dbutils.py index 5b9b9e7..e5ea065 100644 --- a/dbutils.py +++ b/dbutils.py @@ -51,7 +51,6 @@ if __name__ == "__main__": elif args.action == "create-owner": loop = asyncio.get_event_loop() loop.run_until_complete(data.create_owner(args.email, args.access_code)) - data.schema_upgrade(args.version) elif args.action == "migrate": loop = asyncio.get_event_loop()