|
|
@ -12,14 +12,14 @@ from atheneum.authentication import ( |
|
|
|
api_blueprint = Blueprint(name='api', import_name=__name__, url_prefix='/api') |
|
|
|
|
|
|
|
|
|
|
|
class APIMessage(NamedTuple): |
|
|
|
class APIResponse(NamedTuple): |
|
|
|
payload: Any |
|
|
|
status: int |
|
|
|
|
|
|
|
|
|
|
|
def return_json(func: Callable) -> Callable: |
|
|
|
""" |
|
|
|
if a Response object is not returned, jsonify the result and return it |
|
|
|
If an Response object is not returned, jsonify the result and return it |
|
|
|
:param func: |
|
|
|
:return: |
|
|
|
""" |
|
|
@ -29,7 +29,7 @@ def return_json(func: Callable) -> Callable: |
|
|
|
result = func(*args, **kwargs) |
|
|
|
if isinstance(result, Response): |
|
|
|
return result |
|
|
|
if isinstance(result, APIMessage): |
|
|
|
if isinstance(result, APIResponse): |
|
|
|
return jsonify(result.payload), result.status |
|
|
|
return jsonify(result) |
|
|
|
|
|
|
@ -39,35 +39,33 @@ def return_json(func: Callable) -> Callable: |
|
|
|
@api_blueprint.route('/login', methods=['POST']) |
|
|
|
@return_json |
|
|
|
@require_basic_auth |
|
|
|
def login() -> APIMessage: |
|
|
|
def login() -> APIResponse: |
|
|
|
""" |
|
|
|
Get a token for continued authentication |
|
|
|
:return: A login token for continued authentication |
|
|
|
""" |
|
|
|
token = generate_token() |
|
|
|
response = APIMessage(token, 200) |
|
|
|
return response |
|
|
|
return APIResponse({'token': token}, 200) |
|
|
|
|
|
|
|
|
|
|
|
@api_blueprint.route('/login/bump', methods=['POST']) |
|
|
|
@return_json |
|
|
|
@require_token_auth |
|
|
|
def login_bump() -> APIMessage: |
|
|
|
def login_bump() -> APIResponse: |
|
|
|
""" |
|
|
|
Update the user last seen timestamp |
|
|
|
:return: A time stamp for the bumped login |
|
|
|
""" |
|
|
|
response = APIMessage(None, 200) |
|
|
|
return response |
|
|
|
return APIResponse(None, 200) |
|
|
|
|
|
|
|
|
|
|
|
@api_blueprint.route('/logout', methods=['POST']) |
|
|
|
@return_json |
|
|
|
@require_token_auth |
|
|
|
def logout() -> APIMessage: |
|
|
|
def logout() -> APIResponse: |
|
|
|
""" |
|
|
|
logout and delete a token |
|
|
|
:return: |
|
|
|
""" |
|
|
|
session.pop('user') |
|
|
|
return APIMessage(None, 200) |
|
|
|
return APIResponse(None, 200) |