Browse Source

logout if session is invalid

pull/1/head
Jonathan Cobb 4 years ago
parent
commit
d79ef0adea
2 changed files with 28 additions and 29 deletions
  1. +27
    -28
      src/_store/account.module.js
  2. +1
    -1
      src/app/App.vue

+ 27
- 28
src/_store/account.module.js View File

@@ -1,4 +1,4 @@
import { userService, systemService } from '../_services';
import { userService } from '../_services';
import { router, util } from '../_helpers'; import { router, util } from '../_helpers';


const user = util.currentUser(); const user = util.currentUser();
@@ -154,7 +154,7 @@ const actions = {


const mutations = { const mutations = {
refreshUser(state, user) { refreshUser(state, user) {
state.status.loggedIn = (user !== null);
state.status = Object.assign({}, state.status, {loggedIn: (user !== null)});
state.user = user; state.user = user;
}, },
checkSessionRequest(state) {}, checkSessionRequest(state) {},
@@ -167,16 +167,15 @@ const mutations = {
}, },
checkSessionFailure(state, error) { checkSessionFailure(state, error) {
state.user = null; state.user = null;
state.status.loggedIn = false;
state.status = Object.assign({}, state.status, {loggedIn: false});
}, },
loginRequest(state, user) { loginRequest(state, user) {
state.status.loggingIn = true;
state.status = Object.assign({}, state.status, {loggingIn: true});
state.user = user; state.user = user;
}, },
loginSuccess(state, user) { loginSuccess(state, user) {
if (user.token) { if (user.token) {
state.status.loggingIn = false;
state.status.loggedIn = true;
state.status = Object.assign({}, state.status, {loggingIn: false, loggedIn: true});
} else if (user.multifactorAuth) { } else if (user.multifactorAuth) {
state.status = { multifactorAuth: true }; state.status = { multifactorAuth: true };
} else { } else {
@@ -187,7 +186,7 @@ const mutations = {
state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale); state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale);
}, },
loginFailure(state) { loginFailure(state) {
state.status.loggingIn = false;
state.status = Object.assign({}, state.status, {loggingIn: false, loggedIn: false});
state.user = null; state.user = null;
}, },


@@ -197,24 +196,24 @@ const mutations = {
}, },


registerRequest(state, user) { registerRequest(state, user) {
state.status.registering = true;
state.status = Object.assign({}, state.status, {registering: true});
state.user = user; state.user = user;
}, },
registerSuccess(state, user) { registerSuccess(state, user) {
state.user = user; state.user = user;
state.status.registering = false;
state.status = Object.assign({}, state.status, {registering: false});
localStorage.setItem(util.USER_KEY, JSON.stringify(user)); localStorage.setItem(util.USER_KEY, JSON.stringify(user));
state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale); state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale);
state.registrationError = null; state.registrationError = null;
}, },
registerFailure(state, error) { registerFailure(state, error) {
state.status.registering = false;
state.status = Object.assign({}, state.status, {registering: false});
state.status = {}; state.status = {};
state.registrationError = error; state.registrationError = error;
}, },


setLocaleRequest(state, locale) { setLocaleRequest(state, locale) {
state.status.settingLocale = true;
state.status = Object.assign({}, state.status, {settingLocale: true});
state.locale = locale; state.locale = locale;
const user = util.currentUser(); const user = util.currentUser();
if (user === null) { if (user === null) {
@@ -227,60 +226,60 @@ const mutations = {
}, },
setLocaleSuccess(state, user) { setLocaleSuccess(state, user) {
state.locale = ''+state.locale; state.locale = ''+state.locale;
state.status.settingLocale = false;
state.status = Object.assign({}, state.status, {settingLocale: false});
}, },
setLocaleFailure(state) { setLocaleFailure(state) {
state.status.settingLocale = false;
state.status = Object.assign({}, state.status, {settingLocale: false});
state.status = {}; state.status = {};
}, },


updateRequest(state, user) { updateRequest(state, user) {
state.status.updating = true;
state.status = Object.assign({}, state.status, {updating: true});
state.user = user; state.user = user;
}, },
updateSuccess(state, user) { updateSuccess(state, user) {
state.status.updating = false;
state.status = Object.assign({}, state.status, {updating: false});
localStorage.setItem(util.USER_KEY, JSON.stringify(user)); localStorage.setItem(util.USER_KEY, JSON.stringify(user));
state.user = user; state.user = user;
state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale); state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale);
}, },
updateFailure(state) { updateFailure(state) {
state.status.updating = false;
state.status = Object.assign({}, state.status, {updating: false});
state.status = {}; state.status = {};
}, },


approveActionRequest(state) { approveActionRequest(state) {
state.status.approving = true;
state.status = Object.assign({}, state.status, {approving: true});
state.actionStatus = { requesting: true, type: 'approve' }; state.actionStatus = { requesting: true, type: 'approve' };
}, },
approveActionSuccess(state, user) { approveActionSuccess(state, user) {
state.status.approving = false;
state.status = Object.assign({}, state.status, {approving: false});
state.actionStatus = { success: true, type: 'approve', result: user }; state.actionStatus = { success: true, type: 'approve', result: user };
if (user.token) state.user = user; if (user.token) state.user = user;
}, },
approveActionFailure(state, error) { approveActionFailure(state, error) {
state.status.approving = false;
state.status = Object.assign({}, state.status, {approving: false});
state.actionStatus = { error: error, type: 'approve' }; state.actionStatus = { error: error, type: 'approve' };
}, },
denyActionRequest(state) { denyActionRequest(state) {
state.status.denying = true;
state.status = Object.assign({}, state.status, {denying: true});
state.actionStatus = { requesting: true, type: 'deny' }; state.actionStatus = { requesting: true, type: 'deny' };
}, },
denyActionSuccess(state, denial) { denyActionSuccess(state, denial) {
state.status.denying = false;
state.status = Object.assign({}, state.status, {denying: false});
state.actionStatus = { success: true, type: 'deny', result: denial }; state.actionStatus = { success: true, type: 'deny', result: denial };
state.denial = denial; state.denial = denial;
}, },
denyActionFailure(state, error) { denyActionFailure(state, error) {
state.status.denying = false;
state.status = Object.assign({}, state.status, {denying: false});
state.actionStatus = { error: error, type: 'deny' }; state.actionStatus = { error: error, type: 'deny' };
}, },
sendAuthenticatorCodeRequest(state) { sendAuthenticatorCodeRequest(state) {
state.status.authenticating = true;
state.status = Object.assign({}, state.status, {authenticating: true});
state.actionStatus = { requesting: true, type: 'approve' }; state.actionStatus = { requesting: true, type: 'approve' };
}, },
sendAuthenticatorCodeSuccess(state, user, messages) { sendAuthenticatorCodeSuccess(state, user, messages) {
state.status.authenticating = false;
state.status = Object.assign({}, state.status, {authenticating: false});
state.actionStatus = { success: true, type: 'approve', result: user }; state.actionStatus = { success: true, type: 'approve', result: user };
console.log('auth successful -- setting window.showTotpModal = false'); console.log('auth successful -- setting window.showTotpModal = false');
window.showTotpModal = false; window.showTotpModal = false;
@@ -295,20 +294,20 @@ const mutations = {
} }
}, },
sendAuthenticatorCodeFailure(state, error) { sendAuthenticatorCodeFailure(state, error) {
state.status.authenticating = false;
state.status = Object.assign({}, state.status, {authenticating: false});
state.actionStatus = { error: error, type: 'approve' }; state.actionStatus = { error: error, type: 'approve' };
}, },


resendVerificationCodeRequest(state) { resendVerificationCodeRequest(state) {
state.status.sendingVerification = true;
state.status = Object.assign({}, state.status, {sendingVerification: true});
state.actionStatus = { requesting: true, type: 'verify' }; state.actionStatus = { requesting: true, type: 'verify' };
}, },
resendVerificationCodeSuccess(state, policy) { resendVerificationCodeSuccess(state, policy) {
state.status.sendingVerification = false;
state.status = Object.assign({}, state.status, {sendingVerification: false});
state.actionStatus = { success: true, type: 'verify', result: policy }; state.actionStatus = { success: true, type: 'verify', result: policy };
}, },
resendVerificationCodeFailure(state, error) { resendVerificationCodeFailure(state, error) {
state.status.sendingVerification = false;
state.status = Object.assign({}, state.status, {sendingVerification: false});
state.actionStatus = { error: error, type: 'verify' }; state.actionStatus = { error: error, type: 'verify' };
} }
}; };


+ 1
- 1
src/app/App.vue View File

@@ -76,7 +76,7 @@ export default {
}, },
user (u) { user (u) {
if (typeof u === 'undefined' || u === null || typeof u.locale === 'undefined' || u.locale === null) { if (typeof u === 'undefined' || u === null || typeof u.locale === 'undefined' || u.locale === null) {
if (this.activated && status.registrationError === null) {
if (this.activated && (typeof status.registrationError === 'undefined' || status.registrationError === null)) {
this.logout(); this.logout();
this.$router.replace('/logout'); this.$router.replace('/logout');
} }


Loading…
Cancel
Save