class EmailCheckModelBackend(ModelBackend):
"""
重新定义authenticate方法
"""
def authenticate(self, username=None, password=None):
try:
user = models.User.objects.get(Q(email=username)| Q(username=username))
if user.check_password(password):
return user
except models.User.DoesNotExist:
return None
网友评论