def _check_operate_params(self): """ 检查创建、编辑的操作合法性 :return: """ self._result.pop('page_size') self._result.pop('page_index') self._result['env_id'] = int_checker(self._result.get('env_id'), 0, default=0) if self._result.get('env_id') == 0: raise ValueError('环境参数异常') self._result['app_id'] = int_checker(self._result.get('app_id'), 0, default=0) if self._result.get('app_id') == 0: raise ValueError('应用参数错误') self._result['is_grey'] = int_checker(self._result.get('is_grey'), 0, default=0) self._result['platform_num'] = int_checker( self._result.get('platform_num'), 0, default=0) if self._result.get('platform_num') == 0: raise ValueError('平台参数异常') self._result['name'] = str_checker(self._result.get('name'), 5, 100, is_html_encode=True, default=None) if self._result['name'] is None: raise ValueError('路由名参数错误') self._result['content'] = str_checker(self._result.get('content'), is_html_encode=True) self._result['url'] = str_checker(self._result.get('url'), is_html_encode=True, default='') if self._result.get('url') == '': raise ValueError('API路由不能为空') self._result['version'] = float_checker(self._result.get('version'), 0.0, default=0.0) if self._result.get('version') == 0.0: raise ValueError('版本号异常') self._result['function_name'] = str_checker( self._result.get('function_name'), 5, 255, is_html_encode=True, default=None) if self._result.get('function_name') is None: raise ValueError('函数名称参数异常')
def _check_search_params(self): """ 检查查询的参数合法性 :return: """ if self._result.get('env_id') is None: self._result['env_id'] = 0 if self._result.get('app_id') is None: self._result['app_id'] = 0 int_checker(self._result.get('page_size'), 5, 50, default=10) int_checker(self._result.get('page_index'), 1, default=1) self._result.pop('function_name') self._result.pop('url') self._result.pop('version')
def put(self, user_id): """ :param user_id: :return: """ info = Request() user_id = int(user_id) user_object = User() username = str_checker(info.get_param('username'), 5, 20, default=None) role_id = int_checker(info.get_param('role_id'), 1, 3, default=None) content = str_checker(info.get_param('content'), is_html_encode=True) print(session.get('role')) if session.get('role') == 1: if user_object.update(user_id, role_id=role_id) is None: return self.error_404('用户不存在') else: return self.succeed('用户更新信息成功') if session.get('admin_user_id') == user_id: if user_object.update(user_id, username=username, content=content) is None: return self.error_404('用户不存在') else: return self.succeed('用户更新信息成功') return self.error_403('用户更新信息失败')
def get(self): """ 获取用户列表 :return: """ info = Request() username = str_checker(info.get_param('username'), is_html_encode=False) page_size = int_checker(info.get_param('page_size', 10), 5, 50, default=10) page_index = int_checker(info.get_param('page_index', 1), 1, default=1) user_info = User.get_list(username, page_size, page_index) return self.succeed( '查询成功', { 'user_list': user_info.get('list'), 'page_info': user_info.get('page_info') })
def post(self): """ 创建用户 :return: """ user_object = User() if session.get('role') != 1: return self.error_403('创建用户失败') info = Request() username = str_checker(info.get_param('username'), 5, 20, default=None, is_html_encode=True) password = str_checker((info.get_param('password')), 8, default=None, is_html_encode=True) if username is None: return self.error_400('用户名长度需要需要在5-20个字符之间') if password is None: return self.error_400('密码不符合要求') if user_object.check_username(username): user_object.create(username=username, password=sha256( password.encode('utf-8')).hexdigest(), content=str_checker(info.get_param('content'), is_html_encode=True, default=''), role_id=int_checker(info.get_param('role_id'), 1, 3, default=3)) return self.succeed('用户创建成功') else: return self.error_400('用户名已被占用')