Esempio n. 1
0
def get_complex_one(id):
    '''
	Theme详情接口
	:url /theme/:id
	:param id: 专题theme的id
	:return: 专题theme的详情
	'''
    id = IDMustBePositiveInt().validate_for_api().id.data
    theme_detail = Theme.get_theme_detail(id=id)
    return Success(theme_detail)
Esempio n. 2
0
def get_simple_list():
    '''
	:url /theme
	:arg /theme?ids=id1,id2,id3,...
	:return: 一组theme模型
	'''
    # args = IDCollection().validate_for_api()
    ids = IDCollection().validate_for_api().ids.data
    theme = Theme.get_themes(ids=ids)
    return Success(theme)
Esempio n. 3
0
def get_token():
    form = ClientValidator().validate_for_api()
    promise = {
        ClientTypeEnum.USER_EMAIL: User.verify_by_email,
        ClientTypeEnum.USER_WX: User.verify_by_wx,
    }
    # 微信登录则account为code(需要微信小程序调用wx.login接口获取), secret为空
    identity = promise[ClientTypeEnum(form.type.data)](form.account.data,
                                                       form.secret.data)

    # Token生成
    expiration = current_app.config['TOKEN_EXPIRATION']
    token = generate_auth_token(identity['uid'], form.type.data,
                                identity['scope'], expiration)
    return Success(data=token)
Esempio n. 4
0
def get_token_info():
    """获取令牌信息"""
    form = TokenValidator().validate_for_api()
    s = Serializer(current_app.config['SECRET_KEY'])
    try:
        data = s.loads(form.token.data, return_header=True)
    except SignatureExpired:
        raise AuthFailed(msg='token is expired', error_code=1003)
    except BadSignature:
        raise AuthFailed(msg='token is invalid', error_code=1002)

    r = {
        'scope': data[0]['scope'],
        'create_at': data[1]['iat'],  # 创建时间
        'expire_in': data[1]['exp'],  # 有效期
        'uid': data[0]['uid']
    }
    return Success(data=r)
Esempio n. 5
0
def get_banner(id):
    '''获取「首页轮播图」'''
    id = IDMustBePositiveInt().validate_for_api().id.data
    banner = Banner.get_banner_by_id(id=id)
    # banner.hide('description') # 临时隐藏
    return Success(banner)
Esempio n. 6
0
def delete_one(id):
	id = IDMustBePositiveInt().validate_for_api().id.data
	product = Product.get_product_detail(id=id)
	return Success(code=202, error_code=2, msg='删除成功')
Esempio n. 7
0
def get_one(id):
	id = IDMustBePositiveInt().validate_for_api().id.data
	product = Product.get_product_detail(id=id)
	return Success(product)
Esempio n. 8
0
def get_all_in_category():
	id = IDMustBePositiveInt().validate_for_api().id.data
	products = Product.get_product_by_category_id(id=id)
	return Success(products)
Esempio n. 9
0
def get_recent():
	count = Count().validate_for_api().count.data
	products = Product.get_most_recent(count=count)
	return Success(products)
Esempio n. 10
0
def get_address():
    '''获取「用户自身的地址」'''
    uid = g.user.uid
    with db.auto_check_empty(UserException(error_code=6001, msg='用户地址不存在')):
        user_address = UserAddress.query.filter_by(user_id=uid).first_or_404()
    return Success(user_address)
Esempio n. 11
0
def get_user():
    uid = g.user.uid  # g变量是「线程隔离」的,是全局变量(方便在各处调用);「g.user」是当前用户
    user = User.query.filter_by(id=uid).first_or_404()
    return Success(user)
Esempio n. 12
0
def super_get_user(uid):
    # user = User.query.get_or_404(uid) # 会查询到已经被删除的数据
    user = User.query.filter_by(id=uid).first_or_404()
    return Success(user)
Esempio n. 13
0
def place_order():
    products = OrderPlace().validate_for_api().products.data

    return Success(products)
Esempio n. 14
0
def download_file(file_name):
	'''文件下载(从数据库)'''
	print('file_name', file_name)
	return Success(file_name)
Esempio n. 15
0
def get_all_categories():
	categories = Category.get_all_categories()
	return Success(categories)
Esempio n. 16
0
def upload_file():
    '''文件上传'''
    return Success(123)