Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    def signup(cls, username: str, email: str, password: str) -> User:
        user = User(email=email,
                    username=username,
                    password=auth.hashpwd(password))

        user.save()
        return user
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
 def list(cls, page=0, limit=10) -> List[User]:
     offset = page * limit
     accounts = User.objects().filter().limit(limit).skip(offset)
     return list(accounts)
Ejemplo n.º 5
0
 def get_by_username(cls, username: str):
     user = User.objects().filter(username=username).first()
     return user
Ejemplo n.º 6
0
 def get_by_email(cls, email: str):
     user = User.objects().filter(email=email).first()
     return user
Ejemplo n.º 7
0
 def get_by_id(cls, uid: str):
     user = User.objects().filter(id=uid).first()
     return user
Ejemplo n.º 8
0
 def update(cls, user: User, **kwargs):
     user = update_document(user, kwargs)
     user.save()
Ejemplo n.º 9
0
    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()