def remove(cls, user: User, scope: str, name: str): permission = cls.get(scope=scope, name=name) if permission in user.permissions: index = user.permissions.index(permission) user.permissions.pop(index) user.save()
def signup(cls, username: str, email: str, password: str) -> User: user = User(email=email, username=username, password=auth.hashpwd(password)) user.save() return user
def update_avatar(cls, user: User, file: File): if user.avatar is not None: FileService.destroy(user.avatar) user.avatar = file user.save() return user
def list(cls, page=0, limit=10) -> List[User]: offset = page * limit accounts = User.objects().filter().limit(limit).skip(offset) return list(accounts)
def get_by_username(cls, username: str): user = User.objects().filter(username=username).first() return user
def get_by_email(cls, email: str): user = User.objects().filter(email=email).first() return user
def get_by_id(cls, uid: str): user = User.objects().filter(id=uid).first() return user
def update(cls, user: User, **kwargs): user = update_document(user, kwargs) user.save()
def add(cls, user: User, scope: str, name: str): permission = cls.get(scope=scope, name=name) if permission not in user.permissions: user.permissions.append(permission) user.save()