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)
|
gen=linegen(users)
|
||||||
for line in gen:
|
for line in gen:
|
||||||
split=line.split(',')
|
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 delete_user(user): pass
|
||||||
|
|
||||||
def load_tokens(user): pass
|
def load_tokens(user): pass
|
||||||
|
@ -51,5 +52,6 @@ def update(path,lines):
|
||||||
if i in lines: write.write(lines[i]+'\n')
|
if i in lines: write.write(lines[i]+'\n')
|
||||||
else: write.write(line)
|
else: write.write(line)
|
||||||
line=file.readline()
|
line=file.readline()
|
||||||
|
if -1 in lines: write.write(lines[-1])
|
||||||
file.close()
|
file.close()
|
||||||
write.close()
|
write.close()
|
4
main.py
4
main.py
|
@ -2,3 +2,7 @@ from importlib import import_module
|
||||||
from . import utils, models
|
from . import utils, models
|
||||||
from .config import config
|
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
|
import uuid
|
||||||
|
|
||||||
def phash(pw,salt=None):
|
def phash(pw,salt=None):
|
||||||
if salt is None: salt=uuid.uuid64()
|
if salt is None: salt=uuid.uuid4()
|
||||||
return shake_256(f'{pw}{salt}'.encode('utf-8')).hexdigest(),salt
|
return shake_256(f'{pw}{salt}'.encode('utf-8')).hexdigest(256),salt
|
||||||
|
|
||||||
class AbstractUser():
|
class AbstractUser():
|
||||||
pass # It fixes circular dep on user.invited_by
|
pass # It fixes circular dep on user.invited_by
|
||||||
|
@ -15,7 +15,7 @@ class User(AbstractUser):
|
||||||
username: str
|
username: str
|
||||||
password_hash: str
|
password_hash: str
|
||||||
salt: str
|
salt: str
|
||||||
invited_by: AbstractUser # Root node will just reference itself
|
invited_by: AbstractUser=None # Root node will just reference itself
|
||||||
email: str=''
|
email: str=''
|
||||||
@property
|
@property
|
||||||
def csv(self):
|
def csv(self):
|
||||||
|
@ -33,11 +33,11 @@ class User(AbstractUser):
|
||||||
if phash(password,u.salt)[0]==u.password_hash: return AccessToken(u)
|
if phash(password,u.salt)[0]==u.password_hash: return AccessToken(u)
|
||||||
raise Exception("Incorrect password")
|
raise Exception("Incorrect password")
|
||||||
@classmethod
|
@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')
|
if set([chr(n) for n in range(32)]+[','])&set(username): raise Exception('Invalid username')
|
||||||
u=backend.load_user(username)
|
u=backend.load_user(username)
|
||||||
if u is not None: raise Exception("User already exists")
|
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()
|
u.save()
|
||||||
return u
|
return u
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user