from dataclasses import dataclass from datetime import datetime from hashlib import shake_256 import uuid def phash(pw,salt=None): 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 # And on User.register (InviteToken) @dataclass class Token(): value: str owner: AbstractUser def __init__(self,value,owner=None): if owner is None: owner=value self.value=uuid.uuid4() else: self.value=uuid.UUID(value) self.owner=owner def revoke(self): backend.delete_token(self) @dataclass class InviteToken(Token): _uses: int=0 _max_uses: int=-1 _expires: datetime=None def __init__(self,*args,**kwargs): return super().__init__(*args,**kwargs) @property def uses(self): return self._uses @uses.setter def uses(self,val): if -1