3 from django.contrib.auth.models import User
5 from engine.manifoldapi import ManifoldAPI
7 # Name my backend 'ManifoldBackend'
10 # Create an authentication method
11 # This is called by the standard Django login procedure
12 def authenticate(self, token=None):
17 username = token['username']
18 password = token['password']
19 request = token['request']
21 auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password}
22 api = ManifoldAPI(auth)
23 # Authenticate user and get session key
24 session = api.GetSession()
28 #self.session = session
29 # Change GetSession() at some point to return expires as well
30 expires = time.time() + (24 * 60 * 60)
32 # Change to session authentication
33 api.auth = {'AuthMethod': 'session', 'session': session}
37 person = api.GetPersons(auth)[0]
40 request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': expires}
45 # Check if the user exists in Django's local database
46 user = User.objects.get(username=username)
47 except User.DoesNotExist:
48 # Create a user in Django's local database
49 user = User.objects.create_user(username, username, 'passworddoesntmatter')
50 user.first_name = person['first_name']
51 user.last_name = person['last_name']
52 user.email = person['email']
55 # Required for your backend to work properly - unchanged in most scenarios
56 def get_user(self, user_id):
58 return User.objects.get(pk=user_id)
59 except User.DoesNotExist: