From 676f2fcaac7b81bc3a77c2ecc047d508927814d5 Mon Sep 17 00:00:00 2001 From: Derick Montague Date: Mon, 23 Dec 2019 20:53:49 -0600 Subject: Add login form validation - Sending incorrect credentials returns a 401 and we don't want the page to redirect if we are trying to login. Wrapped the redirect in an if block. - Returning a promise used by the logout action, which is needed when not redirecting the page. Didn't add to the if block since other errors that use the router to redirect will need the Promise returned also, e.g. 403. Signed-off-by: Derick Montague Change-Id: I6db706ef7c71ed13baed95dc4264e6ae11d13ad3 --- src/main.js | 2 + src/store/api.js | 6 +- .../modules/Authentication/AuthenticanStore.js | 5 +- src/views/Login/Login.vue | 186 +++++++++++++++------ 4 files changed, 145 insertions(+), 54 deletions(-) diff --git a/src/main.js b/src/main.js index 023c24ec..b69c6591 100644 --- a/src/main.js +++ b/src/main.js @@ -4,6 +4,7 @@ import router from './router'; import store from './store'; import { dateFilter } from 'vue-date-fns'; import { + AlertPlugin, BadgePlugin, ButtonPlugin, CollapsePlugin, @@ -24,6 +25,7 @@ import { Vue.filter('date', dateFilter); +Vue.use(AlertPlugin); Vue.use(BadgePlugin); Vue.use(ButtonPlugin); Vue.use(CollapsePlugin); diff --git a/src/store/api.js b/src/store/api.js index 4918d804..0f8c9484 100644 --- a/src/store/api.js +++ b/src/store/api.js @@ -10,12 +10,16 @@ api.interceptors.response.use(undefined, error => { // TODO: Provide user with a notification and way to keep system active if (response.status == 401) { - window.location = '/login'; + if (response.config.url != '/login') { + window.location = '/login'; + } } if (response.status == 403) { router.push({ name: 'unauthorized' }); } + + return Promise.reject(error); }); export default { diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js index 88456e95..3a554b6b 100644 --- a/src/store/modules/Authentication/AuthenticanStore.js +++ b/src/store/modules/Authentication/AuthenticanStore.js @@ -13,7 +13,7 @@ const AuthenticationStore = { }, mutations: { authRequest(state) { - state.status = 'loading'; + state.status = 'processing'; }, authSuccess(state) { state.status = 'authenticated'; @@ -22,6 +22,9 @@ const AuthenticationStore = { authError(state) { state.status = 'error'; }, + authReset(state) { + state.status = ''; + }, logout(state) { state.status = ''; Cookies.remove('XSRF-TOKEN'); diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue index b6adf9eb..706d3ecc 100644 --- a/src/views/Login/Login.vue +++ b/src/views/Login/Login.vue @@ -1,67 +1,125 @@