Second upload
This commit is contained in:
parent
ace3385ca0
commit
5d4886e806
@ -201,11 +201,11 @@
|
||||
|
||||
<!--檢查token-->
|
||||
<script>
|
||||
var token;
|
||||
var token
|
||||
function token_check() {
|
||||
// 检查本地存储中是否存在JWT令牌
|
||||
token = localStorage.getItem('token_park_space');
|
||||
console.log(token);
|
||||
//console.log(token)
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: 'http://localhost:7700/Users/token_check',
|
||||
@ -213,22 +213,60 @@
|
||||
'Authorization': token
|
||||
},
|
||||
success: function (response) {
|
||||
console.log(response);
|
||||
token_check = "true";
|
||||
from_token_import_id();
|
||||
//console.log(response)
|
||||
token_check = "true"
|
||||
from_token_import_id()
|
||||
},
|
||||
error: function () {
|
||||
alert("您的Token失效,請重新登錄");
|
||||
// 重定向到登錄頁面或處理失敗情況
|
||||
window.location.href = '/Users/Login';
|
||||
error: function (xhr) {
|
||||
token_check = "false"
|
||||
window.location.href = '/';
|
||||
// 处理错误响应,例如跳转到未授权页面
|
||||
//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>
|
||||
// 在頁面加載時檢查令牌
|
||||
$(document).ready(function () {
|
||||
token_check();
|
||||
});
|
||||
window.onload = token_check;
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user