X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=auth%2Fmanifoldbackend.py;h=ab224a35b44ea3831c88198459b745763fb98211;hb=36f0a2f013dc861c84f2f2781ccffa05228759a7;hp=da3c23f93b545dee7e6b6d2e087ae67749148ecd;hpb=bbdf40b4dd1bebc81461f1c9294aca95323bf889;p=myslice.git diff --git a/auth/manifoldbackend.py b/auth/manifoldbackend.py index da3c23f9..ab224a35 100644 --- a/auth/manifoldbackend.py +++ b/auth/manifoldbackend.py @@ -1,10 +1,9 @@ -# 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, ManifoldException, ManifoldResult +from manifold.core.query import Query # Name my backend 'ManifoldBackend' class ManifoldBackend: @@ -22,25 +21,38 @@ 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 - - request.session['manifold_session'] = session - #self.session = session - # Change GetSession() at some point to return expires as well - expires = time.time() + (24 * 60 * 60) + sessions_result = api.forward(Query.create('local:session').to_dict()) + print "result" + sessions = sessions_result.ok_value() + print "ok" + if not sessions: + print "GetSession failed", sessions_result.error() + return + print "first", sessions + session = sessions[0] # Change to session authentication - api.auth = {'AuthMethod': 'session', 'session': session} - #self.api = api + api.auth = {'AuthMethod': 'session', 'session': session['session']} + self.api = api # Get account details - person = api.GetPersons(auth)[0] - request.session['manifold_person'] = person - #self.person = person[0] - except: + # the new API would expect Get('local:user') instead + persons_result = api.forward(Query.get('local:user').to_dict()) + persons = persons_result.ok_value() + if not persons: + print "GetPersons failed",persons_result.error() + return + person = persons[0] + print "PERSON=", person + + request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']} + except ManifoldException, e: + print "ManifoldBackend.authenticate caught ManifoldException, returning corresponding ManifoldResult" + return e.manifold_result + except Exception, e: + print "E: manifoldbackend", e + import traceback + traceback.print_exc() return None try: @@ -49,8 +61,8 @@ class ManifoldBackend: except User.DoesNotExist: # Create a user in Django's local database user = User.objects.create_user(username, username, 'passworddoesntmatter') - user.first_name = person['first_name'] - user.last_name = person['last_name'] + user.first_name = "DUMMY_FIRST_NAME" #person['first_name'] + user.last_name = "DUMMY LAST NAME" # person['last_name'] user.email = person['email'] return user