1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from django.conf import settings
from django.contrib.auth.models import User
class EmailOrUsernameModelBackend(object):
def authenticate(self, username=None, password=None):
if '@' in username:
kwargs = {'email': username}
else:
kwargs = {'username': username}
try:
user = User.objects.get(**kwargs)
if user.check_password(password):
return user
except User.DoesNotExist:
return None
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
|
More like this
- Email or username authentication with masquerading by petrilli 2 years, 7 months ago
- Case Insensitive Authentication Backend by ericflo 2 years, 10 months ago
- OracleAuthBackend by nosrednakram 2 years, 5 months ago
- MoinMoin auth backend by yourcelf 1 year, 4 months ago
- Use email addresses for user name by chris 4 years, 11 months ago
Comments
thanks!
#