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 @@ - + + -