signals.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from flask.signals import Namespace
  2. _signals = Namespace()
  3. #: Sent when a user is logged in. In addition to the app (which is the
  4. #: sender), it is passed `user`, which is the user being logged in.
  5. user_logged_in = _signals.signal("logged-in")
  6. #: Sent when a user is logged out. In addition to the app (which is the
  7. #: sender), it is passed `user`, which is the user being logged out.
  8. user_logged_out = _signals.signal("logged-out")
  9. #: Sent when the user is loaded from the cookie. In addition to the app (which
  10. #: is the sender), it is passed `user`, which is the user being reloaded.
  11. user_loaded_from_cookie = _signals.signal("loaded-from-cookie")
  12. #: Sent when the user is loaded from the header. In addition to the app (which
  13. #: is the #: sender), it is passed `user`, which is the user being reloaded.
  14. _user_loaded_from_header = _signals.signal("loaded-from-header")
  15. #: Sent when the user is loaded from the request. In addition to the app (which
  16. #: is the #: sender), it is passed `user`, which is the user being reloaded.
  17. user_loaded_from_request = _signals.signal("loaded-from-request")
  18. #: Sent when a user's login is confirmed, marking it as fresh. (It is not
  19. #: called for a normal login.)
  20. #: It receives no additional arguments besides the app.
  21. user_login_confirmed = _signals.signal("login-confirmed")
  22. #: Sent when the `unauthorized` method is called on a `LoginManager`. It
  23. #: receives no additional arguments besides the app.
  24. user_unauthorized = _signals.signal("unauthorized")
  25. #: Sent when the `needs_refresh` method is called on a `LoginManager`. It
  26. #: receives no additional arguments besides the app.
  27. user_needs_refresh = _signals.signal("needs-refresh")
  28. #: Sent whenever the user is accessed/loaded
  29. #: receives no additional arguments besides the app.
  30. user_accessed = _signals.signal("accessed")
  31. #: Sent whenever session protection takes effect, and a session is either
  32. #: marked non-fresh or deleted. It receives no additional arguments besides
  33. #: the app.
  34. session_protected = _signals.signal("session-protected")
  35. def __getattr__(name):
  36. if name == "user_loaded_from_header":
  37. import warnings
  38. warnings.warn(
  39. "'user_loaded_from_header' is deprecated and will be"
  40. " removed in Flask-Login 0.7. Use"
  41. " 'user_loaded_from_request' instead.",
  42. DeprecationWarning,
  43. stacklevel=2,
  44. )
  45. return _user_loaded_from_header
  46. raise AttributeError(name)