コード例 #1
0
def validate_invitation_token(invitation_type, token):

    max_age_seconds = 60 * 60 * 24 * current_app.config[
        'INVITATION_EXPIRATION_DAYS']

    try:
        invited_user_id = check_token(token, current_app.config['SECRET_KEY'],
                                      current_app.config['DANGEROUS_SALT'],
                                      max_age_seconds)
    except SignatureExpired:
        errors = {
            'invitation':
            'Your invitation to GOV.UK Notify has expired. '
            'Please ask the person that invited you to send you another one'
        }
        raise InvalidRequest(errors, status_code=400)
    except BadData:
        errors = {
            'invitation':
            'Something’s wrong with this link. Make sure you’ve copied the whole thing.'
        }
        raise InvalidRequest(errors, status_code=400)

    if invitation_type == 'service':
        invited_user = get_invited_user_by_id(invited_user_id)
        return jsonify(data=invited_user_schema.dump(invited_user).data), 200
    elif invitation_type == 'organisation':
        invited_user = dao_get_invited_organisation_user(invited_user_id)
        return jsonify(data=invited_user.serialize()), 200
    else:
        raise InvalidRequest(
            "Unrecognised invitation type: {}".format(invitation_type))
コード例 #2
0
ファイル: rest.py プロジェクト: cds-snc/notification-api
def validate_invitation_token(invitation_type, token):

    max_age_seconds = 60 * 60 * 24 * current_app.config[
        "INVITATION_EXPIRATION_DAYS"]

    try:
        invited_user_id = check_token(
            token,
            current_app.config["SECRET_KEY"],
            current_app.config["DANGEROUS_SALT"],
            max_age_seconds,
        )
    except SignatureExpired:
        errors = {"invitation": "invitation expired"}
        raise InvalidRequest(errors, status_code=400)
    except BadData:
        errors = {"invitation": "bad invitation link"}
        raise InvalidRequest(errors, status_code=400)

    if invitation_type == "service":
        invited_user = get_invited_user_by_id(invited_user_id)
        return jsonify(data=invited_user_schema.dump(invited_user).data), 200
    elif invitation_type == "organisation":
        invited_user = dao_get_invited_organisation_user(invited_user_id)
        return jsonify(data=invited_user.serialize()), 200
    else:
        raise InvalidRequest(
            "Unrecognised invitation type: {}".format(invitation_type))
コード例 #3
0
ファイル: rest.py プロジェクト: alphagov/notifications-api
def get_invited_user_by_token(token):

    max_age_seconds = 60 * 60 * 24 * current_app.config['INVITATION_EXPIRATION_DAYS']

    try:
        invited_user_id = check_token(token,
                                      current_app.config['SECRET_KEY'],
                                      current_app.config['DANGEROUS_SALT'],
                                      max_age_seconds)
    except SignatureExpired:
        errors = {'invitation':
                  ['Your invitation to GOV.UK Notify has expired. '
                   'Please ask the person that invited you to send you another one']}
        raise InvalidRequest(errors, status_code=400)

    invited_user = get_invited_user_by_id(invited_user_id)

    return jsonify(data=invited_user_schema.dump(invited_user).data), 200
コード例 #4
0
ファイル: rest.py プロジェクト: Djuka/notifications-api-1
def get_invited_user(invited_user_id):
    invited_user = get_invited_user_by_id(invited_user_id)
    return jsonify(data=invited_user_schema.dump(invited_user).data), 200
コード例 #5
0
def test_get_invited_user_by_id(notify_db, notify_db_session,
                                sample_invited_user):
    from_db = get_invited_user_by_id(sample_invited_user.id)
    assert from_db == sample_invited_user
コード例 #6
0
def test_get_invited_user_by_id(notify_db, notify_db_session, sample_invited_user):
    from_db = get_invited_user_by_id(sample_invited_user.id)
    assert from_db == sample_invited_user