Instead of the default Django User the Auth Model is 'customer' from the usercp App.
User's can use username as a display to the public, without disclosing their login information. This way they can use a forum with their username, which is seen by everyone. The login credentials, however are more privat, since it is the e-mail address. Allowing the user to not disclose any information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# settings file: AUTH_USER_MODEL = 'usercp.Customer' AUTHENTICATION_BACKENDS = ('usercp.backend.MyAuth', ) # backend.py in usercp (APP) folder from models import Customer from django.contrib.auth.hashers import check_password # Taken from http://www.djangorocks.com/tutorials/creating-a-custom-authentication-backend/creating-a-simple-authentication-backend.html class MyAuth: def authenticate(self, email="", password=""): try: user = Customer.objects.get(email=email) if check_password(password, user.password): return user else: return None except Customer.DoesNotExist: # No user was found, return None - triggers default login failed return None # Required for your backend to work properly - unchanged in most scenarios def get_user(self, user_id): try: return Customer.objects.get(pk=user_id) except Customer.DoesNotExist: return None
More like this
- "Magic Link" Management Command by webology 3 months ago
- Closest ORM models to a latitude/longitude point by simonw 3 months ago
- Log the time taken to execute each DB query by kennyx46 3 months ago
- django database snippet by ItsRLuo 3 months, 1 week ago
- Serialize a model instance by chriswedgwood 4 months ago