A multipurpose python flask API server and administration SPA
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.

45 lines
1.3 KiB

  1. from flask import Blueprint, g
  2. from corvus.api.decorators import return_json
  3. from corvus.api.model import APIResponse
  4. from corvus.middleware import authentication_middleware
  5. from corvus.service import user_token_service, authentication_service
  6. auth_blueprint = Blueprint(
  7. name='auth', import_name=__name__, url_prefix='/auth')
  8. @auth_blueprint.route('/login', methods=['POST'])
  9. @return_json
  10. @authentication_middleware.require_basic_auth
  11. def login() -> APIResponse:
  12. """
  13. Get a token for continued authentication
  14. :return: A login token for continued authentication
  15. """
  16. user_token = user_token_service.create(g.user)
  17. return APIResponse({'token': user_token.token}, 200)
  18. @auth_blueprint.route('/bump', methods=['POST'])
  19. @return_json
  20. @authentication_middleware.require_token_auth
  21. def login_bump() -> APIResponse:
  22. """
  23. Update the user last seen timestamp
  24. :return: A time stamp for the bumped login
  25. """
  26. authentication_service.bump_login(g.user)
  27. return APIResponse({'last_login_time': g.user.last_login_time}, 200)
  28. @auth_blueprint.route('/logout', methods=['POST'])
  29. @return_json
  30. @authentication_middleware.require_token_auth
  31. def logout() -> APIResponse:
  32. """
  33. logout and delete a token
  34. :return:
  35. """
  36. authentication_service.logout(g.user_token)
  37. return APIResponse(None, 200)