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 sessions_result = api.forward(Query.create('local:session').to_dict())
26 sessions = sessions_result.ok_value()
29 print "GetSession failed", sessions_result.error()
31 print "first", sessions
33 print "SESSION=", session
35 # Change to session authentication
36 api.auth = {'AuthMethod': 'session', 'session': session['session']}
40 # the new API would expect Get('local:user') instead
41 persons_result = api.forward(Query.get('local:user').to_dict())
42 persons = persons_result.ok_value()
44 print "GetPersons failed",persons_result.error()
47 print "PERSON=", person
49 request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']}
51 print "E: manifoldbackend", e
57 # Check if the user exists in Django's local database
58 user = User.objects.get(username=username)
59 except User.DoesNotExist:
60 # Create a user in Django's local database
61 user = User.objects.create_user(username, username, 'passworddoesntmatter')
62 user.first_name = "DUMMY_FIRST_NAME" #person['first_name']
63 user.last_name = "DUMMY LAST NAME" # person['last_name']
64 user.email = person['email']
67 # Required for your backend to work properly - unchanged in most scenarios
68 def get_user(self, user_id):
70 return User.objects.get(pk=user_id)
71 except User.DoesNotExist: