Beispiel #1
0
def get_refresh_token():
    user = api.helpers.get_user()
    user_id = user.id
    agent = request.headers.get('User-Agent')
    token = jwt.create_refresh_token(user_id, agent)
    xhr = MakeResponse(200)
    res = dict(refresh_token=token)
    xhr.set_body(res)
    return xhr.response
Beispiel #2
0
def get_refresh_token():
    user = api.helpers.get_user()
    user_id = user.id
    agent = request.headers.get('User-Agent')
    token = jwt.create_refresh_token(user_id, agent)
    xhr = MakeResponse(200)
    res = dict(refresh_token=token)
    xhr.set_body(res)
    return xhr.response
Beispiel #3
0
def get_user_tags(user_id):
    user = helpers.get_user()
    xhr = MakeResponse()
    if user.id is not user_id:
        xhr.set_error(401)
        return xhr.response
    tags = User.query.get_or_404(user_id).tags
    tags = [t.to_dict() for t in tags]
    xhr.set_body(tags)
    return xhr.response
Beispiel #4
0
def get_user_tags(user_id):
    user = helpers.get_user()
    xhr = MakeResponse()
    if user.id is not user_id:
        xhr.set_error(401)
        return xhr.response
    tags = User.query.get_or_404(user_id).tags
    tags = [t.to_dict() for t in tags]
    xhr.set_body(tags)
    return xhr.response
Beispiel #5
0
def get_tag(tag_id):
    user = api.helpers.get_user()
    tag = Tag.query.get_or_404(tag_id)
    xhr = MakeResponse(200)

    if not tag.user_is_owner(user):
        xhr.set_error(401, "You are not the owner of this tag.")
        return xhr.response

    tag = tag_schema.dump(tag).data
    xhr.set_body(data=tag)
    return xhr.response
Beispiel #6
0
def auth_login():
    data = request.get_json()
    username = data.get('username')
    password = data.get('password')
    user = User.query.filter_by(username=username).first()
    xhr = MakeResponse(200)
    if user and user.authenticate(password):
        token = jwt.create_token_for_user(user)
        res = dict(access_token=token)
        xhr.set_body(res)
        return xhr.response

    else:
        xhr.set_error(401, {"error": "Trouble authenticating"})
        return xhr.response
Beispiel #7
0
def auth_login():
    data = request.get_json()
    username = data.get('username')
    password = data.get('password')
    user = User.query.filter_by(username=username).first()
    xhr = MakeResponse(200)
    if user and user.authenticate(password):
        token = jwt.create_token_for_user(user)
        res = dict(access_token=token)
        xhr.set_body(res)
        return xhr.response

    else:
        xhr.set_error(401, {"error": "Trouble authenticating"})
        return xhr.response
Beispiel #8
0
def refresh_auth_token():
    data = request.get_json()
    agent = request.headers.get('User-Agent')
    refresh_token = data.get('refresh_token')
    user = api.helpers.get_user()
    user_id = user.id
    xhr = MakeResponse(200)

    if jwt.verify_refresh_token(refresh_token, user_id, agent):
        token = jwt.create_token_for_user(user)
        xhr.set_body(dict(access_token=token))
        return xhr.response

    xhr.set_error(
        401, "Could not refresh, please try logging out and logging back in.")
    return xhr.response
Beispiel #9
0
def refresh_auth_token():
    data = request.get_json()
    agent = request.headers.get('User-Agent')
    refresh_token = data.get('refresh_token')
    user = api.helpers.get_user()
    user_id = user.id
    xhr = MakeResponse(200)

    if jwt.verify_refresh_token(refresh_token, user_id, agent):
        token = jwt.create_token_for_user(user)
        xhr.set_body(dict(access_token=token))
        return xhr.response

    xhr.set_error(
        401,
        "Could not refresh, please try logging out and logging back in."
    )
    return xhr.response