add settings routes
This commit is contained in:
17
app/auth.py
17
app/auth.py
@@ -66,6 +66,13 @@ def revoke_session(user_id):
|
||||
sess.delete()
|
||||
session.clear()
|
||||
|
||||
def revoke_all_sessions(user_id):
|
||||
if not is_logged_in():
|
||||
return
|
||||
|
||||
Sessions.revoke_all(user_id)
|
||||
session.clear()
|
||||
|
||||
def parse_username(username: str) -> Tuple[str, str]:
|
||||
"""first is the unmodified name/display name, second is username"""
|
||||
if len(username) < 3:
|
||||
@@ -77,6 +84,15 @@ def parse_username(username: str) -> Tuple[str, str]:
|
||||
invalid_regex = r'[^a-zA-Z0-9_-]'
|
||||
return re.sub(invalid_regex, '_', username.lower())[:24], username
|
||||
|
||||
def parse_display_name(display_name: str) -> str:
|
||||
if len(display_name) == 0:
|
||||
return display_name
|
||||
invalid_regex = r'[@<>&]'
|
||||
res = re.sub(invalid_regex, '_', display_name)[:50]
|
||||
while len(res) < 3:
|
||||
res += '_'
|
||||
return res
|
||||
|
||||
def is_password_valid(password: str) -> bool:
|
||||
return re.match(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_])(?!.*\s).{10,255}$', password) is not None
|
||||
|
||||
@@ -130,4 +146,3 @@ def csrf_verified(view_func):
|
||||
|
||||
return view_func(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user