mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-01 22:53:29 +08:00
管理员和用户后台框架完成;用户登录功能完成
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -18,4 +18,7 @@ package-lock.json
|
||||
bookshelfplus.iml
|
||||
|
||||
# TODO文件
|
||||
TODO*
|
||||
TODO*
|
||||
|
||||
# 不提交仓库代码量统计相关文件
|
||||
.VSCodeCounter
|
@@ -44,16 +44,59 @@ router.get('/register', function (req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
router.get('/dashboard/admin/index', function (req, res) { // '/admin(/index)?'
|
||||
res.render('dashboard/admin/index', {
|
||||
title: "后台管理(管理员)"
|
||||
});
|
||||
});
|
||||
router.get('/dashboard/:group/:page', function (req, res) {
|
||||
var navbarLinks = null;
|
||||
if (req.params.group === "admin") {
|
||||
navbarLinks = [
|
||||
{
|
||||
name: "仪表盘",
|
||||
url: "/dashboard/admin/index"
|
||||
}, {
|
||||
name: "用户管理",
|
||||
url: "/dashboard/admin/UserManage"
|
||||
}, {
|
||||
name: "书籍管理",
|
||||
url: "/dashboard/admin/BookManage"
|
||||
}, {
|
||||
name: "分类管理",
|
||||
url: "/dashboard/admin/CategoryManage"
|
||||
}
|
||||
];
|
||||
} else if (req.params.group === "user") {
|
||||
navbarLinks = [
|
||||
{
|
||||
name: "仪表盘",
|
||||
url: "/dashboard/user/index"
|
||||
}, {
|
||||
name: "我的书架",
|
||||
url: "/dashboard/user/myBookshelf"
|
||||
}, {
|
||||
name: "我的收藏",
|
||||
url: "/dashboard/user/myCollection"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
router.get('/dashboard/user/index', function (req, res) { // '/admin(/index)?'
|
||||
res.render('dashboard/user/index', {
|
||||
title: "后台管理"
|
||||
});
|
||||
// 仪表盘
|
||||
if (req.params.page == "index") {
|
||||
res.render(`dashboard/${req.params.group}/index`, {
|
||||
title: "后台管理",
|
||||
links: navbarLinks
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 后台管理 其他管理页面
|
||||
if ((req.params.group === "admin" && ["UserManage", "BookManage", "CategoryManage"].indexOf(req.params.page) > -1) ||
|
||||
(req.params.group === "user" && ["myBookshelf", "myCollection"].indexOf(req.params.page) > -1)) {
|
||||
res.render(`dashboard/${req.params.group}/manage`, {
|
||||
title: req.params.group === "admin" ? "后台管理" : "用户中心",
|
||||
links: navbarLinks,
|
||||
page: req.params.page,
|
||||
});
|
||||
return;
|
||||
}
|
||||
throw new Error("404 Not Found");
|
||||
});
|
||||
|
||||
router.get('/status', function (req, res) {
|
||||
|
19
bookshelfplus-frontend/views/dashboard/admin/manage.html
Normal file
19
bookshelfplus-frontend/views/dashboard/admin/manage.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<%- include("../component/header.html"); %>
|
||||
<%- include("../component/header-admin.html"); %>
|
||||
</head>
|
||||
<body>
|
||||
<%- include("../component/navbar.html"); %>
|
||||
<main class="main">
|
||||
<h1><%= title %></h1>
|
||||
<div id="container">
|
||||
<div>
|
||||
<%= typeof title !=='undefined' ? page : "出错啦"; %>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<%- include("../component/footer-admin.html"); %>
|
||||
</body>
|
||||
</html>
|
@@ -25,7 +25,7 @@
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
getRequest("/user/getUserStatus", { token: localStorage.getItem("token") })
|
||||
postRequest("/user/getUserStatus", { token: localStorage.getItem("token") })
|
||||
.then(function (responseData) {
|
||||
var axiosData = responseData.data;
|
||||
var status = axiosData.status;
|
||||
|
@@ -1,22 +1,24 @@
|
||||
<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 class="grid-item" style="grid-column-start: span 2;">
|
||||
<h1 style="display: inline; vertical-align: middle; margin-right: 20px; cursor: pointer;"
|
||||
onclick="location.href='/';">
|
||||
书栖网
|
||||
</h1>
|
||||
<% links.forEach(item=> { %>
|
||||
<a href="<%= item.url %>" style="vertical-align: middle;">
|
||||
<%= item.name %>
|
||||
</a>
|
||||
<% }); %>
|
||||
<a href="javascript:logout();" style="color: grey; vertical-align: middle; float: right;">退出登录</a>
|
||||
</div>
|
||||
<div class="grid-item"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function logout() {
|
||||
getRequest("/user/logout", { token: localStorage.getItem("token") })
|
||||
postRequest("/user/logout", { token: localStorage.getItem("token") })
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
var status = axiosData.status;
|
||||
@@ -24,12 +26,10 @@
|
||||
|
||||
if (status === "success") {
|
||||
console.log(data);
|
||||
if(data) {
|
||||
if (data) {
|
||||
localStorage.clear("token");
|
||||
localStorage.clear("is_admin");
|
||||
// alert("退出登录成功");
|
||||
// window.location.href = "/";
|
||||
location.reload();
|
||||
location.href = "/login";
|
||||
} else {
|
||||
alert("退出登录失败");
|
||||
}
|
||||
|
19
bookshelfplus-frontend/views/dashboard/user/manage.html
Normal file
19
bookshelfplus-frontend/views/dashboard/user/manage.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<%- include("../component/header.html"); %>
|
||||
<%- include("../component/header-user.html"); %>
|
||||
</head>
|
||||
<body>
|
||||
<%- include("../component/navbar.html"); %>
|
||||
<main class="main">
|
||||
<h1><%= title %></h1>
|
||||
<div id="container">
|
||||
<div>
|
||||
<%= typeof title !=='undefined' ? page : "出错啦"; %>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<%- include("../component/footer-user.html"); %>
|
||||
</body>
|
||||
</html>
|
@@ -70,14 +70,13 @@ public class UserController extends BaseController {
|
||||
// @ApiImplicitParams({
|
||||
// @ApiImplicitParam(name = "token", value = "用户token", required = true, dataType = "String")
|
||||
// })
|
||||
@RequestMapping(value = "logout", method = {RequestMethod.GET})
|
||||
@RequestMapping(value = "logout", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType logout(@RequestParam(value = "token", required = false) String token) throws BusinessException {
|
||||
// token 未传入
|
||||
if (token == null || "".equals(token)) {
|
||||
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "用户令牌未传入");
|
||||
}
|
||||
|
||||
// // token 未传入
|
||||
// if (token == null || "".equals(token)) {
|
||||
// throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "用户令牌未传入");
|
||||
// }
|
||||
onLogout(token);
|
||||
return CommonReturnType.create("success");
|
||||
}
|
||||
@@ -86,7 +85,7 @@ public class UserController extends BaseController {
|
||||
// @ApiImplicitParams({
|
||||
// @ApiImplicitParam(name = "token", value = "用户token", required = true, dataType = "String")
|
||||
// })
|
||||
@RequestMapping(value = "getUserStatus", method = {RequestMethod.GET})
|
||||
@RequestMapping(value = "getUserStatus", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType getUserStatus(@RequestParam(value = "token", required = false) String token) throws BusinessException {
|
||||
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
|
||||
|
@@ -20,7 +20,7 @@ public class UserModel {
|
||||
// 用户昵称
|
||||
String nickname;
|
||||
|
||||
// 用户身份 NOT_LOGIN, ADMIN, LOGIN_USER;
|
||||
// 用户身份 NOT_LOGIN, ADMIN, USER;
|
||||
String group;
|
||||
|
||||
// 用户头像
|
||||
|
Reference in New Issue
Block a user