mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-22 16:31:15 -05:00
[WIP] Start of api for accepting invite.
This commit is contained in:
41
app/accept_invite/rest.py
Normal file
41
app/accept_invite/rest.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from flask import (
|
||||
Blueprint,
|
||||
jsonify,
|
||||
current_app
|
||||
)
|
||||
|
||||
from itsdangerous import SignatureExpired
|
||||
|
||||
from utils.url_safe_token import check_token
|
||||
|
||||
from app.dao.invited_user_dao import get_invited_user_by_id
|
||||
|
||||
from app.errors import register_errors
|
||||
from app.schemas import invited_user_schema
|
||||
|
||||
|
||||
accept_invite = Blueprint('accept_invite', __name__)
|
||||
register_errors(accept_invite)
|
||||
|
||||
|
||||
@accept_invite.route('/<token>', methods=['GET'])
|
||||
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:
|
||||
message = 'Invitation with id {} expired'.format(invited_user_id)
|
||||
return jsonify(result='error', message=message), 400
|
||||
|
||||
invited_user = get_invited_user_by_id(invited_user_id)
|
||||
|
||||
if not invited_user:
|
||||
message = 'Invited user not found with id: {}'.format(invited_user_id)
|
||||
return jsonify(result='error', message=message), 404
|
||||
|
||||
return jsonify(data=invited_user_schema.dump(invited_user).data), 200
|
||||
Reference in New Issue
Block a user