frontend: fix account and owner creation (fixes #108)

This commit is contained in:
Hay1tsme 2024-03-02 17:48:48 -05:00
parent 84c059ed75
commit bd97428166
3 changed files with 9 additions and 9 deletions

View File

@ -127,7 +127,7 @@ class Data:
) )
hash = bcrypt.hashpw(pw.encode(), bcrypt.gensalt()) 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: if user_id is None:
self.logger.error(f"Failed to create owner with email {email}") self.logger.error(f"Failed to create owner with email {email}")
return return

View File

@ -310,7 +310,7 @@ class FE_Gate(FE_Base):
sesh = await self.data.user.check_password(uid) sesh = await self.data.user.check_password(uid)
if sesh is not None: 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) return RedirectResponse("/gate/?e=1", 303)
@ -334,10 +334,11 @@ class FE_Gate(FE_Base):
async def render_create(self, request: Request): async def render_create(self, request: Request):
ip = Utils.get_ip_addr(request) ip = Utils.get_ip_addr(request)
access_code: str = request.query_params.get("access_code", "") frm = await request.form()
username: str = request.query_params.get("username", "") access_code: str = frm.get("access_code", "")
email: str = request.query_params.get("email", "") username: str = frm.get("username", "")
passwd: bytes = request.query_params.get("passwd", "").encode() email: str = frm.get("email", "")
passwd: bytes = frm.get("passwd", "").encode()
if not access_code or not username or not email or not passwd: if not access_code or not username or not email or not passwd:
return RedirectResponse("/gate/?e=1", 303) return RedirectResponse("/gate/?e=1", 303)
@ -365,13 +366,13 @@ class FE_Gate(FE_Base):
usr_sesh = self.encode_session(sesh) usr_sesh = self.encode_session(sesh)
self.logger.debug(f"Created session with JWT {usr_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) resp.set_cookie("DIANA_SESH", usr_sesh)
return resp return resp
async def render_create_get(self, request: Request): 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: if len(ac) != 20:
return RedirectResponse("/gate/?e=2", 303) return RedirectResponse("/gate/?e=2", 303)

View File

@ -51,7 +51,6 @@ if __name__ == "__main__":
elif args.action == "create-owner": elif args.action == "create-owner":
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(data.create_owner(args.email, args.access_code)) loop.run_until_complete(data.create_owner(args.email, args.access_code))
data.schema_upgrade(args.version)
elif args.action == "migrate": elif args.action == "migrate":
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()