示例#1
0
def register():
    name = get_or_400(request.get_json(), 'name')
    user = db.session.query(User).filter(User.name==name).first()
    if user is not None:
        return make_api_resp(status_code=400, msg='user exists')
    password = get_or_400(request.get_json(), 'password')
    password_hash = bcrypt.generate_password_hash(password)
    user = User(name=name, password=password_hash)
    db.session.add(user)
    db.session.commit()
    return make_api_resp({'user_id':user.id})
示例#2
0
def register():
    name = get_or_400(request.get_json(), 'name')
    user = db.session.query(User).filter(User.name == name).first()
    if user is not None:
        return make_api_resp(status_code=400, msg='user exists')
    password = get_or_400(request.get_json(), 'password')
    password_hash = bcrypt.generate_password_hash(password)
    user = User(name=name, password=password_hash)
    db.session.add(user)
    db.session.commit()
    return make_api_resp({'user_id': user.id})
示例#3
0
def get_user():
    user_id = get_user_id_or_401()
    user = db.session.query(User).get(user_id)
    return make_api_resp({'user': {'id': user_id, 'name': user.name}})
示例#4
0
def default_error_handler(error):
    return make_api_resp(status_code=error.code, msg=error.name)
示例#5
0
def index():
    i = get_int_arg_or_400('i')
    s = get_arg_or_400('s')
    d = request.args.get('d', 'ddd')
    return make_api_resp({'i': i, 's': s, 'd': d})
示例#6
0
def get_user():
    user_id = get_user_id_or_401()
    user = db.session.query(User).get(user_id)
    return make_api_resp(
        {'user':{'id':user_id, 'name':user.name}}
    )
示例#7
0
def default_error_handler(error):
    return make_api_resp(status_code=error.code, msg=error.name)
示例#8
0
def index():
    i = get_int_arg_or_400('i')
    s = get_arg_or_400('s')
    d = request.args.get('d', 'ddd')
    return make_api_resp({'i':i, 's':s, 'd':d})