1 # import the User object
2 from django.contrib.auth.models import User
4 # import the IMAP library
5 #from imaplib import IMAP4
7 # import time - this is used to create Django's internal username
10 # Name my backend 'MyCustomBackend'
11 class MyCustomBackend:
13 hard_wired_users = { 'jean': '1234',
19 # Create an authentication method
20 # This is called by the standard Django login procedure
21 def authenticate(self, username=None, password=None):
22 users=MyCustomBackend.hard_wired_users
23 if username not in users: return None
24 if password != users[username]: return None
26 # Check if the user exists in Django's local database
27 user = User.objects.get(email=username)
28 except User.DoesNotExist:
29 # Create a user in Django's local database
30 user = User.objects.create_user(time.time(), username, 'passworddoesntmatter')
34 # Required for your backend to work properly - unchanged in most scenarios
35 def get_user(self, user_id):
37 return User.objects.get(pk=user_id)
38 except User.DoesNotExist: