1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-12 19:51:39 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

后端:用户登录、退出登录、获取用户状态相关功能完成;引入SessionManager;数据库:user_identity改为group;前端:添加登录页面、后台管理页面框架,axios POST请求Content-Type问题修复,引入md5、sha1 js库;小问题调整

This commit is contained in:
2022-04-01 17:50:22 +08:00
parent 54c6ce8bca
commit d3c9ba10c4
26 changed files with 440 additions and 74 deletions

View File

@@ -0,0 +1,6 @@
<div class="footer" style="margin-top: 10vh;">
<hr>
<p>
<a href="/status">网站状态检测</a>
</p>
</div>

View File

@@ -0,0 +1,16 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title><%= typeof title !=='undefined' ? title : "前端服务出现异常"; %></title>
<link rel="stylesheet" href="/assets/stylesheets/style.css">
<script src="/assets/lib/jquery/3.6.0/jquery.min.js"></script>
<script src="/assets/lib/axios/0.26.1/axios.min.js"></script>
<script src="/assets/javascripts/httpRequest.js"></script>
<script>
// API地址
const APIHOST = '<%= global.site.api.prefix %>';
axios.defaults.baseURL = APIHOST;
</script>

View File

@@ -0,0 +1,43 @@
<div class="navbar">
<div class="navbar-grid">
<div class="grid-item"></div>
<div class="grid-item">
<nobr>
<h1 onclick="location.href='/'" style="cursor: pointer;">书栖网</h1>
</nobr>
</div>
<div class="grid-item exnarrowHide" style="text-align: right; color: white;">
<a href="/">首页</a>
<a href="/admin/manage">管理</a>
<a style="color: grey;" href="javascript:logout();">退出登录</a>
</div>
<div class="grid-item"></div>
</div>
</div>
<script>
function logout() {
getRequest("/user/logout", {})
.then(function (response) {
var axiosData = response.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data);
if(data) {
alert("退出登录成功");
// window.location.href = "/";
location.reload();
} else {
alert("退出登录失败");
}
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
})
.catch(function (error) {
console.log(error);
alert("退出登录失败");
});
}
</script>

View File

@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%- include("./component/header.html"); %>
</head>
<body>
<%- include("./component/navbar.html"); %>
<main class="main">
<h1><%= title %></h1>
<div id="container">
</div>
</main>
<%- include("./component/footer.html"); %>
<!-- 获取参数 -->
<script src="../assets/javascripts/getParams.js"></script>
<script>
var requestParams = getParams();
function getUserStatus() {
getRequest("/user/getUserStatus", { })
.then(function (responseData) {
var axiosData = responseData.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data)
if(data) {
} else {
window.location.href = "/login";
}
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
});
}
getUserStatus();
</script>
</body>
</html>

View File

@@ -77,7 +77,7 @@
// 渲染后重新获取一次字体
fontmin(getPageText());
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);

View File

@@ -51,7 +51,7 @@
// 渲染后重新获取一次字体
fontmin(getPageText());
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);

View File

@@ -14,9 +14,6 @@
const APIHOST = '<%= global.site.api.prefix %>';
axios.defaults.baseURL = APIHOST;
// 请求头 Content-Type
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
// 字体加载前先隐藏,不然文字会闪一下
$("html,body").css("opacity", "0");
</script>

View File

@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%- include("./component/header.html"); %>
<style>
.main {
width: 80vw !important;
max-width: initial !important;
}
#bookImage {
/* width: 100%; */
height: auto;
max-height: 300px;
margin-bottom: 20px;
}
</style>
</head>
<body>
<%- include("./component/navbar.html"); %>
<main class="main">
<h1><%= title %></h1>
<div id="container">
<div>
<!-- 用户登录 输入用户名和密码的文本框 -->
<div class="form">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" id="username" placeholder="用户名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" id="password" placeholder="密码">
</div>
<button class="btn-submit">登录</button>
</div>
</div>
</div>
</main>
<%- include("./component/footer.html"); %>
<script src="./assets/lib/cryptography/2.2/md5-min.js"></script>
<!-- <script src="./assets/lib/cryptography/2.2/sha1-min.js"></script> -->
<script>
$("#username").val("xiaomo");
$("#password").val("123456");
$(".btn-submit").click(function() {
var username = $("#username").val();
var password = $("#password").val();
// var encryptpwd = hex_sha1(password);
var encryptpwd = hex_md5(password);
console.log(password, encryptpwd);
postRequest("/user/login", { username: username, encryptpwd: encryptpwd })
.then(function (response) {
var axiosData = response.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data);
if(data) {
alert("登录成功");
if(data.group === "ADMIN") {
window.location.href = "/admin/index";
} else {
window.location.href = "/user/index";
}
} else {
alert("用户名或密码错误");
}
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);
});
});
</script>
</body>
</html>

View File

@@ -36,6 +36,7 @@
</div>
</div>
<%- include("./component/footer.html"); %>
<!-- 获取参数 -->
<script src="./assets/javascripts/getParams.js"></script>
<!-- 渲染表格 -->