An ebook/comic library service and web client
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
"""
Authentication API blueprint and endpoint definitions """
from flask import Blueprint, g
from atheneum.api.decorators import return_json from atheneum.api.model import APIResponse from atheneum.middleware import authentication_middleware from atheneum.service import user_token_service, authentication_service
AUTH_BLUEPRINT = Blueprint( name='auth', import_name=__name__, url_prefix='/auth')
@AUTH_BLUEPRINT.route('/login', methods=['POST']) @return_json @authentication_middleware.require_basic_auth def login() -> APIResponse: """
Get a token for continued authentication :return: A login token for continued authentication """
user_token = user_token_service.create(g.user) return APIResponse({'token': user_token.token}, 200)
@AUTH_BLUEPRINT.route('/bump', methods=['POST']) @return_json @authentication_middleware.require_token_auth def login_bump() -> APIResponse: """
Update the user last seen timestamp :return: A time stamp for the bumped login """
authentication_service.bump_login(g.user) return APIResponse({'last_login_time': g.user.last_login_time}, 200)
@AUTH_BLUEPRINT.route('/logout', methods=['POST']) @return_json @authentication_middleware.require_token_auth def logout() -> APIResponse: """
logout and delete a token :return: """
authentication_service.logout(g.user_token) return APIResponse(None, 200)
|