Browse Source

Plug webui to auth

- Implemeting Client in plugins/webui/client.py
- Calling client in run.py
Yann Weber 8 years ago
parent
commit
d2eef44ca7
3 changed files with 51 additions and 12 deletions
  1. 33
    11
      lodel/auth/auth.py
  2. 11
    0
      plugins/webui/client.py
  3. 7
    1
      plugins/webui/run.py

+ 33
- 11
lodel/auth/auth.py View File

@@ -29,6 +29,7 @@ class Client(object):
29 29
             del(old)
30 30
             logger.debug("Replacing old Client instance by a new one")
31 31
         Client._instance = self
32
+        logger.debug("New client : %s" % self)
32 33
 
33 34
         # Instanciation done. Triggering Auth instanciation
34 35
         self.__auth = Auth(self)
@@ -57,6 +58,18 @@ class Client(object):
57 58
 instance exists")
58 59
         return cls._instance
59 60
     
61
+    ##@brief Alias of Client::destroy()
62
+    @classmethod
63
+    def deauth(cls):
64
+        cls.destroy()
65
+    
66
+    ##@brief Destroy current client
67
+    @classmethod
68
+    def destroy(cls):
69
+        inst = cls._instance
70
+        cls._instance = None
71
+        del(inst)
72
+
60 73
     ##@brief Authenticate using login an password
61 74
     #@note Wrapper on Auth.auth()
62 75
     #@param login str
@@ -160,20 +173,24 @@ class Auth(object):
160 173
         # Singleton
161 174
         if self._instance is not None:
162 175
             bck = self._instance
176
+            bck.destroy()
163 177
             self._instance = None
164
-            del(bck)
165 178
             logger.debug("Previous Auth instance replaced by a new one")
166 179
         else:
167 180
             #First instance, fetching settings
168 181
             self.fetch_settings()
169 182
         self.__class__._instance = self
170
-        
171
-    ##@brief Instance destructor
172
-    def __del__(self):
183
+    
184
+    ##@brief Destroy current instance an associated session
185
+    def _destroy(self):
173 186
         self.__user_infos = LodelHook.call_hook('lodel2_session_destroy',
174
-            caller = self, payload = token)  # TODO unresolved variable
175
-        pass
187
+            caller = self, payload = self.__session_id)
176 188
     
189
+    ##@brief Destroy singleton instance
190
+    @classmethod
191
+    def destroy(cls):
192
+        cls._instance._destroy()
193
+
177 194
     ##@brief Raise exception because of authentication failure
178 195
     #@note trigger a security log containing client infos
179 196
     #@throw LodelFatalError if no instance exsists
@@ -194,20 +211,25 @@ class Auth(object):
194 211
             #Allready fetched
195 212
             return
196 213
         infos = (
197
-            Settings.auth.login_classfield.split('.'),
198
-            Settings.auth.pass_classfield.split('.'))
214
+            Settings.auth.login_classfield,
215
+            Settings.auth.pass_classfield)
199 216
         res_infos = []
200 217
         for clsname, fieldname in infos:
218
+<<<<<<< HEAD
201 219
             res_infos.append((
202 220
                 dyncode.lowername2class(infos[0]),
203 221
                 dcls.field(infos[1])))  # TODO cls.field ?
222
+=======
223
+            dcls = dyncode.lowername2class(infos[0][0])
224
+            res_infos.append((dcls, infos[1][1]))
225
+>>>>>>> Plug webui to auth
204 226
 
205 227
         link_field = None
206
-        if res_infos[0][0] != res_infos[0][1]:
228
+        if res_infos[0][0] != res_infos[1][0]:
207 229
             # login and password are in two separated EmClass
208 230
             # determining the field that links login EmClass to password
209 231
             # EmClass
210
-            for fname, fdh in res_infos[0][0].fields(True):
232
+            for fname, fdh in res_infos[0][0].fields(True).items():
211 233
                 if fdh.is_reference() and res_infos[1][0] in fdh.linked_classes():
212 234
                     link_field = fname
213 235
             if link_field is None:
@@ -243,7 +265,7 @@ login EmClass '%s' and password EmClass '%s'. Abording..." % (
243 265
             login_cls = infos['login'][0]
244 266
             pass_cls = infos['pass'][0]
245 267
             qfilter = "passfname = passhash"
246
-            uid_fname = login_cls.uid_fieldname()[0] #COMPOSED UID BROKEN
268
+            uid_fname = login_cls.uid_fieldname()[0] #COMPOSED UID BROKEN
247 269
             if login_cls == pass_cls:
248 270
                 #Same EmClass for login & pass
249 271
                 qfilter = qfilter.format(

+ 11
- 0
plugins/webui/client.py View File

@@ -0,0 +1,11 @@
1
+from lodel.auth.auth import Client
2
+
3
+class WebUiClient(Client):
4
+    
5
+    def __init__(self, ip, user_agent):
6
+        self.__ip = ip
7
+        self.__user_agent = user_agent
8
+        super().__init__()
9
+
10
+    def __str__(self):
11
+        return "%s (%s)" % (self.__ip, self.__user_agent)

+ 7
- 1
plugins/webui/run.py View File

@@ -9,6 +9,7 @@ from lodel.settings import Settings
9 9
 from .interface.router import get_controller
10 10
 from .interface.lodelrequest import LodelRequest
11 11
 from .exceptions import *
12
+from .client import WebUiClient
12 13
 from lodel.utils.datetime import get_utc_timestamp
13 14
 from lodel.plugin.hooks import LodelHook
14 15
 
@@ -20,6 +21,10 @@ session_store = FilesystemSessionStore(path=SESSION_FILES_BASE_DIR, filename_tem
20 21
 
21 22
 #Starting instance
22 23
 loader.start()
24
+#providing access to dyncode
25
+import lodel
26
+import leapi_dyncode as dyncode
27
+lodel.dyncode = dyncode
23 28
 
24 29
 # TODO déplacer dans un module "sessions.py"
25 30
 def delete_old_session_files(timestamp_now):
@@ -44,6 +49,7 @@ def is_session_file_expired(timestamp_now, sid):
44 49
 
45 50
 # WSGI Application
46 51
 def application(env, start_response):
52
+    WebUiClient(env['REMOTE_ADDR'], env['HTTP_USER_AGENT'])
47 53
     current_timestamp = get_utc_timestamp()
48 54
     delete_old_session_files(current_timestamp)
49 55
     request = LodelRequest(env)
@@ -76,5 +82,5 @@ def application(env, start_response):
76 82
         response.set_cookie('sid', request.session.sid)
77 83
     
78 84
     res = response(env, start_response)
79
-    LodelHook.call_hook('lodel2_session_end', __file__, None)
85
+    WebUiClient.destroy()
80 86
     return res

Loading…
Cancel
Save