Browse Source

Added the AuthenticationError raises in the filesystem session plugins main.py

Roland Haroutiounian 8 years ago
parent
commit
92c12150f2
1 changed files with 14 additions and 3 deletions
  1. 14
    3
      plugins/filesystem_session/main.py

+ 14
- 3
plugins/filesystem_session/main.py View File

4
 import pickle
4
 import pickle
5
 import uuid
5
 import uuid
6
 
6
 
7
+from lodel.auth.exceptions import AuthenticationError
7
 from lodel.plugin import LodelHook
8
 from lodel.plugin import LodelHook
8
 from lodel.settings import Settings
9
 from lodel.settings import Settings
9
 from lodel.utils.datetime import get_utc_timestamp
10
 from lodel.utils.datetime import get_utc_timestamp
46
     session_file_path = get_session_file_path(sid)
47
     session_file_path = get_session_file_path(sid)
47
     if os.path.isfile(session_file_path):
48
     if os.path.isfile(session_file_path):
48
         os.unlink(session_file_path)
49
         os.unlink(session_file_path)
50
+    else:
51
+        raise AuthenticationError("No session file found for the sid : %s" % sid)
49
 
52
 
50
 
53
 
51
 ## @brief checks if a session file has expired
54
 ## @brief checks if a session file has expired
53
 # @return bool
56
 # @return bool
54
 def is_session_file_expired(sid):
57
 def is_session_file_expired(sid):
55
     session_file = get_session_file_path(sid)
58
     session_file = get_session_file_path(sid)
59
+
60
+    if not os.path.isfile(session_file):
61
+        raise AuthenticationError("No session file found for the sid : %s" % sid)
62
+
56
     expiration_timestamp = os.stat(session_file).st_mtime + SESSION_EXPIRATION_LIMIT
63
     expiration_timestamp = os.stat(session_file).st_mtime + SESSION_EXPIRATION_LIMIT
57
     timestamp_now = get_utc_timestamp()
64
     timestamp_now = get_utc_timestamp()
58
     return timestamp_now >= expiration_timestamp
65
     return timestamp_now >= expiration_timestamp
64
 @LodelHook('session_read')
71
 @LodelHook('session_read')
65
 def read_session(caller, sid):
72
 def read_session(caller, sid):
66
     session_file = get_session_file_path(sid)
73
     session_file = get_session_file_path(sid)
67
-    if os.path.isfile(session_file) and not is_session_file_expired(sid):
68
-        session = pickle.load(open(session_file, "rb"))
74
+    if os.path.isfile(session_file):
75
+        if not is_session_file_expired(sid):
76
+            session = pickle.load(open(session_file, "rb"))
77
+        else:
78
+            LodelHook.call_hook('session_stop', __file__, sid)
79
+            session = {}
69
     else:
80
     else:
70
-        session = None
81
+        raise AuthenticationError("No session file found for the sid : %s" % sid)
71
 
82
 
72
     return session
83
     return session
73
 
84
 

Loading…
Cancel
Save