fix signup
This commit is contained in:
@@ -28,7 +28,7 @@ class DB:
|
|||||||
|
|
||||||
if in_transaction:
|
if in_transaction:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
if in_transaction and self._connection:
|
if in_transaction and self._connection:
|
||||||
conn.rollback()
|
conn.rollback()
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -67,11 +67,22 @@ def get_active_user():
|
|||||||
|
|
||||||
|
|
||||||
def create_session(user_id):
|
def create_session(user_id):
|
||||||
return Sessions.create({
|
print('key')
|
||||||
"key": secrets.token_hex(16),
|
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,
|
"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):
|
def extend_session(user_id):
|
||||||
@@ -334,26 +345,27 @@ def sign_up_post():
|
|||||||
else:
|
else:
|
||||||
display_name = ''
|
display_name = ''
|
||||||
|
|
||||||
new_user = Users.create({
|
with db.transaction():
|
||||||
"username": username,
|
new_user = Users.create({
|
||||||
'display_name': display_name,
|
"username": username.lower(),
|
||||||
"password_hash": hashed,
|
'display_name': display_name,
|
||||||
"permission": PermissionLevel.GUEST.value,
|
"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,
|
|
||||||
})
|
})
|
||||||
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)
|
flash("Signed up successfully!", InfoboxKind.INFO)
|
||||||
return redirect(url_for("topics.all_topics"))
|
return redirect(url_for("topics.all_topics"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user