Esempio 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)
Esempio 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()
Esempio 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
        })    
Esempio 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)
Esempio 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())    
Esempio 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)
Esempio 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)
Esempio n. 8
0
def logout():
    return Restful.ok()
Esempio n. 9
0
def auth_error():
    # return Restful.bad_request('用户名或密码错误')
    # qq浏览器返回401时,会弹出默认登录登陆框。   在after_request中改变响应头也没用。
    return Restful.forbidden('用户名或密码错误')
Esempio 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
Esempio n. 11
0
def app_method_not_allowed(e):
    current_app.logger.error(e)
    response = Restful.method_not_allowed()
    return response
Esempio n. 12
0
def app_internal_server_error(e):
    current_app.logger.error(e)
    response = Restful.internal_server_error(e.message)
    return response
Esempio 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)
Esempio n. 14
0
def app_page_not_found(e):
    current_app.logger.error(e)
    response = Restful.page_not_found()
    return response
Esempio n. 15
0
def app_internal_server_error(e):
    current_app.logger.error(e)
    response = Restful.internal_server_error(e.message)
    return response
Esempio n. 16
0
def app_page_not_found(e):
    current_app.logger.error(e)
    response = Restful.page_not_found()
    return response
Esempio n. 17
0
def app_method_not_allowed(e):
    current_app.logger.error(e)
    response = Restful.method_not_allowed()
    return response
Esempio 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
Esempio 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
Esempio 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()