コード例 #1
0
def authenticate():
    token = request.headers.get(AUTH_TOKEN)
    token = params().get('token', token)
    user = User.from_token(token)
    if user:
        return user
    else:
        raise Unauthorized()
コード例 #2
0
def create_user():
    try:
        form = UserForm(params())
        if form.validate():
            user = User()
            user.generate_token()
            form.populate_obj(user)
            db.session.add(user)
            db.session.commit()
            return jsonify(user_view(user))
        else:
            return errors(form.errors)
    except IntegrityError:
        resp = jsonify({
            'username': "******",
            })
        resp.status_code = 400
        return resp