|
@@ -4,6 +4,7 @@ import os
|
4
|
4
|
import pickle
|
5
|
5
|
import uuid
|
6
|
6
|
|
|
7
|
+from lodel.auth.exceptions import AuthenticationError
|
7
|
8
|
from lodel.plugin import LodelHook
|
8
|
9
|
from lodel.settings import Settings
|
9
|
10
|
from lodel.utils.datetime import get_utc_timestamp
|
|
@@ -46,6 +47,8 @@ def stop_session(caller, sid):
|
46
|
47
|
session_file_path = get_session_file_path(sid)
|
47
|
48
|
if os.path.isfile(session_file_path):
|
48
|
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
|
54
|
## @brief checks if a session file has expired
|
|
@@ -53,6 +56,10 @@ def stop_session(caller, sid):
|
53
|
56
|
# @return bool
|
54
|
57
|
def is_session_file_expired(sid):
|
55
|
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
|
63
|
expiration_timestamp = os.stat(session_file).st_mtime + SESSION_EXPIRATION_LIMIT
|
57
|
64
|
timestamp_now = get_utc_timestamp()
|
58
|
65
|
return timestamp_now >= expiration_timestamp
|
|
@@ -64,10 +71,14 @@ def is_session_file_expired(sid):
|
64
|
71
|
@LodelHook('session_read')
|
65
|
72
|
def read_session(caller, sid):
|
66
|
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
|
80
|
else:
|
70
|
|
- session = None
|
|
81
|
+ raise AuthenticationError("No session file found for the sid : %s" % sid)
|
71
|
82
|
|
72
|
83
|
return session
|
73
|
84
|
|