Added new setting, widget, form and auth backend to allow login via user email address
To enable:
AUTHENTICATION_BACKENDS = ('common.auth.email_auth_backend.EmailAuthBackend',)
COMMON_LOGIN_METHOD = 'email'
This commit is contained in:
23
apps/common/auth/email_auth_backend.py
Normal file
23
apps/common/auth/email_auth_backend.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# From: http://www.micahcarrick.com/django-email-authentication.html
|
||||
from django.contrib.auth.models import User, check_password
|
||||
from django.contrib.auth.backends import ModelBackend
|
||||
|
||||
|
||||
class EmailAuthBackend(ModelBackend):
|
||||
"""
|
||||
Email Authentication Backend
|
||||
|
||||
Allows a user to sign in using an email/password pair rather than
|
||||
a username/password pair.
|
||||
"""
|
||||
|
||||
def authenticate(self, email=None, password=None):
|
||||
"""
|
||||
Authenticate a user based on email address as the user name.
|
||||
"""
|
||||
try:
|
||||
user = User.objects.get(email=email)
|
||||
if user.check_password(password):
|
||||
return user
|
||||
except User.DoesNotExist:
|
||||
return None
|
||||
Reference in New Issue
Block a user