def delete_user(id): token = request.headers.get('token') #用来校验令牌是否有效 user = UserService.get_user_by_token(token) user = User.get_by_id(id) if user.name == 'admin': return Utils.resp_failure('admin不允许删除') user.delete_instance() return Utils.resp_success()
def new_role(): token = request.headers.get('token') #用来校验令牌是否有效 UserService.get_user_by_token(token) form = NewRoleForm() form.validate_for_api() name = form.name.data # 判断名是否重复 role = Role.get_or_none(Role.name == name) if role is not None: return Utils.resp_failure('角色名' + name + '已存在') role = Role() role.name = name role.create_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) role.update_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) role.save() return Utils.resp_success(role)
def left(): #用来校验令牌是否有效 user = UserService.get_user_by_token(request.headers.get('token')) # 根据角色ID获取对应的权限列表 role_items = RoleItem.select().where(RoleItem.role_id == user.role_id) # 根据菜单ID查出所有的菜单详情 items = [] for roleItem in role_items: item = Item.get_by_id(roleItem.item_id) items.append(item) return Utils.resp_success(items)
def new_user(): token = request.headers.get('token') #用来校验令牌是否有效 user = UserService.get_user_by_token(token) form = NewUserForm() form.validate_for_api() name = form.name.data pwd = form.pwd.data role_id = form.roleId.data # 判断用户名是否重复 user = User.get_or_none(User.name == name) if user is not None: return Utils.resp_failure('用户名' + name + '已存在') user = User() user.name = name user.role_id = role_id user.pwd = hashlib.md5(pwd.encode(encoding='UTF-8')).hexdigest() user.enabled = 1 user.create_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) user.update_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) user.save() return Utils.resp_success(user)
def load_user(): token = request.headers.get('token') #用来校验令牌是否有效 user = UserService.get_user_by_token(token) form = LoadUserForm() # 第几页 current_page = form.currentPage.data # 用户名模糊查询 name = form.userName.data # 角色模糊查询 role_id = form.roleId.data return Utils.resp_success( UserService.find_user_by_name_role_page(name, role_id, current_page))
def test(): # header_name=request.headers.get('name',default="empty") # form_name=request.form.get('name',default="empty") # args_name=request.args.get('name',default="empty") # data=request.get_data() # data = json.loads(data) # json_name = data['name'] # # logging.info("header_name:"+header_name) # logging.info("form_name:"+form_name) # logging.info("args_name:"+args_name) # logging.info("json_name:"+json_name) #return Response('<h1>Hello World!</h2>', status=200, mimetype='text/html') a = Utils.resp_failure("用户名密码错误") return a
def edit_user(): token = request.headers.get('token') #用来校验令牌是否有效 user = UserService.get_user_by_token(token) form = EditUserForm() form.validate_for_api() id = form.id.data pwd = form.pwd.data role_id = form.role_id.data user = User.get_by_id(id) if pwd != '': user.pwd = hashlib.md5(pwd.encode(encoding='UTF-8')).hexdigest() user.role_id = role_id user.update_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) user.save() return Utils.show_alert('保存成功', '/go_edit_user/' + str(id))
def index(): token = request.headers.get('token') #用来校验令牌是否有效 user = UserService.get_user_by_token(token) return Utils.resp_success(user)