mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-01 22:53:29 +08:00
localStorage操作统一使用localStorage.getItem,localStorage.removeItem;登录前判断用户名密码是否为空
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
</p>
|
||||
<script>
|
||||
// 带 token 的为绑定第三方账号,不带 token 的为第三方登录
|
||||
getRequest("/third-party/callback/<%=platform%>" + location.search + (localStorage.token ? ("&token=" + localStorage.token) : ""))
|
||||
getRequest("/third-party/callback/<%=platform%>" + location.search + (localStorage.getItem("token") ? ("&token=" + localStorage.getItem("token")) : ""))
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
var status = axiosData.status;
|
||||
@@ -30,7 +30,7 @@
|
||||
if (status === "success") {
|
||||
console.log(data)
|
||||
// 默认直接跳转 user 后台,如果是管理员则由 user 后台跳转
|
||||
if(localStorage.token) {
|
||||
if(localStorage.getItem("token")) {
|
||||
// 绑定第三方账号
|
||||
|
||||
// 绑定第三方账号成功
|
||||
|
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (localStorage.token)
|
||||
if (localStorage.getItem("token"))
|
||||
$("#dashboard").html("后台");
|
||||
|
||||
function navbarHighlight() {
|
||||
|
@@ -30,13 +30,56 @@
|
||||
|
||||
console.log(categoryOptions);
|
||||
return [
|
||||
// 【模板】
|
||||
// {
|
||||
// // 必填
|
||||
// "tag": "input",
|
||||
// "attr": {
|
||||
// // 可选
|
||||
// "id": "",
|
||||
// "name": "", // 用于 POST 提交
|
||||
// "class": "",
|
||||
// "style": "",
|
||||
// "placeholder": "电子书的名称",
|
||||
// },
|
||||
// "label": {
|
||||
// "value": "书本名称",
|
||||
// },
|
||||
// "required": true, // 是否必填
|
||||
|
||||
// // 可选
|
||||
// "innerHTML": "",
|
||||
// "children": [
|
||||
// {
|
||||
// "tag": "option",
|
||||
// "attr": { "value": "1" },
|
||||
// "innerHTML": "选项1",
|
||||
// },
|
||||
// {
|
||||
// "tag": "option",
|
||||
// "attr": { "value": "2" },
|
||||
// "innerHTML": "选项2",
|
||||
// },
|
||||
// ],
|
||||
// "validate": function (value) {
|
||||
// var validate = validateUtils.setValue(value)
|
||||
// .validate.notNull(value, "书本名称不能为空,请输入书本名称")
|
||||
// .validate.notNull(value, "书本名称不能超过 50 个字符")
|
||||
// .validate.notNull(value, "书本名称不能包含特殊字符")
|
||||
// .result();
|
||||
// console.log(validate);
|
||||
|
||||
// if (validateUtils.isEmpty(value)) {
|
||||
// result = false;
|
||||
// msg = "不能为空";
|
||||
// }
|
||||
// return { result: result, msg: msg };
|
||||
// }
|
||||
// },
|
||||
{
|
||||
// 必填
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
// 可选
|
||||
"id": "",
|
||||
"name": "", // 用于 POST 提交
|
||||
"name": "",
|
||||
"class": "",
|
||||
"style": "",
|
||||
"placeholder": "电子书的名称",
|
||||
@@ -45,10 +88,7 @@
|
||||
"value": "书本名称",
|
||||
},
|
||||
"required": true, // 是否必填
|
||||
|
||||
// 可选
|
||||
innerHTML: "",
|
||||
|
||||
"innerHTML": "",
|
||||
"validate": function (value) {
|
||||
|
||||
var validate = validateUtils.setValue(value)
|
||||
@@ -66,12 +106,9 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
// 必填
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
// 可选
|
||||
"id": "",
|
||||
"name": "", // 用于 POST 提交
|
||||
"name": "",
|
||||
"class": "",
|
||||
"style": "",
|
||||
"placeholder": "电子书的作者",
|
||||
@@ -80,10 +117,7 @@
|
||||
"value": "作者姓名",
|
||||
},
|
||||
"required": true, // 是否必填
|
||||
|
||||
// 可选
|
||||
innerHTML: "",
|
||||
|
||||
"innerHTML": "",
|
||||
"validate": function (value) {
|
||||
var result = true, msg = "";
|
||||
if (validateUtils.isEmpty(value)) {
|
||||
@@ -94,12 +128,10 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
// 必填
|
||||
"tag": "textarea",
|
||||
"attr": {
|
||||
// 可选
|
||||
"id": "",
|
||||
"name": "", // 用于 POST 提交
|
||||
"name": "",
|
||||
"class": "",
|
||||
"style": "height:100px;",
|
||||
"placeholder": "电子书的简介",
|
||||
@@ -108,10 +140,7 @@
|
||||
"value": "书籍简介",
|
||||
},
|
||||
"required": false, // 是否必填
|
||||
|
||||
// 可选
|
||||
innerHTML: "",
|
||||
|
||||
"innerHTML": "",
|
||||
"validate": function (value) {
|
||||
var result = true, msg = "";
|
||||
if (validateUtils.isEmpty(value)) {
|
||||
@@ -122,12 +151,10 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
// 必填
|
||||
"tag": "select",
|
||||
"attr": {
|
||||
// 可选
|
||||
"id": "",
|
||||
"name": "", // 用于 POST 提交
|
||||
"name": "",
|
||||
"class": "",
|
||||
"style": "",
|
||||
"placeholder": "书籍语言",
|
||||
@@ -153,10 +180,7 @@
|
||||
"innerHTML": "其他",
|
||||
},
|
||||
],
|
||||
|
||||
// 可选
|
||||
innerHTML: "",
|
||||
|
||||
"innerHTML": "",
|
||||
"validate": function (value) {
|
||||
var result = true, msg = "";
|
||||
if (validateUtils.isEmpty(value)) {
|
||||
@@ -167,12 +191,9 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
// 必填
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
// 可选
|
||||
"id": "",
|
||||
"name": "", // 用于 POST 提交
|
||||
"name": "",
|
||||
"class": "",
|
||||
"style": "",
|
||||
"placeholder": "出版社",
|
||||
@@ -181,10 +202,7 @@
|
||||
"value": "出版社",
|
||||
},
|
||||
"required": true, // 是否必填
|
||||
|
||||
// 可选
|
||||
innerHTML: "",
|
||||
|
||||
"innerHTML": "",
|
||||
"validate": function (value) {
|
||||
var result = true, msg = "";
|
||||
if (validateUtils.isEmpty(value)) {
|
||||
@@ -195,12 +213,9 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
// 必填
|
||||
"tag": "input",
|
||||
"attr": {
|
||||
// 可选
|
||||
"id": "",
|
||||
"name": "", // 用于 POST 提交
|
||||
"name": "",
|
||||
"class": "",
|
||||
"style": "",
|
||||
"placeholder": "",
|
||||
@@ -209,10 +224,7 @@
|
||||
"value": "来源(版权)",
|
||||
},
|
||||
"required": false, // 是否必填
|
||||
|
||||
// 可选
|
||||
innerHTML: "",
|
||||
|
||||
"innerHTML": "",
|
||||
"validate": function (value) {
|
||||
var result = true, msg = "";
|
||||
if (validateUtils.isEmpty(value)) {
|
||||
@@ -223,12 +235,9 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
// 必填
|
||||
"tag": "select",
|
||||
"attr": {
|
||||
// 可选
|
||||
"id": "",
|
||||
"name": "", // 用于 POST 提交
|
||||
"name": "",
|
||||
"class": "",
|
||||
"style": "",
|
||||
},
|
||||
@@ -236,8 +245,6 @@
|
||||
"value": "书籍分类",
|
||||
},
|
||||
"required": true, // 是否必填
|
||||
|
||||
// 可选
|
||||
"children": categoryOptions,
|
||||
// [
|
||||
// {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
postRequest('/debug/status', { token: localStorage.token })
|
||||
postRequest('/debug/status', { token: localStorage.getItem("token") })
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
var status = axiosData.status;
|
||||
|
@@ -65,7 +65,7 @@
|
||||
alert("请输入您的密码");
|
||||
return;
|
||||
}
|
||||
postRequest("/user/cancelAccount", { token: localStorage.token, password: accountCancellationPassword })
|
||||
postRequest("/user/cancelAccount", { token: localStorage.getItem("token"), password: accountCancellationPassword })
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
var status = axiosData.status;
|
||||
|
@@ -38,8 +38,8 @@
|
||||
}
|
||||
|
||||
if(!localStorage.getItem("token") || !localStorage.getItem("is_admin")) {
|
||||
localStorage.clear("token");
|
||||
localStorage.clear("is_admin");
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("is_admin");
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@
|
||||
}
|
||||
} else {
|
||||
if(data.errCode == "20004") { // 登陆过期
|
||||
localStorage.clear("token");
|
||||
localStorage.clear("is_admin");
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("is_admin");
|
||||
window.location.href = "/login";
|
||||
}
|
||||
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
|
||||
|
@@ -25,8 +25,8 @@
|
||||
if (status === "success") {
|
||||
console.log(data);
|
||||
if (data) {
|
||||
localStorage.clear("token");
|
||||
localStorage.clear("is_admin");
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("is_admin");
|
||||
location.href = "/login";
|
||||
} else {
|
||||
alert("退出登录失败");
|
||||
@@ -39,8 +39,8 @@
|
||||
console.log(error);
|
||||
var choice = confirm("服务器连接失败,无法正常退出登录,是否要强行退出登录?");
|
||||
if(choice) {
|
||||
localStorage.clear("token");
|
||||
localStorage.clear("is_admin");
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("is_admin");
|
||||
location.href = "/login";
|
||||
}
|
||||
});
|
||||
|
@@ -8,7 +8,7 @@
|
||||
</div>
|
||||
<script>
|
||||
function thirdPartyWithdraw(platform) {
|
||||
postRequest("/third-party/withdrawThirdPartyBings", { token: localStorage.token, platform: platform })
|
||||
postRequest("/third-party/withdrawThirdPartyBings", { token: localStorage.getItem("token"), platform: platform })
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
var status = axiosData.status;
|
||||
@@ -30,8 +30,8 @@
|
||||
alert("无法连接到服务器,请检查网络连接!");
|
||||
});
|
||||
}
|
||||
if (localStorage.token != null) {
|
||||
getRequest("/third-party/getBindingStatus", { token: localStorage.token })
|
||||
if (localStorage.getItem("token") != null) {
|
||||
getRequest("/third-party/getBindingStatus", { token: localStorage.getItem("token") })
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
var status = axiosData.status;
|
||||
|
@@ -50,8 +50,8 @@
|
||||
window.location.href = "/dashboard/user/index";
|
||||
} else {
|
||||
// 未知状态
|
||||
localStorage.clear("token");
|
||||
localStorage.clear("is_admin");
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("is_admin");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -111,6 +111,11 @@
|
||||
}
|
||||
});
|
||||
$(".btn-submit").click(function() {
|
||||
if($("#username").val() === "" || $("#password").val() === "") {
|
||||
alert("用户名或密码不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(isOnLogin) return;
|
||||
isOnLogin= true;
|
||||
|
||||
@@ -119,10 +124,8 @@
|
||||
// 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");
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("is_admin");
|
||||
postRequest("/user/login", { username: username, password: password })
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
|
Reference in New Issue
Block a user