Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[myslice.git] / localauth / manifoldbackend.py
index 4889d34..504a85b 100644 (file)
@@ -7,6 +7,10 @@ from manifold.core.query        import Query
 
 from myslice.settings import config, logger, DEBUG
 
+from portal.actions import authority_check_pis
+
+# from unfold.sessioncache import SessionCache
+
 # Name my backend 'ManifoldBackend'
 class ManifoldBackend:
 
@@ -29,12 +33,13 @@ class ManifoldBackend:
             sessions = sessions_result.ok_value()
             if not sessions:
                 logger.error("GetSession failed: {}".format(sessions_result.error()))
-                return
+                return None
             session = sessions[0]
-            logger.debug("SESSION : {}".format(session))
+            logger.debug("SESSION : {}".format(session.keys()))
             
             # Change to session authentication
             api.auth = {'AuthMethod': 'session', 'session': session['session']}
+            #api.auth = session_auth
             self.api = api
 
             # Get account details
@@ -43,13 +48,17 @@ class ManifoldBackend:
             persons = persons_result.ok_value()
             if not persons:
                 logger.error("GetPersons failed: {}".format(persons_result.error()))
-                return
+                return None
             person = persons[0]
             logger.debug("PERSON : {}".format(person))
+            
+            request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']}
+
             #logger.info("{} {} <{}> logged in"\
             #    .format(person['config']['first_name'], person['config']['last_name'], person['config']['email']))
 
-            request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']}
+            #SessionCache().store_auth(request, session_auth)
+
         except ManifoldException as e:
             logger.error("ManifoldException in Auth Backend: {}".format(e.manifold_result))
         except Exception as e:
@@ -71,6 +80,8 @@ class ManifoldBackend:
         if 'lastname' in person:
             user.last_name = person['lastname']
 
+        user.pi = authority_check_pis (request, user.email)
+        request.session['user'] = {'email':user.email,'pi':user.pi,'firstname':user.first_name,'lastname':user.last_name}
         return user
 
     # Required for your backend to work properly - unchanged in most scenarios