def post(self, *_args, **_kwargs): """Log in.""" args = self.parse_json_arguments('name', 'password') user_info = tasks.query_user(username=args.name) if not user_info['data']: user_info = tasks.query_user(email=args.name) if not user_info['data']: self.fail(3011) user_info = user_info['data'] if user_info['pswd'] != generate.encode_passwd(args.password): self.fail(3001) if not user_info['active_status']: self.fail(3002) user_params = dict(supervisor=user_info['supervisor'], user_name=user_info['username'], email=user_info['email'], user_id=user_info['user_id']) self.set_current_user(user_info['user_id']) self.set_parameters(user_params) self.success(user_params)
def put(self, *_args, **_kwargs): """Update Category Name.""" yield self.check_auth() args = self.parse_json_arguments('category_id', 'category_name') tasks.update_category_name(category_id=args.category_id, category_name=args.category_name) self.success()
def post(self, *_args, **_kwargs): yield self.check_auth() args = self.parse_json_arguments('article_id', 'publish_status') tasks.update_article_publish_state( article_id=args.article_id, publish_status=args.publish_status, ) self.success()
def delete(self, *_args, **_kwargs): params = yield self.check_auth() args = self.parse_form_arguments('category_id') result = tasks.delete_category(category_id=args.category_id, user_id=params.user_id) if not result['data'] or not result['data']['effect_rows']: self.fail(4004) tasks.delete_article_by_category_id(category_id=args.category_id) self.success()
def get(self, *_args, **_kwargs): result = tasks.query_article_latest() article_list = result['data']['article_list'] self.success(data=dict(article_list=article_list))
def post(self, *_args, **_kwargs): params = yield self.check_auth() args = self.parse_json_arguments('name') result = tasks.query_user_exists(username=args.name) if result['data']['exist']: self.fail(3004) tasks.update_user_name(user_id=params.user_id, username=args.name) params['user_name'] = args.name self.set_parameters(params) self.success()
def get(self, *_args, **_kwargs): """Get Category List of Current User.""" args = self.parse_form_arguments('category_id') result = tasks.query_category_by_id(category_id=args.category_id) self.success(data=dict(category_info=result['data']['category_info']))
def get(self, *_args, **_kwargs): """Get Category List of Current User.""" result = tasks.query_category_by_category_status(category_status=1) category_list = result['data']['category_list'] self.success(data=dict(category_list=category_list))
def get(self, *_args, **_kwargs): args = self.parse_form_arguments('article_id') result = tasks.query_article_relative(article_id=args.article_id) article = result['data']['article'] category = result['data']['category'] user = result['data']['user'] self.success(dict(article=article, category=category, user=user))
def post(self, *_args, **_kwargs): params = yield self.check_auth() args = self.parse_json_arguments('old_pass', 'new_pass') user_info = tasks.query_user(user_id=params.user_id) if not user_info['data']: self.fail(4004) old_md5 = generate.encode_passwd(args.old_pass) if old_md5 != user_info['data']['pswd']: self.fail(3001) new_md5 = generate.encode_passwd(args.new_pass) tasks.update_user_pass(user_id=params.user_id, pswd=new_md5) self.success()
def get(self, *_args, **_kwargs): args = self.parse_form_arguments('user_id') result = tasks.query_user(user_id=args.user_id) user_params = dict(supervisor=result['data']['supervisor'], user_name=result['data']['username'], email=result['data']['email'], user_id=result['data']['user_id']) self.success(user_params)
def post(self, *_args, **_kwargs): """Add a Category to Current User.""" params = yield self.check_auth() args = self.parse_json_arguments('category_name') result = tasks.insert_category(category_name=args.category_name, category_type=1, user_id=params.user_id) category_id = result['data']['category_id'] self.success(dict(category_id=category_id))
def get(self, *_args, **_kwargs): """Get Article Source via Specific ID.""" args = self.parse_form_arguments('article_id') result = tasks.query_article(article_id=args.article_id) if not result['data']: self.fail(4004) article_content = self.article_content.find_one( dict(article_id=args.article_id)) result['data']['article']['content'] = article_content['content'] self.success(result['data']['article'])
def put(self, *_args, **_kwargs): args = self.parse_json_arguments('username', 'email', 'password') if not verify.verify_email(args.email): self.fail(3032) if not verify.verify_password(args.password): self.fail(3031) result = tasks.query_user_exists(username=args.username, email=args.email) if result['data']['exist']: self.fail(3004) result = tasks.insert_user(username=args.username, email=args.email, pswd=generate.encode_passwd(args.password)) user_id = result['data']['user_id'] tasks.insert_category(category_name='默认分类', category_type=0, user_id=user_id) self.success(dict(user_id=user_id))
def get(self, *_args, **_kwargs): """Get Category List of Current User.""" args = self.parse_form_arguments('user_id') result = tasks.query_category_by_user_id(user_id=args.user_id) category_list = result['data']['category_list'] order_list = self.category_order.find_one({'user_id': args.user_id}) if order_list: order_list = order_list.get('category_order') self.success( data=dict(category_list=category_list, order_list=order_list))
def get(self, *_args, **_kwargs): params = yield self.check_auth() args = self.parse_form_arguments('article_id') result = tasks.query_article(article_id=args.article_id) if not result['data'].get('article'): self.fail(4004) article = result['data'].get('article') if params.user_id != article['user_id']: self.fail(4005) self.success()
def delete(self, *_args, **_kwargs): params = yield self.check_auth() args = self.parse_form_arguments('article_id') result = tasks.delete_article(article_id=args.article_id, user_id=params.user_id) if result['status']: self.fail(4004) if not result['data']['effect_rows']: self.fail(4005) self.article_content.delete_one({'article_id': args.article_id}) self.success()
def put(self, *_args, **_kwargs): yield self.check_auth() args = self.parse_json_arguments('article_id', title=None, content=None, category_id=None) if args.title or args.category_id: update_dict = dict(title=args.title, category_id=args.category_id) tasks.update_article(article_id=args.article_id, **update_dict) if args.content: self.article_content.update_one( {'article_id': args.article_id}, {'$set': { 'content': args.content }}, upsert=True) result = tasks.query_article(article_id=args.article_id) result['data']['article']['content'] = args.content self.success(result['data']['article'])
def get(self, *_args, **_kwargs): args = self.parse_form_arguments('category_id') result = tasks.query_article_info_list(category_id=args.category_id) article_list = result['data']['article_list'] order_list = self.article_order.find_one( {'category_id': args.category_id}) if order_list: order_list = order_list.get('article_order') self.success( data=dict(article_list=article_list, order_list=order_list))
def post(self, *_args, **_kwargs): params = yield self.check_auth() args = self.parse_json_arguments('category_id') result = tasks.insert_article(user_id=params.user_id, title='无标题文章', content='', category_id=args.category_id) if not result['data']: self.fail(5003) article_id = result['data']['article_id'] self.article_content.update_one({'article_id': article_id}, {'$set': { 'content': '' }}, upsert=True) self.success(dict(article_id=article_id))
def get(self, *_args, **_kwargs): _params = yield self.check_auth(supervisor=1) user_list = tasks.query_normal_user_list() self.success(user_list['data']['users'])