---增加authenticate,多账户判断---
注入设置 -> (二选一)使用装饰器,类继承 -> 加入所需功能
----settings中注入----
AUTHENTICATION_BACKENDS = ['meiduo_mall.utils.authenticate.NewAuth']
----新增authenticate用途----
from django.contrib.auth.backends import ModelBackend
# 继承原功能
class NewAuth(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs)
# 用户判定
try:
user = User.objects.get(username=username)
except:
try:
user = User.objects.get(mobile=username)
except:
return None
# 密码判定
if user.check_password(password):
return user
else:
return None |
|