|
|
@@ -38,11 +38,11 @@ const actions = { |
|
|
|
refreshUser({ commit }) { |
|
|
|
commit('refreshUser', JSON.parse(localStorage.getItem(util.USER_KEY))); |
|
|
|
}, |
|
|
|
checkSession({ commit }, { messages, errors, session, uri }) { |
|
|
|
checkSession({ commit }, { messages, errors }) { |
|
|
|
commit('checkSessionRequest'); |
|
|
|
userService.getMe(messages, errors, session) |
|
|
|
userService.getMe(messages, errors) |
|
|
|
.then( |
|
|
|
user => commit('checkSessionSuccess', {user, uri}), |
|
|
|
user => commit('checkSessionSuccess', user), |
|
|
|
error => { |
|
|
|
commit('checkSessionFailure', error); |
|
|
|
if (error === 'Unauthorized' || error === 'Not Found' || error === 'Forbidden' ) { |
|
|
@@ -85,6 +85,22 @@ const actions = { |
|
|
|
error => commit('loginFailure', error) |
|
|
|
); |
|
|
|
}, |
|
|
|
appLogin({ commit }, { session, uri, messages, errors }) { |
|
|
|
commit('appLoginRequest'); |
|
|
|
userService.appLogin(session, messages, errors) |
|
|
|
.then( |
|
|
|
user => commit('appLoginSuccess', {user, uri}), |
|
|
|
error => { |
|
|
|
commit('appLoginFailure', error); |
|
|
|
if (error === 'Unauthorized' || error === 'Not Found' || error === 'Forbidden' ) { |
|
|
|
userService.logout(messages, errors).then( |
|
|
|
ok => router.replace('/login'), |
|
|
|
error => router.replace('/login') |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
}, |
|
|
|
logout({ commit }, {messages, errors}) { |
|
|
|
commit('logoutRequest'); |
|
|
|
userService.logout(messages, errors) |
|
|
@@ -202,10 +218,9 @@ const mutations = { |
|
|
|
state.user = user; |
|
|
|
}, |
|
|
|
checkSessionRequest(state) {}, |
|
|
|
checkSessionSuccess(state, {user, uri}) { |
|
|
|
let hasUri = typeof uri !== 'undefined' && uri != null; |
|
|
|
checkSessionSuccess(state, user) { |
|
|
|
if (user.token) { |
|
|
|
if (util.currentUser() === null && !hasUri) { |
|
|
|
if (util.currentUser() === null) { |
|
|
|
// we must have logged out while this request was in flight... do nothing |
|
|
|
state.user = null; |
|
|
|
} else { |
|
|
@@ -215,7 +230,6 @@ const mutations = { |
|
|
|
} |
|
|
|
} |
|
|
|
state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale); |
|
|
|
if (hasUri && user.token) router.replace(uri); |
|
|
|
}, |
|
|
|
checkSessionFailure(state, error) { |
|
|
|
state.user = null; |
|
|
@@ -244,6 +258,26 @@ const mutations = { |
|
|
|
state.user = null; |
|
|
|
}, |
|
|
|
|
|
|
|
appLoginRequest(state) {}, |
|
|
|
appLoginSuccess(state, {user, uri}) { |
|
|
|
if (user.token) { |
|
|
|
if (util.currentUser() === null) { |
|
|
|
// we must have logged out while this request was in flight... do nothing |
|
|
|
state.user = null; |
|
|
|
} else { |
|
|
|
localStorage.setItem(util.USER_KEY, JSON.stringify(user)); |
|
|
|
state.status = Object.assign({}, state.status, {loggingIn: false, loggedIn: true}); |
|
|
|
state.user = user; |
|
|
|
} |
|
|
|
} |
|
|
|
state.locale = (typeof user.locale !== 'undefined' && user.locale !== null ? user.locale : state.locale); |
|
|
|
if (user.token) router.replace(uri); |
|
|
|
}, |
|
|
|
appLoginFailure(state, error) { |
|
|
|
state.user = null; |
|
|
|
state.status = Object.assign({}, state.status, {loggedIn: false}); |
|
|
|
}, |
|
|
|
|
|
|
|
logoutRequest(state) {}, |
|
|
|
logoutSuccess(state) { |
|
|
|
state.status = Object.assign({}, defaultStatus); |
|
|
|