3 from django.contrib.auth.models import User
5 from manifold.manifoldapi import ManifoldAPI, ManifoldException, 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
34 # Change to session authentication
35 api.auth = {'AuthMethod': 'session', 'session': session['session']}
39 # the new API would expect Get('local:user') instead
40 persons_result = api.forward(Query.get('local:user').to_dict())
41 persons = persons_result.ok_value()
43 print "GetPersons failed",persons_result.error()
46 print "PERSON=", person
48 request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']}
49 except ManifoldException, e:
50 print "ManifoldBackend.authenticate caught ManifoldException, returning corresponding ManifoldResult"
51 return e.manifold_result
53 print "E: manifoldbackend", e
59 # Check if the user exists in Django's local database
60 user = User.objects.get(username=username)
61 except User.DoesNotExist:
62 # Create a user in Django's local database
63 user = User.objects.create_user(username, username, 'passworddoesntmatter')
64 user.first_name = "DUMMY_FIRST_NAME" #person['first_name']
65 user.last_name = "DUMMY LAST NAME" # person['last_name']
66 user.email = person['email']
69 # Required for your backend to work properly - unchanged in most scenarios
70 def get_user(self, user_id):
72 return User.objects.get(pk=user_id)
73 except User.DoesNotExist: