暫無描述
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.

main.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. from lodel.auth.exceptions import AuthenticationError
  3. from lodel.plugin import LodelHook
  4. from .filesystem_session_store import FileSystemSessionStore
  5. session_store = FileSystemSessionStore()
  6. ## @brief starts a new session and returns its sid
  7. # @param caller *
  8. # @param payload dict
  9. # @return str
  10. @LodelHook('session_start')
  11. def start_session(caller, payload):
  12. return session_store.create_new_session(payload)
  13. ## @brief destroys a session
  14. # @param caller *
  15. # @param sid str : session id
  16. @LodelHook('session_destroy')
  17. def stop_session(caller, sid):
  18. session_store.delete_session(sid)
  19. ## @brief reads a session content
  20. # @param caller *
  21. # @param sid str: session id
  22. # @return dict
  23. @LodelHook('session_load')
  24. def read_session(caller, sid):
  25. return session_store.get_session(sid)
  26. ## @brief destroys all the old sessions (expired ones)
  27. # @param caller *
  28. @LodelHook('session_clean')
  29. def clean_sessions(caller):
  30. session_store.clean()
  31. ## @brief updates the content of the session
  32. # @param caller *
  33. # @param payload dict : datas to insert/update in the session
  34. @LodelHook('update_session')
  35. def update_session_content(caller, payload):
  36. if 'sid' in payload:
  37. sid = payload['sid']
  38. del payload['sid']
  39. session_store.update_session(sid, payload)
  40. else:
  41. raise AuthenticationError("Session Update: Missing sid (session id) in the given payload argument")