login-authorization-v2 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@
16
16
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
17
17
 
18
18
  "use strict";
19
- eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"init\": () => (/* binding */ init),\n/* harmony export */ \"getUserInfo\": () => (/* binding */ getUserInfo),\n/* harmony export */ \"getIdToken\": () => (/* binding */ getIdToken),\n/* harmony export */ \"setIdToken\": () => (/* binding */ setIdToken),\n/* harmony export */ \"getRefreshToken\": () => (/* binding */ getRefreshToken),\n/* harmony export */ \"setRefreshToken\": () => (/* binding */ setRefreshToken),\n/* harmony export */ \"clearLoginCookie\": () => (/* binding */ clearLoginCookie),\n/* harmony export */ \"refreshIdTokenTimer\": () => (/* binding */ refreshIdTokenTimer),\n/* harmony export */ \"logout\": () => (/* binding */ logout),\n/* harmony export */ \"setCookie\": () => (/* binding */ setCookie),\n/* harmony export */ \"getCookie\": () => (/* binding */ getCookie),\n/* harmony export */ \"getUrlParam\": () => (/* binding */ getUrlParam)\n/* harmony export */ });\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);\n\r\nlet tokenTimer = null;\r\nlet idTokenFront = null;\r\nlet idTokenBack = null;\r\nlet refreshTokenFront = null;\r\nlet refreshTokenBack = null;\r\nlet userRequestUrl = null;\r\nlet userLogoutUrl = null;\r\nlet tenantId = '';\r\nlet currentSystemType = 'client';\r\n// 获取、设置cookie\r\nfunction getCookie (c_name) {\r\n if (document.cookie.length > 0) {\r\n let c_start = document.cookie.indexOf(c_name + \"=\")\r\n if (c_start != -1) {\r\n c_start = c_start + c_name.length + 1\r\n let c_end = document.cookie.indexOf(\";\", c_start)\r\n if (c_end == -1) c_end = document.cookie.length\r\n return unescape(document.cookie.substring(c_start, c_end))\r\n }\r\n }\r\n return null\r\n}\r\nfunction setCookie (name, value, domain, path = '/', time = 30 * 24 * 60 * 60 * 1000) {\r\n let exp = new Date();\r\n exp.setTime(exp.getTime() + time);\r\n document.cookie = name + \"=\" + escape(value) + \";expires=\" + exp.toGMTString() + \";domain=\" + domain + \";path=\" + path;\r\n}\r\n// 获取url参数中的某个值\r\nfunction getUrlParam (urlStr) {\r\n var query = window.location.href.split('?')[1];\r\n var vars = query ? query.split(\"&\") : [];\r\n for (var i = 0; i < vars.length; i++) {\r\n var pair = vars[i].split(\"=\");\r\n if (pair[0] == urlStr) { return pair[1]; }\r\n }\r\n return null;\r\n}\r\n\r\nif (getCookie('idTokenFront')) {\r\n idTokenFront = getCookie('idTokenFront');\r\n}\r\nif (getCookie('idTokenBack')) {\r\n idTokenBack = getCookie('idTokenBack');\r\n}\r\nif (getCookie('refreshTokenFront')) {\r\n refreshTokenFront = getCookie('refreshTokenFront');\r\n}\r\nif (getCookie('refreshTokenBack')) {\r\n refreshTokenBack = getCookie('refreshTokenBack');\r\n}\r\n// 获取用户信息\r\nfunction getUserInfo () {\r\n if (idTokenBack) {\r\n return JSON.parse(atob(idTokenBack.split('.')[0]))\r\n } else {\r\n return null\r\n }\r\n}\r\n// 获取idToken\r\nfunction getIdToken () {\r\n return (idTokenFront && idTokenBack) ? (idTokenFront + '.' + idTokenBack) : null\r\n}\r\n// 设置idToken\r\nfunction setIdToken (value) {\r\n idTokenFront = value.split('.')[0] + '.' + value.split('.')[1];\r\n idTokenBack = value.split('.')[2];\r\n setCookie('idTokenFront', idTokenFront, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n setCookie('idTokenBack', idTokenBack, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n}\r\n// 获取refreshToken\r\nfunction getRefreshToken () {\r\n return (refreshTokenFront && refreshTokenBack) ? (refreshTokenFront + '.' + refreshTokenBack) : null\r\n}\r\n// 设置refreshToken\r\nfunction setRefreshToken (value) {\r\n refreshTokenFront = value.split('.')[0] + '.' + value.split('.')[1];\r\n refreshTokenBack = value.split('.')[2] + '.' + value.split('.')[3] + '.' + value.split('.')[4];\r\n setCookie('refreshTokenFront', refreshTokenFront, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n setCookie('refreshTokenBack', refreshTokenBack, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n}\r\n// 清空登录相关cookie\r\nfunction clearLoginCookie () {\r\n if (currentSystemType === getCookie('currentSystemType')) {\r\n setCookie('idTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('idTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n } else if (!getCookie('currentSystemType')) {\r\n setCookie('idTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('idTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n }\r\n}\r\n// 定时刷新IdToken\r\nfunction refreshIdTokenTimer (time) {\r\n if (!getIdToken() || !getRefreshToken()) {\r\n return;\r\n }\r\n tokenTimer = setInterval(() => {\r\n axios__WEBPACK_IMPORTED_MODULE_0___default()({\r\n url: userRequestUrl + '/user-profile/refresh-token/refresh',\r\n method: 'post',\r\n data: {\r\n refreshToken: getRefreshToken()\r\n }\r\n }).then(res => {\r\n if (res.data.code === 200) {\r\n setIdToken(res.data.content.idToken);\r\n } else if (res.data.code === 500) {\r\n if (userLogoutUrl !== '' || userLogoutUrl !== undefined) {\r\n clearLoginCookie();\r\n window.location.href = userLogoutUrl;\r\n }\r\n }\r\n })\r\n }, time)\r\n}\r\n// 登出\r\nfunction logout () {\r\n return new Promise((resolve, reject) => {\r\n axios__WEBPACK_IMPORTED_MODULE_0___default()({\r\n url: userRequestUrl + '/user-profile/logout',\r\n method: 'post',\r\n data: {\r\n refreshToken: getRefreshToken()\r\n }\r\n }).then(res => {\r\n clearInterval(tokenTimer);\r\n clearLoginCookie();\r\n if (userLogoutUrl !== '' || userLogoutUrl !== undefined) {\r\n window.location.href = userLogoutUrl;\r\n }\r\n resolve(true)\r\n })\r\n })\r\n}\r\n// 无权限访问时弹窗显示\r\nfunction createDoalog(){\r\n let html = `<div id=\"confirm-container\" style=\"box-sizing:border-box;position:fixed;width:615px;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left: 35%;padding:20px 20px;top:10px;font-size: 16px;\">\r\n <div id=\"href\" style=\"color: rgb(32,33,36);\"></div>\r\n <div style=\"margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;\">You do not have access to the system.</div>\r\n <div style=\"display: flex;justify-content: flex-end;\">\r\n <button id=\"cancel\" style=\"padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;\">Cancel</button>\r\n <button id=\"confirm\" style=\"padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;\">Sign in to another ZERO account</button>\r\n </div>\r\n </div>`\r\n let confirmDialog=document.getElementsByTagName('body')[0];\r\n confirmDialog.innerHTML = '';\r\n confirmDialog.insertAdjacentHTML(\"beforeend\", html);\r\n document.getElementById('href').innerHTML = window.location.hostname;\r\n document.getElementById('confirm').onclick = confirms;\r\n document.getElementById('cancel').onclick = cancels;\r\n}\r\nfunction createDoalogMobile(){\r\n let html = `<div id=\"confirm-container\" style=\"box-sizing:border-box;position:fixed;width:97.6vw;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left:0px;padding:20px 20px;top:4px;margin:0 4px;font-size: 16px;\">\r\n <div id=\"href\" style=\"color: rgb(32,33,36);\"></div>\r\n <div style=\"margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;\">You do not have access to the system.</div>\r\n <div style=\"display: flex;justify-content: flex-end;\">\r\n <div style=\"display: flex;justify-content: flex-end;\">\r\n <button id=\"cancel\" style=\"padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;\">Cancel</button>\r\n <button id=\"confirm\" style=\"padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;\">Sign in to another ZERO account</button>\r\n </div>\r\n </div>\r\n </div>`\r\n let confirmDialog=document.getElementsByTagName('body')[0];\r\n confirmDialog.innerHTML = '';\r\n confirmDialog.insertAdjacentHTML(\"beforeend\", html);\r\n document.getElementById('href').innerHTML = window.location.hostname;\r\n document.getElementById('confirm').onclick = confirms;\r\n document.getElementById('cancel').onclick = cancels;\r\n}\r\nfunction confirms() {\r\n clearLoginCookie();\r\n document.getElementById('confirm-container').style.display = 'none';\r\n if (window.location.href.indexOf('hedgehood')!==-1){\r\n window.location.href = currentSystemType === 'staff' ? 'https://login' + window.location.hostname.substring(window.location.hostname.indexOf('.')) + '/login' : 'https://trader' + window.location.hostname.substring(window.location.hostname.indexOf('.'));\r\n } else if (window.location.href.indexOf('ddmarketinghub')!==-1) {\r\n window.location.href = \"http://huangcheng.ddmarketinghub.com:8080\";\r\n } else {\r\n window.location.href = currentSystemType === 'staff' ? 'https://login' + window.location.hostname.substring(window.location.hostname.indexOf('.')) + '/login' : 'https://trader' + window.location.hostname.substring(window.location.hostname.indexOf('.'));\r\n }\r\n}\r\nfunction cancels() {\r\n document.getElementById('confirm-container').style.display = 'none';\r\n window.location.href = 'about:blank';\r\n}\r\nfunction IsPC () {\r\n var userAgentInfo = navigator.userAgent;\r\n var Agents = [\r\n 'Android',\r\n 'iPhone',\r\n 'SymbianOS',\r\n 'Windows Phone',\r\n 'iPad',\r\n 'iPod',\r\n ];\r\n var flag = true;\r\n for (var v = 0; v < Agents.length; v++) {\r\n if (userAgentInfo.indexOf(Agents[v]) > 0) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n return flag;\r\n}\r\n// 获取可访问系统列表\r\nfunction systemLists (systemName, idToken) {\r\n return new Promise((resolve, reject) => {\r\n axios__WEBPACK_IMPORTED_MODULE_0___default()({\r\n url: userRequestUrl + '/session/current/servers',\r\n method: 'get',\r\n headers: {\r\n authorization: 'Bearer ' + idToken,\r\n 'X-tenant-id': tenantId ? tenantId : ''\r\n }\r\n }).then(res => {\r\n if (res.data.code === 200) {\r\n let lists = res.data.content;\r\n if (!systemName) {\r\n IsPC() ? createDoalog() : createDoalogMobile()\r\n } else if (systemName === 'commonLogin') {\r\n resolve(true);\r\n } else if (lists.length === 0) {\r\n IsPC() ? createDoalog() : createDoalogMobile()\r\n } else {\r\n let hasAccess = false;\r\n lists.forEach(item => {\r\n if (systemName.toLowerCase() === item.groupName.toLowerCase()) {\r\n resolve(true);\r\n hasAccess = true;\r\n currentSystemType = item.staffEndpoint ? 'staff' : 'client';\r\n }\r\n })\r\n if (!hasAccess) {\r\n IsPC() ? createDoalog() : createDoalogMobile()\r\n }\r\n }\r\n } else {\r\n resolve(false);\r\n }\r\n }).catch(() => {\r\n resolve(true);\r\n })\r\n })\r\n}\r\n// init初始化\r\nasync function init (requestUrl, loginUrl, systemName, tenant, time = 1000 * 60 * 3) {\r\n tenantId = tenant ? tenant : '';\r\n userLogoutUrl = loginUrl;\r\n return new Promise(async (resolve, reject) => {\r\n if (!getIdToken() || !getRefreshToken()) {\r\n resolve(false);\r\n }\r\n if (requestUrl) {\r\n userRequestUrl = requestUrl;\r\n refreshIdTokenTimer(time);\r\n let hasAuth = await systemLists(systemName, getIdToken());\r\n if (hasAuth) {\r\n resolve(true);\r\n } else {\r\n await logout();\r\n resolve(false);\r\n }\r\n } else {\r\n alert('Not request url');\r\n reject();\r\n }\r\n })\r\n}\r\n\n\n//# sourceURL=webpack://login-authorization-v2/./index.js?");
19
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"init\": () => (/* binding */ init),\n/* harmony export */ \"getUserInfo\": () => (/* binding */ getUserInfo),\n/* harmony export */ \"getIdToken\": () => (/* binding */ getIdToken),\n/* harmony export */ \"setIdToken\": () => (/* binding */ setIdToken),\n/* harmony export */ \"getRefreshToken\": () => (/* binding */ getRefreshToken),\n/* harmony export */ \"setRefreshToken\": () => (/* binding */ setRefreshToken),\n/* harmony export */ \"clearLoginCookie\": () => (/* binding */ clearLoginCookie),\n/* harmony export */ \"refreshIdTokenTimer\": () => (/* binding */ refreshIdTokenTimer),\n/* harmony export */ \"logout\": () => (/* binding */ logout),\n/* harmony export */ \"setCookie\": () => (/* binding */ setCookie),\n/* harmony export */ \"getCookie\": () => (/* binding */ getCookie),\n/* harmony export */ \"getUrlParam\": () => (/* binding */ getUrlParam)\n/* harmony export */ });\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_0__);\n\r\nlet tokenTimer = null;\r\nlet idTokenFront = null;\r\nlet idTokenBack = null;\r\nlet refreshTokenFront = null;\r\nlet refreshTokenBack = null;\r\nlet userRequestUrl = null;\r\nlet userLogoutUrl = null;\r\nlet tenantId = '';\r\nlet currentSystemType = 'client';\r\n// 获取、设置cookie\r\nfunction getCookie (c_name) {\r\n if (document.cookie.length > 0) {\r\n let c_start = document.cookie.indexOf(c_name + \"=\")\r\n if (c_start != -1) {\r\n c_start = c_start + c_name.length + 1\r\n let c_end = document.cookie.indexOf(\";\", c_start)\r\n if (c_end == -1) c_end = document.cookie.length\r\n return unescape(document.cookie.substring(c_start, c_end))\r\n }\r\n }\r\n return null\r\n}\r\nfunction setCookie (name, value, domain, path = '/', time = 30 * 24 * 60 * 60 * 1000) {\r\n let exp = new Date();\r\n exp.setTime(exp.getTime() + time);\r\n document.cookie = name + \"=\" + escape(value) + \";expires=\" + exp.toGMTString() + \";domain=\" + domain + \";path=\" + path;\r\n}\r\n// 获取url参数中的某个值\r\nfunction getUrlParam (urlStr) {\r\n var query = window.location.href.split('?')[1];\r\n var vars = query ? query.split(\"&\") : [];\r\n for (var i = 0; i < vars.length; i++) {\r\n var pair = vars[i].split(\"=\");\r\n if (pair[0] == urlStr) { return pair[1]; }\r\n }\r\n return null;\r\n}\r\n\r\nif (getCookie('idTokenFront')) {\r\n idTokenFront = getCookie('idTokenFront');\r\n}\r\nif (getCookie('idTokenBack')) {\r\n idTokenBack = getCookie('idTokenBack');\r\n}\r\nif (getCookie('refreshTokenFront')) {\r\n refreshTokenFront = getCookie('refreshTokenFront');\r\n}\r\nif (getCookie('refreshTokenBack')) {\r\n refreshTokenBack = getCookie('refreshTokenBack');\r\n}\r\n// 获取用户信息\r\nfunction getUserInfo () {\r\n if (idTokenBack) {\r\n return JSON.parse(atob(idTokenBack.split('.')[0]))\r\n } else {\r\n return null\r\n }\r\n}\r\n// 获取idToken\r\nfunction getIdToken () {\r\n return (idTokenFront && idTokenBack) ? (idTokenFront + '.' + idTokenBack) : null\r\n}\r\n// 设置idToken\r\nfunction setIdToken (value) {\r\n idTokenFront = value.split('.')[0] + '.' + value.split('.')[1];\r\n idTokenBack = value.split('.')[2];\r\n setCookie('idTokenFront', idTokenFront, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n setCookie('idTokenBack', idTokenBack, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n}\r\n// 获取refreshToken\r\nfunction getRefreshToken () {\r\n return (refreshTokenFront && refreshTokenBack) ? (refreshTokenFront + '.' + refreshTokenBack) : null\r\n}\r\n// 设置refreshToken\r\nfunction setRefreshToken (value) {\r\n refreshTokenFront = value.split('.')[0] + '.' + value.split('.')[1];\r\n refreshTokenBack = value.split('.')[2] + '.' + value.split('.')[3] + '.' + value.split('.')[4];\r\n setCookie('refreshTokenFront', refreshTokenFront, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n setCookie('refreshTokenBack', refreshTokenBack, window.location.hostname.substring(window.location.hostname.indexOf('.')));\r\n}\r\n// 清空登录相关cookie\r\nfunction clearLoginCookie () {\r\n if (currentSystemType === getCookie('currentSystemType')) {\r\n setCookie('idTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('idTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n } else if (!getCookie('currentSystemType')) {\r\n setCookie('idTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('idTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenFront', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n setCookie('refreshTokenBack', null, window.location.hostname.substring(window.location.hostname.indexOf('.')), '/', -1);\r\n }\r\n}\r\n// 定时刷新IdToken\r\nfunction refreshIdTokenTimer (time) {\r\n if (!getIdToken() || !getRefreshToken()) {\r\n return;\r\n }\r\n tokenTimer = setInterval(() => {\r\n axios__WEBPACK_IMPORTED_MODULE_0___default()({\r\n url: userRequestUrl + '/user-profile/refresh-token/refresh',\r\n method: 'post',\r\n data: {\r\n refreshToken: getRefreshToken()\r\n }\r\n }).then(res => {\r\n if (res.data.code === 200) {\r\n setIdToken(res.data.content.idToken);\r\n } else if (res.data.code === 500) {\r\n if (userLogoutUrl !== '' || userLogoutUrl !== undefined) {\r\n clearLoginCookie();\r\n window.location.href = userLogoutUrl;\r\n }\r\n }\r\n })\r\n }, time)\r\n}\r\n// 登出\r\nfunction logout () {\r\n return new Promise((resolve, reject) => {\r\n axios__WEBPACK_IMPORTED_MODULE_0___default()({\r\n url: userRequestUrl + '/user-profile/logout',\r\n method: 'post',\r\n data: {\r\n refreshToken: getRefreshToken()\r\n }\r\n }).then(res => {\r\n clearInterval(tokenTimer);\r\n clearLoginCookie();\r\n if (userLogoutUrl !== '' || userLogoutUrl !== undefined) {\r\n window.location.href = userLogoutUrl;\r\n }\r\n resolve(true)\r\n })\r\n })\r\n}\r\n// 无权限访问时弹窗显示\r\nfunction createDoalog(){\r\n let html = `<div id=\"confirm-container\" style=\"box-sizing:border-box;position:fixed;width:615px;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left: 35%;padding:20px 20px;top:10px;font-size: 16px;\">\r\n <div id=\"href\" style=\"color: rgb(32,33,36);\"></div>\r\n <div style=\"margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;\">You do not have access to the system.</div>\r\n <div style=\"display: flex;justify-content: flex-end;\">\r\n <button id=\"cancel\" style=\"padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;\">Cancel</button>\r\n <button id=\"confirm\" style=\"padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;\">Sign in to another ZERO account</button>\r\n </div>\r\n </div>`\r\n let confirmDialog=document.getElementsByTagName('body')[0];\r\n confirmDialog.innerHTML = '';\r\n confirmDialog.insertAdjacentHTML(\"beforeend\", html);\r\n document.getElementById('href').innerHTML = window.location.hostname;\r\n document.getElementById('confirm').onclick = confirms;\r\n document.getElementById('cancel').onclick = cancels;\r\n}\r\nfunction createDoalogMobile(){\r\n let html = `<div id=\"confirm-container\" style=\"box-sizing:border-box;position:fixed;width:97.6vw;height:145px;box-shadow: 0 0 2px 2px #eeeeee;border-radius: 5px;z-index: 10000000;display: block;left:0px;padding:20px 20px;top:4px;margin:0 4px;font-size: 16px;\">\r\n <div id=\"href\" style=\"color: rgb(32,33,36);\"></div>\r\n <div style=\"margin: 10px 0 20px 0;color: rgb(32,33,36);font-size: 14px;\">You do not have access to the system.</div>\r\n <div style=\"display: flex;justify-content: flex-end;\">\r\n <div style=\"display: flex;justify-content: flex-end;\">\r\n <button id=\"cancel\" style=\"padding: 8px 15px;background: #ffffff;color:rgb(26,115,232);border:1px solid #ccc;border-radius:5px;cursor: pointer;font-size:14px;\">Cancel</button>\r\n <button id=\"confirm\" style=\"padding: 8px 15px;background: rgb(26,115,232);color:#ffffff;border:none;border-radius:5px;margin-left: 10px;cursor: pointer;font-size:14px;\">Sign in to another ZERO account</button>\r\n </div>\r\n </div>\r\n </div>`\r\n let confirmDialog=document.getElementsByTagName('body')[0];\r\n confirmDialog.innerHTML = '';\r\n confirmDialog.insertAdjacentHTML(\"beforeend\", html);\r\n document.getElementById('href').innerHTML = window.location.hostname;\r\n document.getElementById('confirm').onclick = confirms;\r\n document.getElementById('cancel').onclick = cancels;\r\n}\r\nfunction confirms() {\r\n clearLoginCookie();\r\n document.getElementById('confirm-container').style.display = 'none';\r\n if (window.location.href.indexOf('hedgehood')!==-1){\r\n window.location.href = currentSystemType === 'staff' ? 'https://login' + window.location.hostname.substring(window.location.hostname.indexOf('.')) + '/login' : 'https://trader' + window.location.hostname.substring(window.location.hostname.indexOf('.'));\r\n } else if (window.location.href.indexOf('ddmarketinghub')!==-1) {\r\n window.location.href = \"http://huangcheng.ddmarketinghub.com:8080\";\r\n } else {\r\n window.location.href = currentSystemType === 'staff' ? 'https://login' + window.location.hostname.substring(window.location.hostname.indexOf('.')) + '/login' : 'https://trader' + window.location.hostname.substring(window.location.hostname.indexOf('.'));\r\n }\r\n}\r\nfunction cancels() {\r\n document.getElementById('confirm-container').style.display = 'none';\r\n window.location.href = 'about:blank';\r\n}\r\nfunction IsPC () {\r\n var userAgentInfo = navigator.userAgent;\r\n var Agents = [\r\n 'Android',\r\n 'iPhone',\r\n 'SymbianOS',\r\n 'Windows Phone',\r\n 'iPad',\r\n 'iPod',\r\n ];\r\n var flag = true;\r\n for (var v = 0; v < Agents.length; v++) {\r\n if (userAgentInfo.indexOf(Agents[v]) > 0) {\r\n flag = false;\r\n break;\r\n }\r\n }\r\n return flag;\r\n}\r\n// 获取可访问系统列表\r\nfunction systemLists (systemName, idToken) {\r\n return new Promise((resolve, reject) => {\r\n axios__WEBPACK_IMPORTED_MODULE_0___default()({\r\n url: userRequestUrl + '/session/current/servers',\r\n method: 'get',\r\n headers: {\r\n authorization: 'Bearer ' + idToken,\r\n 'X-tenant-id': tenantId ? tenantId : ''\r\n }\r\n }).then(res => {\r\n if (res.data.code === 200) {\r\n let lists = res.data.content;\r\n if (!systemName) {\r\n IsPC() ? createDoalog() : createDoalogMobile()\r\n } else if (systemName === 'commonLogin') {\r\n resolve(true);\r\n } else if (lists.length === 0) {\r\n IsPC() ? createDoalog() : createDoalogMobile()\r\n } else {\r\n let hasAccess = false;\r\n lists.forEach(item => {\r\n if (systemName.toLowerCase() === item.groupName.toLowerCase()) {\r\n resolve(true);\r\n hasAccess = true;\r\n currentSystemType = item.staffEndpoint ? 'staff' : 'client';\r\n }\r\n })\r\n if (!hasAccess) {\r\n IsPC() ? createDoalog() : createDoalogMobile()\r\n }\r\n }\r\n } else {\r\n resolve(false);\r\n }\r\n }).catch(() => {\r\n resolve(true);\r\n })\r\n })\r\n}\r\n// init初始化\r\nasync function init (requestUrl, loginUrl, systemName, tenant, time = 1000 * 60 * 3) {\r\n tenantId = tenant ? tenant : '';\r\n userLogoutUrl = loginUrl;\r\n return new Promise(async (resolve, reject) => {\r\n if (!getIdToken() || !getRefreshToken()) {\r\n resolve(false);\r\n }\r\n if (requestUrl) {\r\n userRequestUrl = requestUrl;\r\n refreshIdTokenTimer(time);\r\n if (systemName === 'App') {\r\n resolve(true);\r\n } else {\r\n let hasAuth = await systemLists(systemName, getIdToken());\r\n if (hasAuth) {\r\n resolve(true);\r\n } else {\r\n await logout();\r\n resolve(false);\r\n }\r\n }\r\n } else {\r\n alert('Not request url');\r\n reject();\r\n }\r\n })\r\n}\r\n\n\n//# sourceURL=webpack://login-authorization-v2/./index.js?");
20
20
 
21
21
  /***/ }),
22
22
 
package/index.js CHANGED
@@ -256,12 +256,16 @@ async function init (requestUrl, loginUrl, systemName, tenant, time = 1000 * 60
256
256
  if (requestUrl) {
257
257
  userRequestUrl = requestUrl;
258
258
  refreshIdTokenTimer(time);
259
- let hasAuth = await systemLists(systemName, getIdToken());
260
- if (hasAuth) {
259
+ if (systemName === 'App') {
261
260
  resolve(true);
262
261
  } else {
263
- await logout();
264
- resolve(false);
262
+ let hasAuth = await systemLists(systemName, getIdToken());
263
+ if (hasAuth) {
264
+ resolve(true);
265
+ } else {
266
+ await logout();
267
+ resolve(false);
268
+ }
265
269
  }
266
270
  } else {
267
271
  alert('Not request url');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "login-authorization-v2",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "login authorization",
5
5
  "main": "index.js",
6
6
  "scripts": {