mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
Approach from http://www.micahcarrick.com/django-email-authentication.html. (imported from commit 796b8e08d8e1f9769cd3cf8ee61d3724ac3847b7)
26 lines
781 B
Python
26 lines
781 B
Python
from django.contrib.auth.models import User, check_password
|
|
|
|
class EmailAuthBackend(object):
|
|
"""
|
|
Email Authentication Backend
|
|
|
|
Allows a user to sign in using an email/password pair rather than
|
|
a username/password pair.
|
|
"""
|
|
|
|
def authenticate(self, username=None, password=None):
|
|
""" Authenticate a user based on email address as the user name. """
|
|
try:
|
|
user = User.objects.get(email=username)
|
|
if user.check_password(password):
|
|
return user
|
|
except User.DoesNotExist:
|
|
return None
|
|
|
|
def get_user(self, user_id):
|
|
""" Get a User object from the user_id. """
|
|
try:
|
|
return User.objects.get(pk=user_id)
|
|
except User.DoesNotExist:
|
|
return None
|