Browse Source

server: Return a dict for the login

merge-requests/1/head
Drew Short 7 years ago
parent
commit
9d38c982fa
  1. 20
      server/atheneum/api.py

20
server/atheneum/api.py

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