Guest User

Untitled

a guest
May 5th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. # Place this in its own file and add it to your `AUTHENTICATION_BACKENDS` setting in settings.py
  2.  
  3. from django.conf import settings
  4. from django.contrib.auth.models import User
  5.  
  6. class EmailModelBackend(object):
  7. def authenticate(self, username=None, password=None):
  8. kwargs = {'email': username}
  9.  
  10. try:
  11. user = User.objects.get(**kwargs)
  12. if user.check_password(password):
  13. return user
  14. except User.DoesNotExist:
  15. return None
  16.  
  17. def get_user(self, user_id):
  18. try:
  19. return User.objects.get(pk=user_id)
  20. except User.DoesNotExist:
  21. return None
Add Comment
Please, Sign In to add comment