update
This commit is contained in:
@@ -24,5 +24,6 @@ urlpatterns = [
|
|||||||
# ---------------------------------------------------
|
# ---------------------------------------------------
|
||||||
path('register', MindUserView.as_view()), # 用户注册
|
path('register', MindUserView.as_view()), # 用户注册
|
||||||
path('login', LoginView.as_view()), # 用户登录
|
path('login', LoginView.as_view()), # 用户登录
|
||||||
|
path('logout', LogoutView.as_view()), # 用户登出
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class JsMindView(LoginRequiredJSONMixin, ListAPIView):
|
|||||||
"""
|
"""
|
||||||
pk = request.GET.get('id')
|
pk = request.GET.get('id')
|
||||||
user = request.user
|
user = request.user
|
||||||
|
print(user)
|
||||||
if pk is not None:
|
if pk is not None:
|
||||||
mind = CooperationMind.objects.filter(id=pk).first()
|
mind = CooperationMind.objects.filter(id=pk).first()
|
||||||
# 序列化
|
# 序列化
|
||||||
|
|||||||
+22
-6
@@ -1,24 +1,26 @@
|
|||||||
from django import http
|
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.backends import ModelBackend # 验证基类
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
from django.urls import reverse
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from server.util.constant_util import *
|
from server.util.constant_util import *
|
||||||
from server.util.mix_util import build_response
|
from server.util.mix_util import build_response
|
||||||
from server_auth.models import MindUser
|
|
||||||
|
|
||||||
|
|
||||||
class AuthBackend(ModelBackend):
|
class AuthBackend(ModelBackend):
|
||||||
"""
|
"""
|
||||||
login 方法会调用该方法
|
login 方法会调用该方法
|
||||||
"""
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
# 重写验证方式
|
# 重写验证方式
|
||||||
def authenticate(self, request, username=None, password=None, **kwargs):
|
# def authenticate(self, request, username=None, password=None, **kwargs):
|
||||||
user = MindUser.objects.get(id=1)
|
# user = MindUser.objects.get(id=1)
|
||||||
if user is not None and user.check_password(password):
|
# if user is not None and user.check_password(password):
|
||||||
return user
|
# return user
|
||||||
|
|
||||||
|
|
||||||
# 登录方式有多种
|
# 登录方式有多种
|
||||||
@@ -54,6 +56,20 @@ class LoginView(APIView):
|
|||||||
return build_response(code=CODE_FAILED, msg='登录失败')
|
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):
|
class LoginRequiredJSONMixin(LoginRequiredMixin):
|
||||||
"""自定义LoginRequiredMixin
|
"""自定义LoginRequiredMixin
|
||||||
如果用户未登录,响应JSON,且状态码为400
|
如果用户未登录,响应JSON,且状态码为400
|
||||||
|
|||||||
+24
-108
@@ -15,7 +15,7 @@
|
|||||||
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
|
<script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
|
||||||
<script src="/static/bootstrap-4.6.1-dist/js/bootstrap.bundle.js"></script> <!-- bootstrap.bundle.min.js,还包含了 Popper,用于支持工具提示(tooltip)和弹出框(popover)功能,但是不包含 jQuery。-->
|
<script src="/static/bootstrap-4.6.1-dist/js/bootstrap.bundle.js"></script> <!-- bootstrap.bundle.min.js,还包含了 Popper,用于支持工具提示(tooltip)和弹出框(popover)功能,但是不包含 jQuery。-->
|
||||||
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"></script> <!-- 图标相关-->
|
<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"></script> <!-- 图标相关-->
|
||||||
<script src="/static/js/user/c_m_m.js"></script>
|
<script src="/static/js/mind/c_m_m.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const qr_websocket = {
|
const qr_websocket = {
|
||||||
websocket: null,
|
websocket: null,
|
||||||
@@ -148,13 +148,14 @@
|
|||||||
data: {username: userName_login, password: inputPassword_login},
|
data: {username: userName_login, password: inputPassword_login},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
// 注册成功
|
// 登录成功
|
||||||
if (data.code === 0) {
|
if (data.code === 0) {
|
||||||
login_alert(data.msg, 'alert-primary')
|
login_alert(data.msg, 'alert-primary')
|
||||||
$('#exampleModal').modal('hide')
|
$('#exampleModal').modal('hide')
|
||||||
|
$('#login_register').remove()
|
||||||
fetch_mind()
|
fetch_mind()
|
||||||
} else {
|
} else {
|
||||||
// 注册失败
|
// 登录失败
|
||||||
login_alert(data.msg)
|
login_alert(data.msg)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -192,7 +193,7 @@
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title">${item.coop_mind_name}</h5>
|
<h5 class="card-title">${item.coop_mind_name}</h5>
|
||||||
<img src="https://img0.baidu.com/it/u=218959243,558802769&fm=253&fmt=auto&app=138&f=JPEG?w=1377&h=500" class="card-img-top" alt="...">
|
<img src="https://img0.baidu.com/it/u=218959243,558802769&fm=253&fmt=auto&app=138&f=JPEG?w=1377&h=500" class="card-img-top" alt="...">
|
||||||
<a href="#" class="btn btn-info">编辑</a>
|
<a href="#" class="btn btn-info" onclick="window.open('detail?id=${item.id}')">编辑</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
@@ -247,118 +248,33 @@
|
|||||||
fetch_mind()
|
fetch_mind()
|
||||||
// js end
|
// js end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**注销登录*/
|
||||||
|
function logout_() {
|
||||||
|
$.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: "login",
|
||||||
|
headers: {"X-CSRFToken": $.cookie("csrftoken")},
|
||||||
|
data: {'username': 'userName_login'},
|
||||||
|
dataType: "json",
|
||||||
|
success: function (data) {
|
||||||
|
common_alert_(data.msg)
|
||||||
|
},
|
||||||
|
async: false
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<!--script end-->
|
<!--script end-->
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<!-- login Modal start-->
|
|
||||||
<div class="modal fade" id="exampleModal" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
|
||||||
<div class="modal-dialog modal-dialog-centered">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title">扫码登录</h5>
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--qr_login start-->
|
|
||||||
<div class="modal-body qr_login_group" style="height: 360px;">
|
|
||||||
<img src="https://img0.baidu.com/it/u=3881180510,1470858589&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" height="300px">
|
|
||||||
</div>
|
|
||||||
<!--qr_login end-->
|
|
||||||
|
|
||||||
<!--register start-->
|
|
||||||
<form>
|
|
||||||
<div class="modal-body register_group" style="display: none;height: 360px;">
|
|
||||||
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
|
|
||||||
<label for="userName" class="sr-only"></label>
|
|
||||||
<input type="text" id="userName" class="form-control" placeholder="用户名" autocomplete="off" required autofocus>
|
|
||||||
|
|
||||||
<label for="inputPassword" class="sr-only"></label>
|
|
||||||
<input type="password" id="inputPassword" class="form-control" placeholder="密码" autocomplete="new-password" required>
|
|
||||||
|
|
||||||
<label for="inputPassword_" class="sr-only"></label>
|
|
||||||
<input type="password" id="inputPassword_" class="form-control" placeholder="密码" autocomplete="new-password" required>
|
|
||||||
|
|
||||||
<div style="margin-bottom: 10px; text-align:right;">
|
|
||||||
<button class="btn btn-sm btn-primary" type="submit" id="register_button">注册</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<!--register end-->
|
|
||||||
|
|
||||||
<!--pw_login start-->
|
|
||||||
<form>
|
|
||||||
<div class="modal-body pw_login_group" style="display: none;height: 360px;">
|
|
||||||
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
|
|
||||||
<label for="userName_login" class="sr-only">用户名</label>
|
|
||||||
<input type="text" id="userName_login" name="userName_login" class="form-control" placeholder="用户名" autocomplete="username" required autofocus>
|
|
||||||
|
|
||||||
<label for="inputPassword_login" class="sr-only">密码</label>
|
|
||||||
<input type="password" id="inputPassword_login" name="inputPassword_login" class="form-control" placeholder="密码" autocomplete="current-password" required>
|
|
||||||
|
|
||||||
<div style="margin-bottom: 10px; text-align:right;">
|
|
||||||
<button class="btn btn-sm btn-primary" id="login_button" type="button">登录</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<!--pw_login end-->
|
|
||||||
|
|
||||||
<div class="modal-footer">
|
|
||||||
<a class="nav-link active" href="#" id="s_login_a">
|
|
||||||
<span data-feather="grid"></span>
|
|
||||||
扫码登录
|
|
||||||
</a>
|
|
||||||
<a class="nav-link active" id="register_a" href="#">
|
|
||||||
<span data-feather="check-circle"></span>
|
|
||||||
用户注册
|
|
||||||
</a>
|
|
||||||
<a class="nav-link active" href="#" id="p_login_a">
|
|
||||||
<span data-feather="smartphone"></span>
|
|
||||||
用户名登录
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- login Modal end-->
|
|
||||||
|
|
||||||
<!-- new Modal start-->
|
|
||||||
<div class="modal fade" id="newMindModal" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
|
||||||
<div class="modal-dialog modal-dialog-centered">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title">新建</h5>
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--start-->
|
|
||||||
<form>
|
|
||||||
<div class="modal-body">
|
|
||||||
<label for="mindName" class="sr-only"></label>
|
|
||||||
<input type="text" id="mindName" class="form-control" placeholder="思维导图名称" autocomplete="off" required autofocus>
|
|
||||||
<div style="text-align:right;">
|
|
||||||
<button type="button" class="btn btn-info" id="new_mind_btn">确认创建</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<!--end-->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- new Modal end-->
|
|
||||||
|
|
||||||
|
|
||||||
<!-- 页眉 start-->
|
<!-- 页眉 start-->
|
||||||
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
|
<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
|
||||||
<a class="navbar-brand col-md-2 col-lg-2 mr-0 px-3" href="#">协作思维导图</a>
|
<a class="navbar-brand col-md-2 col-lg-2 mr-0 px-3" href="#">协作思维导图</a>
|
||||||
<ul class="navbar-nav px-3">
|
<ul class="navbar-nav px-3">
|
||||||
<li class="nav-item text-nowrap">
|
<li class="nav-item text-nowrap">
|
||||||
<a class="nav-link" href="#" data-toggle="modal" data-target="#exampleModal">登录/注册</a>
|
<a id="login_register" class="nav-link" href="#" data-toggle="modal" data-target="#exampleModal">登录/注册</a>
|
||||||
|
<a id="logout_a" class="nav-link" href="javascript:void(0)" onclick="logout_()" style="display: none;">注销</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -429,11 +345,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--导航 和 内容 end-->
|
<!--导航 和 内容 end-->
|
||||||
|
</body>
|
||||||
|
<script src="/static/js/mind/modal.js"></script>
|
||||||
<script>
|
<script>
|
||||||
if (window.feather) {
|
if (window.feather) {
|
||||||
window.feather.replace();
|
window.feather.replace();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})*/
|
|
||||||
})()
|
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
const modal = `
|
||||||
|
<!-- login Modal start-->
|
||||||
|
<div class="modal fade" id="exampleModal" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">扫码登录</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--qr_login Modal start-->
|
||||||
|
<div class="modal-body qr_login_group" style="height: 360px;">
|
||||||
|
<img src="https://img0.baidu.com/it/u=3881180510,1470858589&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200" height="300px">
|
||||||
|
</div>
|
||||||
|
<!--qr_login Modal end-->
|
||||||
|
|
||||||
|
<!--register Modal start-->
|
||||||
|
<form>
|
||||||
|
<div class="modal-body register_group" style="display: none;height: 360px;">
|
||||||
|
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
|
||||||
|
<label for="userName" class="sr-only"></label>
|
||||||
|
<input type="text" id="userName" class="form-control" placeholder="用户名" autocomplete="off" required autofocus>
|
||||||
|
|
||||||
|
<label for="inputPassword" class="sr-only"></label>
|
||||||
|
<input type="password" id="inputPassword" class="form-control" placeholder="密码" autocomplete="new-password" required>
|
||||||
|
|
||||||
|
<label for="inputPassword_" class="sr-only"></label>
|
||||||
|
<input type="password" id="inputPassword_" class="form-control" placeholder="密码" autocomplete="new-password" required>
|
||||||
|
|
||||||
|
<div style="margin-bottom: 10px; text-align:right;">
|
||||||
|
<button class="btn btn-sm btn-primary" type="submit" id="register_button">注册</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<!--register Modal end-->
|
||||||
|
|
||||||
|
<!--pw_login Modal start-->
|
||||||
|
<form>
|
||||||
|
<div class="modal-body pw_login_group" style="display: none;height: 360px;">
|
||||||
|
<h1 class="h3 mb-3 font-weight-normal">请输入用户名和密码</h1>
|
||||||
|
<label for="userName_login" class="sr-only">用户名</label>
|
||||||
|
<input type="text" id="userName_login" name="userName_login" class="form-control" placeholder="用户名" autocomplete="username" required autofocus>
|
||||||
|
|
||||||
|
<label for="inputPassword_login" class="sr-only">密码</label>
|
||||||
|
<input type="password" id="inputPassword_login" name="inputPassword_login" class="form-control" placeholder="密码" autocomplete="current-password" required>
|
||||||
|
|
||||||
|
<div style="margin-bottom: 10px; text-align:right;">
|
||||||
|
<button class="btn btn-sm btn-primary" id="login_button" type="button">登录</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<!--pw_login Modal end-->
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<a class="nav-link active" href="#" id="s_login_a">
|
||||||
|
<span data-feather="grid"></span>
|
||||||
|
扫码登录
|
||||||
|
</a>
|
||||||
|
<a class="nav-link active" id="register_a" href="#">
|
||||||
|
<span data-feather="check-circle"></span>
|
||||||
|
用户注册
|
||||||
|
</a>
|
||||||
|
<a class="nav-link active" href="#" id="p_login_a">
|
||||||
|
<span data-feather="smartphone"></span>
|
||||||
|
用户名登录
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- login Modal end-->
|
||||||
|
|
||||||
|
<!-- new Modal start-->
|
||||||
|
<div class="modal fade" id="newMindModal" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-dialog-centered">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">新建</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--start-->
|
||||||
|
<form>
|
||||||
|
<div class="modal-body">
|
||||||
|
<label for="mindName" class="sr-only"></label>
|
||||||
|
<input type="text" id="mindName" class="form-control" placeholder="思维导图名称" autocomplete="off" required autofocus>
|
||||||
|
<div style="text-align:right;">
|
||||||
|
<button type="button" class="btn btn-info" id="new_mind_btn">确认创建</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<!--end-->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- new Modal end-->
|
||||||
|
`
|
||||||
|
$('body').append($(modal))
|
||||||
Reference in New Issue
Block a user