Browse Source

Modified filesystem_session plugin + start using sessions in client

Yann Weber 8 years ago
parent
commit
ba244bdd82
3 changed files with 25 additions and 23 deletions
  1. 2
    2
      lodel/auth/client.py
  2. 2
    2
      lodel/auth/session.py
  3. 21
    19
      plugins/filesystem_session/main.py

+ 2
- 2
lodel/auth/client.py View File

@@ -5,6 +5,7 @@ import copy
5 5
 from lodel.settings import Settings
6 6
 from lodel import logger
7 7
 from lodel.plugin.hooks import LodelHook
8
+from lodel.plugin import SessionHandlerPlugin as SessionHandler
8 9
 
9 10
 ##@brief Client metaclass designed to implements container accessor on 
10 11
 #Client Class
@@ -23,7 +24,7 @@ class ClientMetaclass(type):
23 24
 
24 25
     def __setitem__(self, key, value):
25 26
         if SESSION_ID_NAME not in self.__session:
26
-            self.__session[SESSION_ID_NAME] = generate_token()
27
+            self.__session[SESSION_ID_NAME] = SessionHandler.start_session()
27 28
         self.__session[key] = value
28 29
     
29 30
     ##@brief Return a copy of sessions infos
@@ -77,7 +78,6 @@ class Client(object, metaclass = ClientMetaclass):
77 78
         ##@brief Stores infos for authenticated users (None == anonymous)
78 79
         self.__user = None
79 80
         ##@brief Stores the session handler
80
-        self._session_handler = 
81 81
         Client._instance = self
82 82
         logger.debug("New client : %s" % self)
83 83
     

+ 2
- 2
lodel/auth/session.py View File

@@ -5,7 +5,7 @@ from uuid import uuid1
5 5
 
6 6
 from werkzeug.contrib.sessions import generate_key, Session
7 7
 
8
-from lodel.auth.exceptions import AuthenticationError
8
+#from lodel.auth.exceptions import AuthenticationError
9 9
 from lodel.utils.datetime import get_utc_timestamp
10 10
 
11 11
 
@@ -123,7 +123,7 @@ class LodelSession(ABC):
123 123
     ## @brief deletes a given key in the session
124 124
     # @param key str
125 125
     def delete_key(self, key):
126
-        delattr(p_object=self, key)
126
+        delattr(self, key)
127 127
         self.save()
128 128
 
129 129
     ## @brief lists all the sessions in the session store

+ 21
- 19
plugins/filesystem_session/main.py View File

@@ -1,7 +1,5 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-"""
4
-from lodel.auth.exceptions import AuthenticationError
5 3
 from lodel.plugin import LodelHook
6 4
 
7 5
 from .filesystem_session_store import FileSystemSession
@@ -10,33 +8,37 @@ from .filesystem_session_store import FileSystemSession
10 8
 # @param caller *
11 9
 # @param payload dict
12 10
 # @return str
13
-@LodelHook('session_start')
14
-def start_session(caller, payload):
15
-    new_session = FileSystemSession(content=payload)
11
+def start_session():
12
+    new_session = FileSystemSession()
16 13
     return new_session.sid
17 14
 
18
-'''
19 15
 ## @brief destroys a session
20 16
 # @param caller *
21 17
 # @param sid str : session id
22
-@LodelHook('session_destroy')
23
-def stop_session(caller, sid):
18
+def destroy_session(sid):
24 19
     FileSystemSession.destroy(sid)
25
-'''
26 20
 
27 21
 ## @brief reads a session content
28 22
 # @param caller *
29 23
 # @param sid str: session id
30 24
 # @return FileSystemSession
31
-@LodelHook('session_load')
32
-def read_session(caller, sid):
25
+def restore_session(sid):
33 26
     return FileSystemSession.load(sid)
34 27
 
35
-'''
36
-## @brief destroys all the old sessions (expired ones)
37
-# @param caller *
38
-@LodelHook('session_clean')
39
-def clean_sessions(caller):
40
-    FileSystemSession.clean()
41
-'''
42
-"""
28
+##@brief Set a session value
29
+#@param name str : session variable name
30
+#@param value mixed : session variable value
31
+def set_value(name, value):
32
+    pass
33
+
34
+##@brief Get a session value
35
+#@param name str : the session variable name
36
+#@return the value
37
+def get_value(name):
38
+    pass
39
+
40
+##@brief Delete a session value
41
+#@param name str : the session variable name
42
+def del_value(name):
43
+    pass
44
+    

Loading…
Cancel
Save