Bladeren bron

Merge branch 'newlodel' of git.labocleo.org:lodel2 into newlodel

prieto 8 jaren geleden
bovenliggende
commit
7fa0c9f8ea
1 gewijzigde bestanden met toevoegingen van 27 en 31 verwijderingen
  1. 27
    31
      lodel/auth/session.py

+ 27
- 31
lodel/auth/session.py Bestand weergeven

@@ -11,7 +11,20 @@ class SessionStore(ABC):
11 11
 
12 12
     expiration_limit = 900
13 13
 
14
-    # === ABSTRACT METHODS === #
14
+    ## @brief Generates a session unique ID
15
+    # @param cls
16
+    # @return str
17
+    @classmethod
18
+    def generate_new_sid(cls):
19
+        return uuid1()
20
+
21
+    ## @brief Creates a new session
22
+    # @param content dict : session content (default: {})
23
+    # @return str
24
+    def create_new_session(self, content={}):
25
+        sid = self.__class__.generate_new_sid()
26
+        self.save_session(sid, content)
27
+        return sid
15 28
 
16 29
     ## @brief Destroys a session
17 30
     # @param sid str : session id
@@ -26,12 +39,6 @@ class SessionStore(ABC):
26 39
     def read_session(self, sid):
27 40
         return {}
28 41
 
29
-    ## @brief lists all the sessions ids
30
-    # @return list
31
-    @abstractmethod
32
-    def list_all_sessions(self):
33
-        return []
34
-
35 42
     ## @brief saves a session to a file
36 43
     # @param sid str : session id
37 44
     # @param session dict : content to be saved
@@ -39,6 +46,19 @@ class SessionStore(ABC):
39 46
     def save_session(self, sid, session):
40 47
         pass
41 48
 
49
+    ## @brief lists all the sessions ids
50
+    # @return list
51
+    @abstractmethod
52
+    def list_all_sessions(self):
53
+        return []
54
+
55
+    ## @brief cleans the session store's by destroying the expired sessions
56
+    def clean(self):
57
+        sessions_list = self.list_all_sessions()
58
+        for sid in sessions_list:
59
+            if self.has_session_expired(sid):
60
+                self.delete_session(sid)
61
+
42 62
     ## @brief checks if a session exists
43 63
     # @param sid str : session id
44 64
     # @return bool
@@ -53,23 +73,6 @@ class SessionStore(ABC):
53 73
     def get_session_last_modified(self, sid):
54 74
         pass
55 75
 
56
-    # === IMPLEMENTED METHODS === #
57
-
58
-    ## @brief Generates a session unique ID
59
-    # @param cls
60
-    # @return str
61
-    @classmethod
62
-    def generate_new_sid(cls):
63
-        return uuid1()
64
-
65
-    ## @brief Creates a new session
66
-    # @param content dict : session content (default: {})
67
-    # @return str
68
-    def create_new_session(self, content={}):
69
-        sid = self.__class__.generate_new_sid()
70
-        self.save_session(sid, content)
71
-        return sid
72
-
73 76
     ## @brief checks if a session has expired
74 77
     # @param sid str: session id
75 78
     # @return bool
@@ -79,13 +82,6 @@ class SessionStore(ABC):
79 82
         now_timestamp = get_utc_timestamp()
80 83
         return now_timestamp > expiration_timestamp
81 84
 
82
-    ## @brief cleans the session store's by destroying the expired sessions
83
-    def clean(self):
84
-        sessions_list = self.list_all_sessions()
85
-        for sid in sessions_list:
86
-            if self.has_session_expired(sid):
87
-                self.delete_session(sid)
88
-
89 85
     ## @brief updates a session's content
90 86
     # @param sid str : session's id
91 87
     # @param content dict : items to update with their new value

Loading…
Annuleren
Opslaan