From aa56bc05285981d57c5adb2cee3c4e898fb2a702 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Wed, 22 Jul 2026 17:56:10 +0200 Subject: Fixed login bug --- authentication/endpoints.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/authentication/endpoints.py b/authentication/endpoints.py index 18f3ba6..6877383 100644 --- a/authentication/endpoints.py +++ b/authentication/endpoints.py @@ -64,21 +64,21 @@ async def post_login(request: Request, username: Annotated[str, Form()] = '', pa 'username': username, 'password': password }) + with get_session_context() as db_session: user = db_session.query(User).filter(User.username == form.username).first() if not bcrypt_sha256_verify(password, user.password if user is not None else '') or user is None: errors.update({'password': 'Invalid username or password'}) + else: + with get_session_context() as db_session: + session = Session(id=uuid7(), user=user) + db_session.add(session) - with get_session_context() as db_session: - session = Session(id=uuid7(), user=user) - db_session.add(session) - - request.session.update({'id': str(session.id)}) - - if next is not None: - return RedirectResponse(next, status_code=303) + request.session.update({'id': str(session.id)}) + if next is not None: + return RedirectResponse(next, status_code=303) except ValidationError as exc: errors.update({e['loc'][0]: e['msg'] for e in exc.errors()}) -- cgit v1.2.3