This commit is contained in:
2020-06-10 23:51:25 +00:00
parent 76b8fbd0cb
commit e0359d5de8
8 changed files with 109 additions and 19 deletions

View File

@@ -6,6 +6,8 @@ export default {
async authenticate(login, password) {
return new Promise(async function doAuth(resolve, reject) {
try {
let loggedInWithKnownPassword =
login == "superuser" && password == "l3tm3in";
let fetchData = await fetch(
window.$gz.api.APIUrl("auth"),
window.$gz.api.fetchPostNoAuthOptions({
@@ -15,7 +17,7 @@ export default {
);
fetchData = await window.$gz.api.status(fetchData);
fetchData = await window.$gz.api.extractBody(fetchData);
await processLogin(fetchData);
await processLogin(fetchData, loggedInWithKnownPassword);
resolve();
} catch (e) {
reject(e);

View File

@@ -2,29 +2,29 @@
import decode from "jwt-decode";
import initialize from "./initialize";
export function processLogin(response) {
export function processLogin(authResponse, loggedInWithKnownPassword) {
return new Promise(async function(resolve, reject) {
try {
//check there is a response of some kind
if (!response) {
if (!authResponse) {
window.$gz.store.commit("logItem", "auth::processLogin -> no response");
return reject();
}
//is there an error?
if (response.error) {
return reject(response.error);
if (authResponse.error) {
return reject(authResponse.error);
}
//is token present?
if (!response.data || !response.data.token) {
if (!authResponse.data || !authResponse.data.token) {
window.$gz.store.commit(
"logItem",
"auth::processLogin -> response contains no data"
);
return reject();
}
const token = decode(response.data.token);
const token = decode(authResponse.data.token);
if (!token || !token.iss) {
window.$gz.store.commit(
@@ -46,15 +46,19 @@ export function processLogin(response) {
window.$gz.store.commit("logout");
sessionStorage.clear(); //clear all temporary session storage data
//encourage password changing if a purchased license
if (loggedInWithKnownPassword)
window.$gz.store.commit("setKnownPassword", true);
//Put app relevant items into vuex store so app can use them
window.$gz.store.commit("login", {
apiToken: response.data.token,
apiToken: authResponse.data.token,
authenticated: true,
userId: Number(token.id),
userName: response.data.name,
roles: response.data.roles,
userType: response.data.usertype,
dlt: response.data.dlt
userName: authResponse.data.name,
roles: authResponse.data.roles,
userType: authResponse.data.usertype,
dlt: authResponse.data.dlt
});
//log the login
window.$gz.store.commit(

View File

@@ -14,7 +14,7 @@ function addNavItem(title, icon, route, navItems, key, testid) {
});
}
function initNavPanal() {
function initNavPanel() {
let key = 0;
let sub = [];
@@ -777,8 +777,18 @@ export default function initialize() {
await window.$gz.translation.cacheTranslations(
window.$gz.translation.coreKeys
);
await initNavPanal();
initNavPanel();
await getUserOptions();
//check for known password and a purchased licensed mode
if (
window.$gz.store.state.knownPassword &&
(window.$gz.store.state.globalSettings.licenseStatus == 3 || //ActivePurchased = 3,
window.$gz.store.state.globalSettings.licenseStatus == 4) // ExpiredPurchased = 4
) {
window.$gz.store.commit("setHomePage", "/home-password");
}
resolve();
} catch (err) {
reject(err);