Ejemplo n.º 1
0
    def put(self, *_args, **_kwargs):
        args = self.parse_json_arguments(username=ENFORCED,
                                         email=ENFORCED,
                                         password=ENFORCED)

        if not self.pattern_match('email', args.email):
            return self.fail(3032)
        if not self.pattern_match('password', args.password):
            return self.fail(3031)

        exists_result = tasks.query_email_or_username_exists(
            username=args.username, email=args.email)
        if exists_result:
            return self.fail(3004)

        insert_result = tasks.insert_user(
            username=args.username,
            email=args.email,
            pswd=md5(args.password.encode()).hexdigest())

        insert_result = tasks.insert_category(
            category_name='默认分类',
            category_type=0,
            user_id=insert_result['data']['user_id'])

        self.success()
Ejemplo n.º 2
0
    def post(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_json_arguments(
            article_id=ENFORCED,
            title=OPTIONAL,
            content=OPTIONAL,
            category_id=OPTIONAL)

        if args.title or args.category_id:
            check_list = ('title', 'category_id')
            update_dict = dict((arg, args.get(arg)) for arg in args.arguments
                               if arg in check_list)

            update_result = tasks.update_article(
                article_id=args.article_id, **update_dict)
            if not update_result['result']:
                return self.fail(5003)

        if args.content:
            update_result = self.article_content.update_one(
                {
                    'article_id': args.article_id
                }, {'$set': {
                    'content': args.content
                }},
                upsert=True)
            if not update_result:
                return self.fail(5003)

        query_result = tasks.query_article(article_id=args.article_id)

        self.success(data=dict(query_result, content=args.content))
Ejemplo n.º 3
0
    def post(self, *_args, **_kwargs):
        args = self.parse_json_arguments(name=ENFORCED, password=ENFORCED)

        user_info = tasks.query_user(username=args.name)

        if not user_info:
            user_info = tasks.query_user(email=args.name)

        if not user_info:
            return self.fail(3011)

        if user_info['pswd'] != md5(args.password.encode()).hexdigest():
            return self.fail(3001)

        if not user_info['active_status']:
            return self.fail(3002)

        user_params = dict(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(data=user_params)
Ejemplo n.º 4
0
    def delete(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_form_arguments(category_id=ENFORCED)

        delete_result = tasks.delete_category(category_id=args.category_id)

        _update_result = tasks.delete_article_by_category_id(
            category_id=args.category_id)

        self.success(data=delete_result)
Ejemplo n.º 5
0
    def get(self, *_args, **_kwargs):

        args = self.parse_form_arguments(limit=ENFORCED)

        query_result = tasks.query_article_info_list(limit=args.limit)

        self.success(data=dict(article_list=query_result, order_list=None))
Ejemplo n.º 6
0
    def delete(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_form_arguments(article_id=ENFORCED)

        query_result = tasks.query_article(article_id=args.article_id)
        if not query_result:
            return self.fail(4004)
        if query_result['user_id'] != _params.user_id:
            return self.fail(4005)

        tasks.delete_article(article_id=args.article_id)
        self.article_content.delete_one({'article_id': args.article_id})

        self.success()
Ejemplo n.º 7
0
    def post(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_json_arguments(name=ENFORCED)

        exists_result = tasks.query_username_exists(username=args.name)

        if exists_result:
            return self.fail(3004)

        tasks.update_user_name(user_id=_params.user_id, username=args.name)

        _params.add('user_name', args.name)
        self.set_parameters(_params[0])

        self.success()
Ejemplo n.º 8
0
    def get(self, *_args, **_kwargs):
        args = self.parse_form_arguments(article_id=ENFORCED)

        query_result = tasks.query_article(article_id=args.article_id)
        if not query_result:
            return self.fail(4004)

        article_content = self.article_content.find_one(
            dict(article_id=args.article_id))

        self.success(
            data=dict(query_result, content=article_content['content']))
Ejemplo n.º 9
0
    def post(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_json_arguments(category_id=ENFORCED,
                                         category_name=ENFORCED)

        update_result = tasks.update_category_name(
            category_id=args.category_id, category_name=args.category_name)

        self.success()
Ejemplo n.º 10
0
    def put(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_json_arguments(category_name=ENFORCED)

        insert_result = tasks.insert_category(category_name=args.category_name,
                                              category_type=1,
                                              user_id=_params.user_id)

        self.success()
Ejemplo n.º 11
0
    def post(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_json_arguments(old_pass=ENFORCED, new_pass=ENFORCED)

        user_info = tasks.query_user(user_id=_params.user_id)

        if not user_info:
            return self.fail(4004)

        old_md5 = md5(args.old_pass.encode()).hexdigest()
        new_md5 = md5(args.new_pass.encode()).hexdigest()

        if old_md5 != user_info['pswd']:
            print(old_md5, user_info['pswd'])
            return self.fail(3001)

        tasks.update_user_pass(user_id=_params.user_id, pswd=new_md5)

        self.success()
Ejemplo n.º 12
0
    def post(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_json_arguments(
            article_id=ENFORCED, publish_status=ENFORCED)

        _update_result = tasks.update_article_publish_state(
            article_id=args.article_id,
            publish_status=args.publish_status,
        )

        self.success()
Ejemplo n.º 13
0
    def get(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        query_result = tasks.query_category_by_user_id(user_id=_params.user_id)

        order_list = self.category_order.find_one({'user_id': _params.user_id})

        if order_list:
            order_list = order_list.get('category_order')

        self.success(
            data=dict(category_list=query_result, order_list=order_list))
Ejemplo n.º 14
0
    def get(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_form_arguments(article_id=ENFORCED)

        query_result = tasks.query_article(article_id=args.article_id)

        if not query_result:
            return self.fail(4004)
        if _params.user_id != query_result['user_id']:
            return self.fail(4005)

        self.success()
Ejemplo n.º 15
0
    def get(self, *_args, **_kwargs):

        args = self.parse_form_arguments(category_id=ENFORCED, )

        query_result = tasks.query_article_info_list(
            category_id=args.category_id)

        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=query_result, order_list=order_list))
Ejemplo n.º 16
0
    def put(self, *_args, **_kwargs):
        _params = self.check_auth(2)
        if not _params:
            return

        args = self.parse_json_arguments(
            category_id=ENFORCED)

        insert_result = tasks.insert_article(
            user_id=_params.user_id,
            title='无标题文章',
            content='',
            category_id=args.category_id)

        update_result = self.article_content.update_one(
            dict(article_id=insert_result['data']['article_id']),
            {'$set': {
                'content': ''
            }},
            upsert=True)

        self.success(data=dict(insert_result['data']))
Ejemplo n.º 17
0
    def get(self, *_args, **_kwargs):

        query_result = tasks.query_category_by_category_order()

        self.success(data=dict(category_list=query_result))