From c1e688d8247371b23797df995273bf6df8413bb0 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 19 Jun 2020 16:55:11 +0000 Subject: [PATCH] Can login now without auth --- ayanova/devdocs/todo.txt | 4 - ayanova/src/api/auth.js | 30 ----- ayanova/src/api/authutil.js | 20 ++-- ayanova/src/api/gzapi.js | 32 +++--- ayanova/src/views/login.vue | 213 ++++++++++++++++++++++++------------ 5 files changed, 164 insertions(+), 135 deletions(-) delete mode 100644 ayanova/src/api/auth.js diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index 5a3e08cb..20f740e8 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -6,10 +6,6 @@ WIFI change 5g channel to 52,56,60 and 2g channel to 8 recheck before doing as it seems to vary, maybe someone else's is auto switching -todo: server error "red box" messages have \r\n characters in them - set html directly instead of just inserting text? - see gzdialog stuff just done for implementing - todo: Auth is directly fetching, re-route through gzapi instead diff --git a/ayanova/src/api/auth.js b/ayanova/src/api/auth.js deleted file mode 100644 index 7c31ef96..00000000 --- a/ayanova/src/api/auth.js +++ /dev/null @@ -1,30 +0,0 @@ -/* Xeslint-disable */ - -import { processLogin, processLogout } from "./authutil"; - -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({ - login: login, - password: password - }) - ); - fetchData = await window.$gz.api.status(fetchData); - fetchData = await window.$gz.api.extractBody(fetchData); - await processLogin(fetchData, loggedInWithKnownPassword); - resolve(); - } catch (e) { - reject(e); - } - }); - }, - logout() { - processLogout(); - } -}; diff --git a/ayanova/src/api/authutil.js b/ayanova/src/api/authutil.js index 5f36e201..b954b411 100644 --- a/ayanova/src/api/authutil.js +++ b/ayanova/src/api/authutil.js @@ -11,20 +11,15 @@ export function processLogin(authResponse, loggedInWithKnownPassword) { return reject(); } - //is there an error? - if (authResponse.error) { - return reject(authResponse.error); - } - //is token present? - if (!authResponse.data || !authResponse.data.token) { + if (!authResponse || !authResponse.token) { window.$gz.store.commit( "logItem", "auth::processLogin -> response contains no data" ); return reject(); } - const token = decode(authResponse.data.token); + const token = decode(authResponse.token); if (!token || !token.iss) { window.$gz.store.commit( @@ -52,13 +47,13 @@ export function processLogin(authResponse, loggedInWithKnownPassword) { //Put app relevant items into vuex store so app can use them window.$gz.store.commit("login", { - apiToken: authResponse.data.token, + apiToken: authResponse.token, authenticated: true, userId: Number(token.id), - userName: authResponse.data.name, - roles: authResponse.data.roles, - userType: authResponse.data.usertype, - dlt: authResponse.data.dlt + userName: authResponse.name, + roles: authResponse.roles, + userType: authResponse.usertype, + dlt: authResponse.dlt }); //log the login window.$gz.store.commit( @@ -86,6 +81,7 @@ export function processLogin(authResponse, loggedInWithKnownPassword) { } catch (err) { reject(err); } + resolve(); //------------------------------------------------- }); diff --git a/ayanova/src/api/gzapi.js b/ayanova/src/api/gzapi.js index 5da7aa76..5c11afa4 100644 --- a/ayanova/src/api/gzapi.js +++ b/ayanova/src/api/gzapi.js @@ -452,28 +452,28 @@ export default { /////////////////////////////////// // POST / PUT DATA TO API SERVER // - async upsertEx(route, data) { + async upsertEx(route, data, noToken = false) { try { let that = this; //determine if this is a new or existing record let fetchOptions = undefined; - if (data) { - //data can be blank in a post that triggers an action - if (data.concurrency) { - //has concurrency token, so this is a PUT as it's updating an existing record - fetchOptions = that.fetchPutOptions(data); - } else { - //Does not have a concurrency token so this is a POST as it's posting a new record without a concurrency token - fetchOptions = that.fetchPostOptions(data); - //ensure the route doesn't end in /0 which will happen if it's a new record since the edit forms just send the url here with the ID regardless - if (window.$gz._.endsWith(route, "/0")) { - route = route.slice(0, -2); - } - } + //put? + if (data && data.concurrency) { + fetchOptions = that.fetchPutOptions(data); } else { - //no data, so this is likely just a trigger post - fetchOptions = that.fetchPostOptions(data); + //post + //ensure the route doesn't end in /0 which will happen if it's a new record + //since the edit forms just send the url here with the ID regardless + if (window.$gz._.endsWith(route, "/0")) { + route = route.slice(0, -2); + } + if (noToken == false) { + fetchOptions = that.fetchPostOptions(data); + } else { + fetchOptions = that.fetchPostNoAuthOptions(data); + } } + let r = await fetch(that.APIUrl(route), fetchOptions); that.statusEx(r); r = await that.extractBodyEx(r); diff --git a/ayanova/src/views/login.vue b/ayanova/src/views/login.vue index 6ba76222..9ad117da 100644 --- a/ayanova/src/views/login.vue +++ b/ayanova/src/views/login.vue @@ -85,6 +85,7 @@