1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-03 23:52:51 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
bookshelfplus/bookshelfplus-frontend/views/login.html

108 lines
4.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>
<script>
if(!localStorage) {
alert("您的浏览器不支持localStorage请更换浏览器");
window.location.href = "/";
}
if(localStorage.getItem("token")) {
// 用户已登录
if(localStorage.getItem("is_admin") === "true") {
// 是管理员
window.location.href = "/dashboard/admin/index";
} else if(localStorage.getItem("is_admin") === "false") {
// 是普通用户
window.location.href = "/dashboard/user/index";
} else {
// 未知状态
localStorage.clear("token");
localStorage.clear("is_admin");
}
}
</script>
</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);
if(localStorage.getItem("token"))
localStorage.clearItem("token");
if(localStorage.getItem("is_admin"))
localStorage.clearItem("is_admin");
postRequest("/user/login", { username: username, password: password })
.then(function (response) {
var axiosData = response.data;
var status = axiosData.status;
var data = axiosData.data;
if (status === "success") {
console.log(data);
if(data) {
localStorage.setItem("token", data.token);
// alert("登录成功");
if(data.group === "ADMIN") {
localStorage.setItem("is_admin", "true");
window.location.href = "/dashboard/admin/index";
} else {
localStorage.setItem("is_admin", "false");
window.location.href = "/dashboard/user/index";
}
} else {
alert("用户名或密码错误");
}
} else {
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
}
}).catch(function (error) {
console.log(error);
});
});
</script>
</body>
</html>