we embed the (currently raw) results from manifold API in a ManifoldResult dict
[myslice.git] / auth / manifoldbackend.py
index da3c23f..2b1bde5 100644 (file)
@@ -1,10 +1,8 @@
-# import the User object
+import time
+
 from django.contrib.auth.models import User
-from engine.manifoldapi import ManifoldAPI
 
-
-# import time - this is used to create Django's internal username
-import time
+from manifold.manifoldapi import ManifoldAPI, ManifoldResult
 
 # Name my backend 'ManifoldBackend'
 class ManifoldBackend:
@@ -23,23 +21,30 @@ class ManifoldBackend:
             auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password}
             api = ManifoldAPI(auth)
             # Authenticate user and get session key
-            session = api.GetSession()
-            if not session : 
-                return None
+            session_result = api.GetSession()
+            session = session_result.ok_value()
+            if not session:
+                print "GetSession failed",session_result.error()
+                return
             
-            request.session['manifold_session'] = session
+            print 'DEALING with session',session
             #self.session = session
             # Change GetSession() at some point to return expires as well
             expires = time.time() + (24 * 60 * 60)
 
             # Change to session authentication
             api.auth = {'AuthMethod': 'session', 'session': session}
-            #self.api = api
+            self.api = api
 
             # Get account details
-            person = api.GetPersons(auth)[0]
-            request.session['manifold_person'] = person
-            #self.person = person[0]
+            persons_result = api.GetPersons(auth)
+            persons = persons_result.ok_value()
+            if not persons:
+                print "GetPersons failed",persons_result.error()
+                return
+            person = persons[0]
+
+            request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': expires}
         except:
             return None