def wrapper(self, *args, **kwargs): if PermissionAuth().permission_auth(self.current_user, handlername, types, obj_model): return method(self, *args, **kwargs) else: flash(self, '没有删除的权限', 'error') self.redirect('/permission/manage_list')
def regist(self, name, mobile, mobile_captcha, password1, password2, captcha, code): """04注册函数 判断类型 边界值 """ if self.conn.get("captcha:%s" % code) != captcha.lower(): flash(self, '图片验证码不正确', 'error') return {'status': False, 'msg': '图片验证码不正确'} if self.conn.get("mobile_code:%s" % mobile) != mobile_captcha: flash(self, '短信验证码不正确', 'error') return {'status': False, 'msg': '短信验证码不正确'} if password1 != password2: flash(self, '两次密码不一致', 'error') return {'status': False, 'msg': '两次密码不一致'} #存入数据库 user = User.by_name(name) if user is not None: flash(self, '用户名已存在', 'error') return {'status': False, 'msg': '用户名已存在'} user = User() user.name = name user.password = password2 user.mobile = mobile self.db.add(user) self.db.commit() flash(self, '注册成功', 'success') return {'status': True, 'msg': '注册成功'}
def del_user_allrole_lib(self, userid): """13删除用户的所有角色""" user = User.by_id(userid) user.roles = [] self.db.add(user) self.db.commit() flash(self, '用户角色删除成功', 'success')
def del_handler_lib(self, handlerid): """09删除处理器""" handler = Handler.by_id(handlerid) if handler is None: return self.db.delete(handler) self.db.commit() flash(self, "处理器删除成功", "success")
def del_user_role_lib(self, userid,roleid): """12删除用户的角色""" user = User.by_id(userid) role = Role.by_id(roleid) user.roles.remove(role) self.db.add(user) self.db.commit() flash(self, '用户角色删除成功', 'success')
def del_role_name(self, role_id): ''' 删除角色名 ''' role = Role.by_id(role_id) if role: self.db.delete(role) self.db.commit() flash(self, "删除成功", "success") return {'status': True} return {'status': False, 'msg': '不存在的ID'}
def del_user_role_lib(self, userid): '''12 删除用户角色''' user = User.by_id(userid) if user is None: flash(self, '用户角色不存在,删除失败!', 'error') return self.db.delete(user) self.db.commit() flash(self, '用户删除成功!', 'success')
def del_menu_lib(self, menuid): """07删除菜单""" menu = Menu.by_id(menuid) if menu is None: flash(self, "菜单权限,删除失败", "error") return self.db.delete(menu) self.db.commit() flash(self, "菜单权限,删除成功", "success")
def del_role_lib(self, roleid): """03删除角色""" role = Role.by_id(roleid) if role is None: #如果role是空的话,我们就什么也不操作 flash(self, "角色不存在") return self.db.delete(role) self.db.commit() flash(self, "角色删除成功", "success")
def del_permission_lib(self,perid): """05删除权限函数""" per = Permission.by_id(perid) if per is None: flash(self, "此权限不存在,删除失败", "error") return self.db.delete(per) self.db.commit() flash(self, "权限删除成功", "success")
def del_handler_lib(self,handlerid): """09删除视图函数""" handler = Handler.by_id(handlerid) if handler is None: flash(self, "处理器权限,删除失败", "error") return self.db.delete(handler) self.db.commit() flash(self, "处理器权限,删除成功", "success")
def del_permission_lib(self, permissionid): """05删除权限""" permission = Permission.by_id(permissionid) if permission is None: return self.db.delete(permission) self.db.commit() flash(self, "权限删除成功", "success")
def del_role_lib(self, roleid): """03删除角色""" role= Role.by_id(roleid) if role is None: flash(self, "角色删除失败", "error") return self.db.delete(role) self.db.commit() flash(self, "角色删除成功", "success")
def del_user_lib(self, uuid): """12为用户删除角色""" user = User.by_id(uuid) if user is None: return user.roles = [] self.db.add(user) self.db.commit() flash(self, "为用户删除角色删除成功", "success")
def add_role_permission_lib(self, roleid, permissionid): """11为角色添加权限""" role = Role.by_id(roleid) permission = Permission.by_id(permissionid) if role is None or permission is None: return role.permissions.append(permission) self.db.add(role) self.db.commit() flash(self, "为角色添加权限添加成功", "success")
def del_menu_lib(self, menuid): """07为菜单删除权限""" # 其实这里只删除了menu,因为menu.permission这个对象是基于menu的 # 所以只要删除了menu,那么基于它之上的都会被删除 menu = Menu.by_id(menuid) if menu is None: return self.db.delete(menu) self.db.commit() flash(self, "菜单删除权限成功", "success")
def del_handler_lib(self, handlerid): '''09删除处理器''' handler = Handler.by_id(handlerid) # 判断该c处理器id获取值是否为空 if handler is None: flash(self, '处理器不存在,删除失败!', 'error') return self.db.delete(handler) self.db.commit() flash(self, '处理器删除成功!', 'success')
def add_user_dev_role_lib(self, userid, roleid): """13添加用户到研发部门""" user = User.by_id(userid) role = Role.by_id(roleid) if user is None or role is None: return user.roles.append(role) self.db.add(user) self.db.commit() flash(self, "为用户添加研发部门的角色添加成功", "success")
def del_role_lib(self, roleid): '''03删除角色''' role = Role.by_id(roleid) # 获取用户信息 # 判断角色是否存在 if role is None: flash(self, '角色删除失败!', 'error') return self.db.delete(role) self.db.commit() flash(self, '角色删除成功!', 'success')
def add_user_role_lib(self, userid, roleid): """10为用户添加角色""" user = User.by_id(userid) role = Role.by_id(roleid) if user is None or role is None: return user.roles.append(role) #注意这里画龙点睛 self.db.add(user) self.db.commit() flash(self, "为用户添加角色添加成功", "success")
def del_permission_lib(self, permissionid): '''05删除权限''' permission = Permission.by_id(permissionid) # 判断该权限id获取值是否为空 if permission is None: flash(self, '权限不存在,删除失败!', 'error') return self.db.delete(permission) self.db.commit() flash(self, '权限删除成功!', 'success')
def del_menu_lib(self, menuid): '''07删除菜单''' menu = Menu.by_id(menuid) # 判断该菜单id获取值是否为空 if menu is None: flash(self, '菜单不存在,删除失败!', 'error') return self.db.delete(menu) self.db.commit() flash(self, '菜单删除成功!', 'success')
def add_permission_lib(self, name, strcode): """04添加权限""" permission = Permission.by_name(name) if permission is not None: return permission = Permission() permission.name = name permission.strcode = strcode self.db.add(permission) self.db.commit() flash(self, "权限添加成功", "success")
def del_user_for_one_role_lib(self, userid, roleid): """15为用户删除某个角色""" user = User.by_id(userid) role = Role.by_id(roleid) # print("********%s"%role) if user is None or role is None: return user.roles.remove(role) self.db.add(user) self.db.commit() flash(self, "为用户删除某个角色删除成功", "success")
def add_role_lib(self, name): """02添加角色函数""" role= Role.by_name(name) if role is not None: flash(self, "角色已经存在,添加失败", "error") return role = Role() role.name = name self.db.add(role) self.db.commit() flash(self, "角色添加成功", "success")
def add_role_permission_lib(self, permissionid, roleid): """11为角色添加权限""" permission = Permission.by_id(permissionid) role = Role.by_id(roleid) if permission is None or role is None: flash(self, "为角色添加权限失败", "error") return permission.roles.append(role) #多对多关系添加 self.db.add(permission) self.db.commit() flash(self, "为角色添加权限成功", "success")
def add_user_role_lib(self, userid, roleid): """10为用户添加角色""" user = User.by_id(userid) role = Role.by_id(roleid) if user is None or role is None: flash(self, "为用户添加角色失败", "error") return user.roles.append(role) #这行的意思是:往多对多关系表中插入数据 #role.users.append(user) self.db.add(user) self.db.commit() flash(self, "为用户添加角色成功", "success")
def add_handler_lib(self, name, permissionid): """08为视图添加权限函数""" permission = Permission.by_id(permissionid) if permission is None: flash(self, "处理器权限,添加失败", "error") return hanlder = Handler.by_name(name) # 注意 if hanlder is None: hanlder = Handler() hanlder.name = name hanlder.permission = permission self.db.add(hanlder) self.db.commit() flash(self, "处理器权限,添加成功", "success")
def edit_profile(self, name, password): """编辑个人信息""" if password == "": return {'status': False, 'msg': "密码不能为空"} if name == "": return {'status': False, 'msg': "姓名不能为空"} user = self.current_user user.name = name user.password = password user.update_time = datetime.now() self.db.add(user) self.db.commit() self.session.set('user_name', user.name) flash(self, '修改成功', 'success')
def add_handler_lib(self, name, permissionid): """08为处理器添加权限""" permission = Permission.by_id(permissionid) handler = Handler.by_name(name) if permission is None: return if handler is None: handler = Handler() handler.name = name handler.permission = permission self.db.add(handler) self.db.commit() flash(self, "处理器权限添加成功", "success")