예제 #1
0
# -*- coding: utf8 -*-
from app.libs.c_blueprints import CBlueprint
from app.libs.error_code import Success
from app.libs.token_auth import auth
from app.models.like import Like
from app.validaters.forms import LikeForm

__author__ = 'Colorful'
__date__ = '2018/8/17 下午11:14'

api = CBlueprint('like')


@api.route('', methods=['POST'])
@auth.login_required
def add_like():
    form = LikeForm().validate_for_api()
    Like.add_favor(form.art_id.data, form.type.data)
    return Success()


@api.route('/cancel', methods=['POST'])
@auth.login_required
def cancel_like():
    form = LikeForm().validate_for_api()
    Like.cancel(form.art_id.data, form.type.data)
    return Success()
예제 #2
0
# -*- coding: utf8 -*-
from app.libs.c_blueprints import CBlueprint
from app.libs.enums import ClientTypeEnum
from app.libs.error_code import Success
from app.models.user import User
from app.validaters.forms import ClientForm

__author__ = 'Colorful'
__date__ = '2018/8/17 下午6:05'


api = CBlueprint('client')


@api.route('/register', methods=['POST'])
def create_client():
    """暂时不需要此接口"""
    form = ClientForm().validate_for_api()

    promise = {
        ClientTypeEnum.USER_EMAIL: __register_by_user_email,
        ClientTypeEnum.USER_MINA: __register_by_mina  # 微信小程序不需要注册,所以该方法暂时保留
    }
    promise[form.type.data]()

    return Success()


def __register_by_user_email():
    pass
예제 #3
0
# -*- coding: utf8 -*-
from flask import current_app, jsonify
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

from app.libs.c_blueprints import CBlueprint
from app.libs.enums import ClientTypeEnum
from app.models.user import User
from app.validaters.forms import UserMinaForm

__author__ = 'Colorful'
__date__ = '2018/8/17 下午6:45'

api = CBlueprint('token')


@api.route('/mina', methods=['POST'])
def get_mina_token():
    """获取小程序的token"""
    form = UserMinaForm().validate_for_api()
    promise = {
        ClientTypeEnum.USER_MINA: User.mina_verify,
        ClientTypeEnum.USER_EMAIL: User.verify
    }
    mina_code = form.code.data
    identify = promise[ClientTypeEnum(form.type.data)](mina_code)
    expiration = current_app.config['TOKEN_EXPIRATION']
    token = generate_auth_token(identify['uid'], form.type.data,
                                identify['scope'], expiration)
    t = {'token': token.decode('ascii')}
    return jsonify(t), 201
예제 #4
0
from app.libs.c_blueprints import CBlueprint
from app.libs.error_code import Success
from app.libs.token_auth import auth
from app.models.book import Book
from app.models.keywords import Keywords
from app.models.like import Like
from app.spider.douban_book import DouBanBook
from app.validaters.forms import\
    BookSearchForm, BookDetailForm, CommentAdd, BookForm
from app.view_models.book import BookCollection

__author__ = 'Colorful'
__date__ = '2018/8/13 上午1:19'


api = CBlueprint('book')


@api.route('/hot_list', methods=['GET'])
def get_hot():
    res = Book.get_hot(summary=1)
    return jsonify(res)


@api.route('/<int:book_id>/short_comment', methods=['GET'])
def get_short_comment(book_id):
    form = BookForm(data={'book_id': book_id}).validate_for_api()
    res = Book.get_comments(form.book_id.data)
    return jsonify(res)

예제 #5
0
# -*- coding: utf8 -*-
from flask import jsonify

from app.libs.c_blueprints import CBlueprint
from app.libs.token_auth import auth
from app.models.classic import Classic
from app.validaters.forms import ClassicForm, ClassicDetailForm, ClassicFavorForm
from app.view_models.classic import ClassicCollection

__author__ = 'Colorful'
__date__ = '2018/8/13 上午12:45'

api = CBlueprint('classic')


@api.route('/latest', methods=['GET'])
def get_latest():
    res = Classic().latest
    classic = ClassicCollection()
    data = classic.fill_single(res)
    return jsonify(data)


@api.route('/<int:index>/next', methods=['GET'])
def get_next(index):
    form = ClassicForm(data={'index': index}).validate_for_api()
    res = Classic().next(form.index.data)
    classic = ClassicCollection()
    data = classic.fill_single(res)
    return jsonify(data)