3 from django.contrib.auth.models import User
5 from manifold.manifoldapi import ManifoldAPI, ManifoldResult
6 from manifold.core.query import Query
8 # Name my backend 'ManifoldBackend'
11 # Create an authentication method
12 # This is called by the standard Django login procedure
13 def authenticate(self, token=None):
18 username = token['username']
19 password = token['password']
20 request = token['request']
22 auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password}
23 api = ManifoldAPI(auth)
24 #old # Authenticate user and get session key
25 #old # the new API would expect Get('local:session') instead
26 #old session_result = api.GetSession()
27 #old session = session_result.ok_value()
29 #old print "GetSession failed",session_result.error()
31 #old print 'DEALING with session',session
32 #old #self.session = session
33 #old # Change GetSession() at some point to return expires as well
34 #old expires = time.time() + (24 * 60 * 60)
36 sessions_result = api.forward(Query.create('local:session').to_dict())
38 sessions = sessions_result.ok_value()
41 print "GetSession failed", sessions_result.error()
43 print "first", sessions
45 print "SESSION=", session
47 # Change to session authentication
48 api.auth = {'AuthMethod': 'session', 'session': session['session']}
52 # the new API would expect Get('local:user') instead
53 persons_result = api.forward(Query.get('local:user').to_dict())
54 persons = persons_result.ok_value()
56 print "GetPersons failed",persons_result.error()
59 print "PERSON=", person
61 request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']}
63 print "E: manifoldbackend", e
69 # Check if the user exists in Django's local database
70 user = User.objects.get(username=username)
71 except User.DoesNotExist:
72 # Create a user in Django's local database
73 user = User.objects.create_user(username, username, 'passworddoesntmatter')
74 user.first_name = "DUMMY_FIRST_NAME" #person['first_name']
75 user.last_name = "DUMMY LAST NAME" # person['last_name']
76 user.email = person['email']
79 # Required for your backend to work properly - unchanged in most scenarios
80 def get_user(self, user_id):
82 return User.objects.get(pk=user_id)
83 except User.DoesNotExist: