I hate the dataclass tbh, circular dependency my ass
This commit is contained in:
parent
e6e98bcbd9
commit
7a975a5782
@ -19,7 +19,8 @@ def save_user(user):
|
||||
gen=linegen(users)
|
||||
for line in gen:
|
||||
split=line.split(',')
|
||||
if split[0]==user.username: update(users,{gen.send(True):user.csv})
|
||||
if split[0]==user.username: update(users,{gen.send(True):user.csv}); break
|
||||
else: update(users,{-1:user.csv})
|
||||
def delete_user(user): pass
|
||||
|
||||
def load_tokens(user): pass
|
||||
@ -51,5 +52,6 @@ def update(path,lines):
|
||||
if i in lines: write.write(lines[i]+'\n')
|
||||
else: write.write(line)
|
||||
line=file.readline()
|
||||
if -1 in lines: write.write(lines[-1])
|
||||
file.close()
|
||||
write.close()
|
4
main.py
4
main.py
@ -2,3 +2,7 @@ from importlib import import_module
|
||||
from . import utils, models
|
||||
from .config import config
|
||||
|
||||
globals()['backend']=import_module('backends.'+config['backend']['type'])
|
||||
backend.config=config['backend']['options']
|
||||
backend.utils=utils
|
||||
models.backend=backend
|
10
models.py
10
models.py
@ -4,8 +4,8 @@ from hashlib import shake_256
|
||||
import uuid
|
||||
|
||||
def phash(pw,salt=None):
|
||||
if salt is None: salt=uuid.uuid64()
|
||||
return shake_256(f'{pw}{salt}'.encode('utf-8')).hexdigest(),salt
|
||||
if salt is None: salt=uuid.uuid4()
|
||||
return shake_256(f'{pw}{salt}'.encode('utf-8')).hexdigest(256),salt
|
||||
|
||||
class AbstractUser():
|
||||
pass # It fixes circular dep on user.invited_by
|
||||
@ -15,7 +15,7 @@ class User(AbstractUser):
|
||||
username: str
|
||||
password_hash: str
|
||||
salt: str
|
||||
invited_by: AbstractUser # Root node will just reference itself
|
||||
invited_by: AbstractUser=None # Root node will just reference itself
|
||||
email: str=''
|
||||
@property
|
||||
def csv(self):
|
||||
@ -33,11 +33,11 @@ class User(AbstractUser):
|
||||
if phash(password,u.salt)[0]==u.password_hash: return AccessToken(u)
|
||||
raise Exception("Incorrect password")
|
||||
@classmethod
|
||||
def register(cls,username:str,password:str,email:str|None):
|
||||
def register(cls,username:str,password:str,invite:InviteToken,email:str|None):
|
||||
if set([chr(n) for n in range(32)]+[','])&set(username): raise Exception('Invalid username')
|
||||
u=backend.load_user(username)
|
||||
if u is not None: raise Exception("User already exists")
|
||||
u=User(username,*phash(password),email)
|
||||
u=User(username,*phash(password),invite.owner,email)
|
||||
u.save()
|
||||
return u
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user