fix signup

This commit is contained in:
2025-12-04 10:19:49 +03:00
parent 265e249eaf
commit 005d2f3b6c
2 changed files with 33 additions and 21 deletions

View File

@@ -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"))