From d8fbbb0fa3344f85666de2ecd881c62c8acfac50 Mon Sep 17 00:00:00 2001 From: chenyang Date: Wed, 29 Jun 2022 12:28:49 +0800 Subject: [PATCH] update --- jsmindmulti/settings.py | 5 +++++ server/views.py | 3 +++ server_auth/lib/auth.py | 17 +++++++++++++++++ static/html/dashboard.html | 8 +++++++- static/html/detail.html | 2 +- static/html/modal.html | 23 ----------------------- static/{style => js}/jsmind.css | 0 7 files changed, 33 insertions(+), 25 deletions(-) delete mode 100644 static/html/modal.html rename static/{style => js}/jsmind.css (100%) diff --git a/jsmindmulti/settings.py b/jsmindmulti/settings.py index 2c02706..4802bce 100644 --- a/jsmindmulti/settings.py +++ b/jsmindmulti/settings.py @@ -142,3 +142,8 @@ STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),) # AUTH_USER_MODEL为我们自定义的用户类 AUTH_USER_MODEL = "server_auth.MindUser" + +# 自定义 登陆手段 +AUTHENTICATION_BACKENDS = [ + 'server_auth.lib.auth.AuthBackend', +] diff --git a/server/views.py b/server/views.py index 438dc56..322635e 100644 --- a/server/views.py +++ b/server/views.py @@ -9,12 +9,14 @@ from server.filters import CooperationMindFilter from server.serializers import * from server.util.mix_util import build_response from server.util.pagination import NewPagination +from django.contrib.auth.decorators import login_required def to_dashboard(request): """ 界面 """ + print(request.user) return render(request, "html/dashboard.html") @@ -50,6 +52,7 @@ class JsMindView(ListAPIView): filter_class = CooperationMindFilter pagination_class = NewPagination + @login_required(login_url="dashboard") def get(self, request, *args, **kwargs): """ 查询思维导图 diff --git a/server_auth/lib/auth.py b/server_auth/lib/auth.py index ad92e75..25ff9e3 100644 --- a/server_auth/lib/auth.py +++ b/server_auth/lib/auth.py @@ -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、用户名密码登录:直接匹配数据库的用户名密码 diff --git a/static/html/dashboard.html b/static/html/dashboard.html index c0bf6ee..3273bd0 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -13,10 +13,16 @@ - + - - - - - - -test - - - - \ No newline at end of file diff --git a/static/style/jsmind.css b/static/js/jsmind.css similarity index 100% rename from static/style/jsmind.css rename to static/js/jsmind.css