add user signup flow
This commit is contained in:
10
app/auth.py
10
app/auth.py
@@ -4,6 +4,7 @@ from argon2 import PasswordHasher
|
||||
from functools import wraps
|
||||
import secrets
|
||||
import time
|
||||
import re
|
||||
|
||||
ph = PasswordHasher()
|
||||
|
||||
@@ -44,6 +45,15 @@ def create_session(user_id, temporary=False):
|
||||
'expires_at': int(time.time()) + (expires_days * 24 * 60 * 60),
|
||||
})
|
||||
|
||||
def parse_username(username: str) -> Tuple[str, str]:
|
||||
if len(username) < 3:
|
||||
raise ValueError
|
||||
invalid_regex = r'[^a-zA-Z0-9_-]'
|
||||
return username, re.sub(invalid_regex, '_', username.lower())[:20]
|
||||
|
||||
def is_password_valid(password: str) -> bool:
|
||||
return re.match(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_])(?!.*\s).{10,255}$', password) is not None
|
||||
|
||||
# annotations
|
||||
def login_required(view_func):
|
||||
@wraps(view_func)
|
||||
|
||||
Reference in New Issue
Block a user