1 # import the User object
2 from django.contrib.auth.models import User
3 from engine.manifoldapi import ManifoldAPI
6 # import time - this is used to create Django's internal username
9 # Name my backend 'ManifoldBackend'
10 class ManifoldBackend:
12 # Create an authentication method
13 # This is called by the standard Django login procedure
14 def authenticate(self, username=None, password=None):
15 if not username or not password:
19 auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password}
20 api = ManifoldAPI(auth)
21 # Authenticate user and get session key
22 session = api.GetSession()
26 #self.session = session
27 # Change GetSession() at some point to return expires as well
28 expires = time.time() + (24 * 60 * 60)
30 # Change to session authentication
31 api.auth = {'AuthMethod': 'session', 'session': session}
35 person = api.GetPersons(auth)
36 #self.person = person[0]
41 # Check if the user exists in Django's local database
42 user = User.objects.get(email=username)
43 except User.DoesNotExist:
44 # Create a user in Django's local database
45 user = User.objects.create_user(time.time(), username, 'passworddoesntmatter')
49 # Required for your backend to work properly - unchanged in most scenarios
50 def get_user(self, user_id):
52 return User.objects.get(pk=user_id)
53 except User.DoesNotExist: