From 005d2f3b6c1e879be2430898c1c982637f498c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Thu, 4 Dec 2025 10:19:49 +0300 Subject: [PATCH] fix signup --- app/db.py | 2 +- app/routes/users.py | 52 ++++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/app/db.py b/app/db.py index a9a30b5..4cf56fd 100644 --- a/app/db.py +++ b/app/db.py @@ -28,7 +28,7 @@ class DB: if in_transaction: conn.commit() - except Exception: + except Exception as e: if in_transaction and self._connection: conn.rollback() finally: diff --git a/app/routes/users.py b/app/routes/users.py index 46ad49b..3dbcfbc 100644 --- a/app/routes/users.py +++ b/app/routes/users.py @@ -67,11 +67,22 @@ def get_active_user(): def create_session(user_id): - return Sessions.create({ - "key": secrets.token_hex(16), + print('key') + key = secrets.token_hex(16) + print(key) + print('user id') + print(user_id) + print('expires') + expires_at = int(time.time()) + 31 * 24 * 60 * 60 + print(expires_at) + print('create') + s = Sessions.create({ + "key": key, "user_id": user_id, - "expires_at": int(time.time()) + 31 * 24 * 60 * 60, + "expires_at": expires_at, }) + print(s) + return s def extend_session(user_id): @@ -334,26 +345,27 @@ def sign_up_post(): else: display_name = '' - new_user = Users.create({ - "username": username, - 'display_name': display_name, - "password_hash": hashed, - "permission": PermissionLevel.GUEST.value, - }) - - BookmarkCollections.create_default(new_user.id) - - if current_app.config['DISABLE_SIGNUP']: - invite_key = InviteKeys.find({'key': key}) - new_user.update({ - 'invited_by': invite_key.created_by, - 'permission': PermissionLevel.USER.value, + with db.transaction(): + new_user = Users.create({ + "username": username.lower(), + 'display_name': display_name, + "password_hash": hashed, + "permission": PermissionLevel.GUEST.value, }) - invite_key.delete() - session_obj = create_session(new_user.id) + BookmarkCollections.create_default(new_user.id) - session['pyrom_session_key'] = session_obj.key + if current_app.config['DISABLE_SIGNUP']: + invite_key = InviteKeys.find({'key': key}) + new_user.update({ + 'invited_by': invite_key.created_by, + 'permission': PermissionLevel.USER.value, + }) + invite_key.delete() + + session_obj = create_session(new_user.id) + + session['pyrom_session_key'] = session_obj.key flash("Signed up successfully!", InfoboxKind.INFO) return redirect(url_for("topics.all_topics"))