Ejemplo n.º 1
0
def get_user(id):
    user = userService.get_user_by_id(id)
    if user is None:
        return Restful.bad_request('用户ID: %s 不存在' % id)

    user = safe_model_to_json(enrich_user(user))
    return Restful.ok(user)
Ejemplo n.º 2
0
def update_user_sns(id):
    user = userService.get_user_by_id(id)
    if user is None:
        return Restful.bad_request('用户ID: %s 不存在' % id)

    userService.spider_user_sns(user)
    return Restful.ok()
Ejemplo n.º 3
0
def get_token():
    if g.token_used:
        return Restful.forbidden('请使用用户名和密码')

    return Restful.ok({
            'userId': g.current_user.id,
            'username': g.current_user.username,
            'avatar': g.current_user.avatar,
            'slogan': g.current_user.slogan,
            'token': userService.generate_auth_token(g.current_user.id, 3600*24), 
            'expiration': 3600*24
        })    
Ejemplo n.º 4
0
def register():
    try:
        user = userService.register(request.json)
        return Restful.created({
                'userId': user.id,
                'username': user.username,
                'avatar': user.avatar,
                'slogan': user.slogan,
                'token': userService.generate_auth_token(user.id, 3600*24),
                'expiration': 3600*24
            })
    except ServiceError, e:
        return Restful.bad_request(e.message)
Ejemplo n.º 5
0
def get_user_list():
    fuzzy = request.args.get('fuzzy', type=str)
    order = request.args.get('order', type=str)
    page, paginate_by = get_request_page_args(request)
    paginate = Paginate(userService.get_user_list(fuzzy=fuzzy), '/user', page, paginate_by)

    return Restful.ok(paginate.to_json())    
Ejemplo n.º 6
0
def validation_error(e):
    current_app.logger.error(e)
    return Restful.bad_request(e.message) 

# @api.errorhandler(Exception)
# def validation_error(e):
#     current_app.logger.error(e)
#     return Restful.internal_server_error(e)
Ejemplo n.º 7
0
def validation_error(e):
    current_app.logger.error(e)
    return Restful.bad_request(e.message)


# @main.errorhandler(Exception)
# def validation_error(e):
#     current_app.logger.error(e)
#     return Restful.internal_server_error(e)
Ejemplo n.º 8
0
def logout():
    return Restful.ok()
Ejemplo n.º 9
0
def auth_error():
    # return Restful.bad_request('用户名或密码错误')
    # qq浏览器返回401时,会弹出默认登录登陆框。   在after_request中改变响应头也没用。
    return Restful.forbidden('用户名或密码错误')
Ejemplo n.º 10
0
def app_page_not_found(e):
    current_app.logger.error(e)
    if request.accept_mimetypes.accept_json and not request.accept_mimetypes.accept_html:
        response = Restful.page_not_found()
        return response
    return render_template('404.html'), 404
Ejemplo n.º 11
0
def app_method_not_allowed(e):
    current_app.logger.error(e)
    response = Restful.method_not_allowed()
    return response
Ejemplo n.º 12
0
def app_internal_server_error(e):
    current_app.logger.error(e)
    response = Restful.internal_server_error(e.message)
    return response
Ejemplo n.º 13
0
def modify_user(id):
    try:
        user = userService.modify_user_profile(id, request.json)
        return Restful.ok(user.to_json())
    except ServiceError, e:
        return Restful.bad_request(e.message)
Ejemplo n.º 14
0
def app_page_not_found(e):
    current_app.logger.error(e)
    response = Restful.page_not_found()
    return response
Ejemplo n.º 15
0
def app_internal_server_error(e):
    current_app.logger.error(e)
    response = Restful.internal_server_error(e.message)
    return response
Ejemplo n.º 16
0
def app_page_not_found(e):
    current_app.logger.error(e)
    response = Restful.page_not_found()
    return response
Ejemplo n.º 17
0
def app_method_not_allowed(e):
    current_app.logger.error(e)
    response = Restful.method_not_allowed()
    return response
Ejemplo n.º 18
0
def app_method_not_allowed(e):
    current_app.logger.error(e)
    if request.accept_mimetypes.accept_json and not request.accept_mimetypes.accept_html:
        response = Restful.method_not_allowed()
        return response
    return render_template('405.html'), 405
Ejemplo n.º 19
0
def app_internal_server_error(e):
    current_app.logger.error(e)
    if request.accept_mimetypes.accept_json and not request.accept_mimetypes.accept_html:
        response = Restful.internal_server_error(e.message)
        return response
    return render_template('500.html'), 500
Ejemplo n.º 20
0
from restful import Restful
#------------Test------------------
rest = Restful()


@rest.router('/wm/[a]?')
def test():
    a = rest.getAttribute('a')
    v = rest.query('u')
    if not v:
        v = ''
    elif v is True:
        v = '\"true\"'
    return '{\"test\":' + a + ',\"value\":' + v + '}'


@rest.router('/vpc/[b]')
def test():
    attrB = rest.getAttribute('b')
    return '{\"vpc\":' + attrB + '}'


@rest.router('/post', 'POST')
def testPost():
    p = rest.query('p')
    v = rest.query('v')
    return '{\"q\":' + p + '\"v\":' + v + '}'


rest.run()