def createNewUserGroup(cls, name, permissions=None): ''' 创建新的用户组 :return: ''' userGroup = UserGroup(name=name) ''' 配置用户组权限 ''' if permissions is None: userGroup.permissions = PM.defaultPms() else: userGroup.setPms(permissions) if not userGroup.is_valid(): raise ValueError(userGroup.errors) ''' 设置用户组id和用户组名 ''' counter = Counter.obj() counter.incr(Counter.userGroup) userGroup.id = counter.ugid ''' 存库 ''' userGroup.save() return userGroup
def createNewUser(cls, username, password): ''' 创建新的用户 :param username: :param password: :return: ''' # TODO 密码明文加密, 暂时不做加密,直接保存明文 # user = User(uid=userUid, username=username, password=password) user = User(username=username, password=password) ''' 检查账号是否生成成功 ''' if not user.is_valid(): ''' 生成失败,直接报错退出 ''' raise ValueError(user.errStr) # if NEW_ACCOUNT_ERR_NOT_UNIQUE in user.validate(): # raise ValueError('用户名重复!!!') ''' 生成新的用户的id ''' counter = Counter.obj() counter.incr(Counter.user) user.id = counter.uid ''' 生成成功,账号存库 ''' user.save() return user