Second upload

This commit is contained in:
qi_0527 2024-10-02 00:37:57 +08:00
parent ace3385ca0
commit 5d4886e806

View File

@ -201,11 +201,11 @@
<!--檢查token--> <!--檢查token-->
<script> <script>
var token; var token
function token_check() { function token_check() {
// 检查本地存储中是否存在JWT令牌 // 检查本地存储中是否存在JWT令牌
token = localStorage.getItem('token_park_space'); token = localStorage.getItem('token_park_space');
console.log(token); //console.log(token)
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: 'http://localhost:7700/Users/token_check', url: 'http://localhost:7700/Users/token_check',
@ -213,22 +213,60 @@
'Authorization': token 'Authorization': token
}, },
success: function (response) { success: function (response) {
console.log(response); //console.log(response)
token_check = "true"; token_check = "true"
from_token_import_id(); from_token_import_id()
}, },
error: function () { error: function (xhr) {
alert("您的Token失效請重新登錄"); token_check = "false"
// 重定向到登錄頁面或處理失敗情況 window.location.href = '/';
window.location.href = '/Users/Login'; // 处理错误响应,例如跳转到未授权页面
//window.location.href = 'https://example.com/unauthorized_page';
}
});
}
function from_token_import_id() {
var token = localStorage.getItem('token_park_space');
$.ajax({
type: "GET",
url: 'http://localhost:7700/Users/token-' + token,
headers: {
'Authorization': token
},
success: function (response) {
//console.log(response)
from_id_import_user_data(response)
}
});
}
function from_id_import_user_data(id) {
var token = localStorage.getItem('token_park_space');
$.ajax({
type: "GET",
url: 'http://localhost:7700/Users/user_id-' + id,
headers: {
'Authorization': token
},
success: function (model) {
model = model.result
position = model.lastname
//console.log(position)
if (position == "engineer") {
get_data()
}
else {
window.location.href = '/';
}
} }
}); });
} }
</script> </script>
<!--開機自啟-->
<script> <script>
// 在頁面加載時檢查令牌 window.onload = token_check;
$(document).ready(function () {
token_check();
});
</script> </script>