This commit is contained in:
chenyang
2022-06-29 12:28:49 +08:00
parent eb6436dbeb
commit d8fbbb0fa3
7 changed files with 33 additions and 25 deletions
+17
View File
@@ -1,3 +1,20 @@
from django.contrib.auth.backends import ModelBackend # 验证基类
from server_auth.models import MindUser
from django.contrib.auth import authenticate, login, logout
class AuthBackend(ModelBackend):
"""
login 方法会调用该方法
"""
# 重写验证方式
def authenticate(self, request, username=None, password=None, **kwargs):
user = MindUser.objects.get(id=1)
if user is not None and user.check_password(password):
return user
# 登录方式有多种
# 1、用户名密码登录:直接匹配数据库的用户名密码