X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=auth%2Fmanifoldbackend.py;h=afb87821930813087c98d5793e21ea3cef8b1018;hb=9e2d1ca41dd8a9e076ecaff432f8ebe8578ee2c5;hp=f763291a84b5d72558915f63232fff4965de03e6;hpb=4e348dd653e2f7124550f153a30744293eab3b2f;p=unfold.git diff --git a/auth/manifoldbackend.py b/auth/manifoldbackend.py index f763291a..afb87821 100644 --- a/auth/manifoldbackend.py +++ b/auth/manifoldbackend.py @@ -2,7 +2,7 @@ import time from django.contrib.auth.models import User -from manifold.manifoldapi import ManifoldAPI, ManifoldResult +from manifoldapi.manifoldapi import ManifoldAPI, ManifoldException, ManifoldResult from manifold.core.query import Query # Name my backend 'ManifoldBackend' @@ -21,18 +21,6 @@ class ManifoldBackend: auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password} api = ManifoldAPI(auth) -#old # Authenticate user and get session key -#old # the new API would expect Get('local:session') instead -#old session_result = api.GetSession() -#old session = session_result.ok_value() -#old if not session: -#old print "GetSession failed",session_result.error() -#old return -#old print 'DEALING with session',session -#old #self.session = session -#old # Change GetSession() at some point to return expires as well -#old expires = time.time() + (24 * 60 * 60) - sessions_result = api.forward(Query.create('local:session').to_dict()) print "result" sessions = sessions_result.ok_value() @@ -42,7 +30,6 @@ class ManifoldBackend: return print "first", sessions session = sessions[0] - print "SESSION=", session # Change to session authentication api.auth = {'AuthMethod': 'session', 'session': session['session']} @@ -59,6 +46,9 @@ class ManifoldBackend: 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 @@ -71,9 +61,13 @@ class ManifoldBackend: except User.DoesNotExist: # Create a user in Django's local database user = User.objects.create_user(username, username, 'passworddoesntmatter') - user.first_name = "DUMMY_FIRST_NAME" #person['first_name'] - user.last_name = "DUMMY LAST NAME" # person['last_name'] user.email = person['email'] + + if 'firstname' in person: + user.first_name = person['firstname'] + if 'lastname' in person: + user.last_name = person['lastname'] + return user # Required for your backend to work properly - unchanged in most scenarios