我有一个正在使用的自定义身份验证后端。我想允许非活动用户登录。将supports_inactive_user
标志设置为 true 似乎并没有解决问题,即使我可以验证是否user
正在返回。
class AuthenticationBackend(ModelBackend):
supports_object_permissions = False
supports_anonymous_user = True
supports_inactive_user = True
def authenticate(self, username=None, password=None):
"""
Allow login with email inplace of username
"""
user = None
if username is not None:
username = username.strip()
if email_re.search(username):
try:
user = User.objects.get(email__iexact=username)
except User.DoesNotExist:
pass
if not user:
try:
user = User.objects.get(username__iexact=username)
except User.DoesNotExist:
return None
if user.check_password(password):
return user
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
我正在使用 django 1.4。我错过了什么?