def sign_in(self, data): user = User.by_name(name=data.get('name')) password = user.local_oauth if user and password.auth_password(other_password=data.get('password')): self.session.set('user_name', user.name) return msg(True, "登陆成功") return msg(False, '用户名和密码不正确')
def set_permissions(self, data): """ 多对多的数据新增 1、拿到原来的数据 2、组装现在的数据 3、原来的数据集合和现在的数据集合比较得到的差集就是需要删除掉的数据 4、把现有的数据插入数据库 5、这里利用的是set的子交并补概念 date:2019-05-04 :param self: :param data: :return: """ role_id = data.get("role_id") del data['role_id'] role = Role.by_id(role_id) plist = role.permission permissions = list() for key, value in data.items(): permissions.append(Permission.by_id(key)) delete = list(set(plist).difference(set(permissions))) if delete is not None: for i in delete: role.permission.remove(i) self.db.commit() role.permission = permissions try: self.db.add(role) self.db.commit() return msg(True, "保存成功") except exc.IntegrityError as e: return msg(False, str(e))
def edit_group(self, data): group = PermissionGroup.by_id(data.get("id")) group.name = data.get("name") group.description = data.get("description") try: self.db.add(group) self.db.commit() return msg(True, "保存成功") except exc.IntegrityError as e: return msg(False, str(e))
def edit_role(self, data): role = Role.by_id(data.get("id")) role.name = data.get("name") role.description = data.get("description") try: self.db.add(role) self.db.commit() return msg(True, "保存成功") except exc.IntegrityError as e: return msg(False, str(e))
def add_group(self, data): group = PermissionGroup( name=data.get("name"), description=data.get("description") ) try: self.db.add(group) self.db.commit() return msg(True, '新增成功') except exc.IntegrityError as e: return msg(False, str(e))
def edit_permission(self, data): permission = Permission.by_id(data.get("id")) permission.name = data.get("name") permission.handler = data.get("handler") permission.description = data.get("description") try: self.db.add(permission) self.db.commit() return msg(True, "保存成功") except exc.IntegrityError as e: return msg(False, str(e))
def sign_up(self, data): user = User(name=data.get('name')) local_oauth = LocalOAuth() local_oauth.password = data.get('password') user.local_oauth = local_oauth try: self.db.add(user) self.db.commit() return msg(True, "注册成功") except exc.IntegrityError as e: return msg(False, str(e))
def add_role(self, data): role = Role( name=data.get("name"), description=data.get("description") ) try: self.db.add(role) self.db.commit() return msg(True, "新增成功") except exc.IntegrityError as e: return msg(False, str(e))
def add_permission(self, data): group = PermissionGroup.by_id(data.get('group_id')) permission = Permission( name=data.get('name'), handler=data.get('handler'), description=data.get("description") ) group.permissions.append(permission) try: self.db.add(group) self.db.commit() return msg(True, "保存成功") except exc.IntegrityError as e: return msg(False, str(e))