From 6dff7c6b4e963806a0e7ff0fc889e1b47b6786f7 Mon Sep 17 00:00:00 2001 From: chenyang Date: Sat, 2 Jul 2022 17:53:54 +0800 Subject: [PATCH] update --- server/urls.py | 1 + server/views/mind_map.py | 1 + server_auth/lib/auth.py | 28 +++++-- static/html/dashboard.html | 132 ++++++------------------------ static/js/dashboard.js | 53 ------------ static/js/{user => mind}/c_m_m.js | 0 static/js/mind/modal.js | 102 +++++++++++++++++++++++ 7 files changed, 150 insertions(+), 167 deletions(-) delete mode 100644 static/js/dashboard.js rename static/js/{user => mind}/c_m_m.js (100%) create mode 100644 static/js/mind/modal.js diff --git a/server/urls.py b/server/urls.py index b379124..93b33db 100644 --- a/server/urls.py +++ b/server/urls.py @@ -24,5 +24,6 @@ urlpatterns = [ # --------------------------------------------------- path('register', MindUserView.as_view()), # 用户注册 path('login', LoginView.as_view()), # 用户登录 + path('logout', LogoutView.as_view()), # 用户登出 ] diff --git a/server/views/mind_map.py b/server/views/mind_map.py index 24edc99..728b4cc 100644 --- a/server/views/mind_map.py +++ b/server/views/mind_map.py @@ -29,6 +29,7 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView): """ pk = request.GET.get('id') user = request.user + print(user) if pk is not None: mind = CooperationMind.objects.filter(id=pk).first() # 序列化 diff --git a/server_auth/lib/auth.py b/server_auth/lib/auth.py index 039be0f..6546ec6 100644 --- a/server_auth/lib/auth.py +++ b/server_auth/lib/auth.py @@ -1,24 +1,26 @@ from django import http -from django.contrib.auth import authenticate, login +from django.contrib.auth import authenticate, login, logout from django.contrib.auth.backends import ModelBackend # 验证基类 from django.contrib.auth.mixins import LoginRequiredMixin +from django.shortcuts import redirect +from django.urls import reverse from rest_framework.views import APIView from server.util.constant_util import * from server.util.mix_util import build_response -from server_auth.models import MindUser class AuthBackend(ModelBackend): """ login 方法会调用该方法 """ + pass # 重写验证方式 - 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 + # 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 # 登录方式有多种 @@ -54,6 +56,20 @@ class LoginView(APIView): return build_response(code=CODE_FAILED, msg='登录失败') +class LogoutView(APIView): + """ + 注销 + """ + + def get(self, request): + logout(request) + return build_response(msg='注销成功') + + def post(self, request): + logout(request) + return build_response(msg='注销成功') + + class LoginRequiredJSONMixin(LoginRequiredMixin): """自定义LoginRequiredMixin 如果用户未登录,响应JSON,且状态码为400 diff --git a/static/html/dashboard.html b/static/html/dashboard.html index 6879aaf..5b5a221 100644 --- a/static/html/dashboard.html +++ b/static/html/dashboard.html @@ -15,7 +15,7 @@ - + - - - - - - - - - @@ -429,11 +345,11 @@ - + + - diff --git a/static/js/dashboard.js b/static/js/dashboard.js deleted file mode 100644 index 15a80d3..0000000 --- a/static/js/dashboard.js +++ /dev/null @@ -1,53 +0,0 @@ -/* globals Chart:false, feather:false */ - -(function () { - 'use strict' - - feather.replace() - - // Graphs - /*var ctx = document.getElementById('myChart') - // eslint-disable-next-line no-unused-vars - var myChart = new Chart(ctx, { - type: 'line', - data: { - labels: [ - 'Sunday', - 'Monday', - 'Tuesday', - 'Wednesday', - 'Thursday', - 'Friday', - 'Saturday' - ], - datasets: [{ - data: [ - 15339, - 21345, - 18483, - 24003, - 23489, - 24092, - 12034 - ], - lineTension: 0, - backgroundColor: 'transparent', - borderColor: '#007bff', - borderWidth: 4, - pointBackgroundColor: '#007bff' - }] - }, - options: { - scales: { - yAxes: [{ - ticks: { - beginAtZero: false - } - }] - }, - legend: { - display: false - } - } - })*/ -})() diff --git a/static/js/user/c_m_m.js b/static/js/mind/c_m_m.js similarity index 100% rename from static/js/user/c_m_m.js rename to static/js/mind/c_m_m.js diff --git a/static/js/mind/modal.js b/static/js/mind/modal.js new file mode 100644 index 0000000..45423cd --- /dev/null +++ b/static/js/mind/modal.js @@ -0,0 +1,102 @@ +const modal = ` + + + + + + + +` +$('body').append($(modal)) \ No newline at end of file