[Frontend][全域功能] JWT 紀錄 原程序 localstorage 改成 cookie 存放
This commit is contained in:
parent
e69dd715d7
commit
4a82696ad1
@ -2084,7 +2084,8 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
<script>
|
||||
|
||||
/*$('#js-page-content').smartPanel();*/
|
||||
var jwt = localStorage.getItem("JWT-Authorization");
|
||||
var cookies = null;
|
||||
var jwt = null;
|
||||
var loadingTip = '';
|
||||
var pageAct = {}; //記錄全頁面已選擇項目
|
||||
pageAct.AreaTag = "TPE";
|
||||
@ -2145,8 +2146,8 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
function loadedMasterPack() {
|
||||
require(
|
||||
[
|
||||
"yourteam/yourteam.ajax.class",
|
||||
"yourteam/yourteam.utility.class",
|
||||
"yourteam/yourteam.ajax.class",
|
||||
"yourteam/yourteam.jquery.datatables",
|
||||
"yourteam/plugins/yt-tooltip/yt-tooltip",
|
||||
"yourteam/plugins/yt-tab/yt-tab",
|
||||
@ -2162,7 +2163,10 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
* 全數套件讀取完成 Callback
|
||||
* */
|
||||
function loadedJsPack() {
|
||||
cookies = new YourTeam.Utility.Cookie();
|
||||
jwt = cookies.get("JWT-Authorization");
|
||||
loadEvent();
|
||||
|
||||
if (!jwt) {
|
||||
myBaja = new MyBaja();
|
||||
myBaja.setMyUserAccount(Login);
|
||||
@ -2321,6 +2325,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
function Login(account) {
|
||||
console.log(account)
|
||||
/*if ($("#login-form").valid()) {*/
|
||||
|
||||
var url = baseApiUrl + "/api/Login/";
|
||||
var send_data = {
|
||||
account: account,
|
||||
@ -2343,7 +2348,7 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
|
||||
}
|
||||
else {
|
||||
/*toast_ok(rel.msg);*/
|
||||
localStorage.setItem('JWT-Authorization', rel.data.token);
|
||||
cookies.create("JWT-Authorization", rel.data.token);
|
||||
isValidLogin();
|
||||
}
|
||||
},
|
||||
|
@ -47,7 +47,8 @@ class Ajax {
|
||||
* @description beforeSendFunction
|
||||
*/
|
||||
beforeSendFunction = function (xhr) {
|
||||
let token = localStorage.getItem("JWT-Authorization");
|
||||
let cookies = new YourTeam.Utility.Cookie();
|
||||
let token = cookies.get("JWT-Authorization");
|
||||
xhr.setRequestHeader('Authorization', "Bearer " + token);
|
||||
}
|
||||
/**
|
||||
@ -56,10 +57,12 @@ class Ajax {
|
||||
* @param {Object} data the data object from the api return
|
||||
* @return {Object} data
|
||||
*/
|
||||
successFunction = function (data,callback) {
|
||||
successFunction = function (data, callback) {
|
||||
debugger
|
||||
if (data && data.unauthorized == 401) {
|
||||
let cookies = new YourTeam.Utility.Cookie();
|
||||
let href = location.href;
|
||||
localStorage.removeItem("JWT-Authorization");
|
||||
cookies.remove("JWT-Authorization");
|
||||
if (href.indexOf("localhost:5966") == -1) {
|
||||
location.href = "/login";
|
||||
} else {
|
||||
@ -85,7 +88,7 @@ class Ajax {
|
||||
window.alert("執行失敗,請聯絡客服人員。");
|
||||
} else if (xhr.status == "401") {
|
||||
window.alert("登入時間超時,請重新登入!");
|
||||
localStorage.removeItem("JWT-Authorization");
|
||||
cookies.remove("JWT-Authorization");
|
||||
location.href = "~/Login/Login";
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@
|
||||
}
|
||||
else {
|
||||
toast_ok(rel.msg);
|
||||
localStorage.setItem('JWT-Authorization', rel.data.token);
|
||||
cookies.create("JWT-Authorization", rel.data.token);
|
||||
location.href = "index.html";
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user