1 # import the User object
2 from django.contrib.auth.models import User
3 from engine.manifold_api 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:
20 auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password}
21 api = ManifoldAPI(auth)
22 # Authenticate user and get session key
23 session = api.GetSession()
27 #self.session = session
28 # Change GetSession() at some point to return expires as well
29 expires = time.time() + (24 * 60 * 60)
31 # Change to session authentication
32 api.auth = {'AuthMethod': 'session', 'session': session}
36 person = api.GetPersons(auth)
37 #self.person = person[0]
42 # Check if the user exists in Django's local database
43 user = User.objects.get(email=username)
44 except User.DoesNotExist:
45 # Create a user in Django's local database
46 user = User.objects.create_user(time.time(), username, 'passworddoesntmatter')
50 # Required for your backend to work properly - unchanged in most scenarios
51 def get_user(self, user_id):
53 return User.objects.get(pk=user_id)
54 except User.DoesNotExist: