diff options
| author | 2026-07-22 17:56:10 +0200 | |
|---|---|---|
| committer | 2026-07-22 17:56:10 +0200 | |
| commit | aa56bc05285981d57c5adb2cee3c4e898fb2a702 (patch) | |
| tree | 8c78888ad52c0d61034d681ca0550ee91b96cee7 | |
| parent | f28781dd1dd718f45bf1cef82d1ce6eb4792b4ca (diff) | |
| download | server-aa56bc05285981d57c5adb2cee3c4e898fb2a702.tar.gz server-aa56bc05285981d57c5adb2cee3c4e898fb2a702.tar.bz2 server-aa56bc05285981d57c5adb2cee3c4e898fb2a702.zip | |
Fixed login bug
| -rw-r--r-- | authentication/endpoints.py | 16 |
1 files 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 | |||
| 64 | 'username': username, | 64 | 'username': username, |
| 65 | 'password': password | 65 | 'password': password |
| 66 | }) | 66 | }) |
| 67 | |||
| 67 | with get_session_context() as db_session: | 68 | with get_session_context() as db_session: |
| 68 | user = db_session.query(User).filter(User.username == form.username).first() | 69 | user = db_session.query(User).filter(User.username == form.username).first() |
| 69 | 70 | ||
| 70 | if not bcrypt_sha256_verify(password, user.password if user is not None else '') or user is None: | 71 | if not bcrypt_sha256_verify(password, user.password if user is not None else '') or user is None: |
| 71 | errors.update({'password': 'Invalid username or password'}) | 72 | errors.update({'password': 'Invalid username or password'}) |
| 73 | else: | ||
| 74 | with get_session_context() as db_session: | ||
| 75 | session = Session(id=uuid7(), user=user) | ||
| 76 | db_session.add(session) | ||
| 72 | 77 | ||
| 73 | with get_session_context() as db_session: | 78 | request.session.update({'id': str(session.id)}) |
| 74 | session = Session(id=uuid7(), user=user) | ||
| 75 | db_session.add(session) | ||
| 76 | |||
| 77 | request.session.update({'id': str(session.id)}) | ||
| 78 | |||
| 79 | if next is not None: | ||
| 80 | return RedirectResponse(next, status_code=303) | ||
| 81 | 79 | ||
| 80 | if next is not None: | ||
| 81 | return RedirectResponse(next, status_code=303) | ||
| 82 | except ValidationError as exc: | 82 | except ValidationError as exc: |
| 83 | errors.update({e['loc'][0]: e['msg'] for e in exc.errors()}) | 83 | errors.update({e['loc'][0]: e['msg'] for e in exc.errors()}) |
| 84 | 84 | ||
