diff --git a/src/lib/userstate.js b/src/lib/userstate.js index a41a3242..d839f6c8 100644 --- a/src/lib/userstate.js +++ b/src/lib/userstate.js @@ -164,6 +164,11 @@ function clearUserInfo() { localStorage.removeItem(userInfoLocalStorageKey); } +function clearSessionToken() { + sessionStorage.removeItem(tokenSessionStorageKey); + sessionStorage.removeItem(appLockStateSessionStorageKey); +} + function clearTokenAndUserInfo(clearAppLockState) { if (clearAppLockState) { sessionStorage.removeItem(appLockStateSessionStorageKey); @@ -191,5 +196,6 @@ export default { updateToken, updateUserInfo, clearUserInfo, + clearSessionToken, clearTokenAndUserInfo }; diff --git a/src/locales/en.js b/src/locales/en.js index ae666d53..e4d990e9 100644 --- a/src/locales/en.js +++ b/src/locales/en.js @@ -1124,6 +1124,7 @@ export default { 'Unable to get current two factor authentication status': 'Unable to get current two factor authentication status', 'Unable to enable two factor authentication': 'Unable to enable two factor authentication', 'Unable to disable two factor authentication': 'Unable to disable two factor authentication', + 'Lock Application': 'Lock Application', 'Log Out': 'Log Out', 'Are you sure you want to log out?': 'Are you sure you want to log out?', 'Unable to logout': 'Unable to logout', diff --git a/src/locales/zh_Hans.js b/src/locales/zh_Hans.js index 30605185..f6896b8a 100644 --- a/src/locales/zh_Hans.js +++ b/src/locales/zh_Hans.js @@ -1124,6 +1124,7 @@ export default { 'Unable to get current two factor authentication status': '无法获取当前两步验证状态', 'Unable to enable two factor authentication': '无法启用两步验证', 'Unable to disable two factor authentication': '无法禁用两步验证', + 'Lock Application': '锁定应用', 'Log Out': '退出登录', 'Are you sure you want to log out?': '您确定要退出登录?', 'Unable to logout': '无法退出登录', diff --git a/src/stores/index.js b/src/stores/index.js index 6bdb9527..881f7184 100644 --- a/src/stores/index.js +++ b/src/stores/index.js @@ -17,9 +17,11 @@ import { isObject, isString } from '@/lib/common.js'; export const useRootStore = defineStore('root', { actions: { - resetAllStates() { - const exchangeRatesStore = useExchangeRatesStore(); - exchangeRatesStore.resetLatestExchangeRates(); + resetAllStates(resetUserInfoAndSettings) { + if (resetUserInfoAndSettings) { + const exchangeRatesStore = useExchangeRatesStore(); + exchangeRatesStore.resetLatestExchangeRates(); + } const statisticsStore = useStatisticsStore(); statisticsStore.resetTransactionStatistics(); @@ -39,8 +41,10 @@ export const useRootStore = defineStore('root', { const accountsStore = useAccountsStore(); accountsStore.resetAccounts(); - const userStore = useUserStore(); - userStore.resetUserInfo(); + if (resetUserInfoAndSettings) { + const userStore = useUserStore(); + userStore.resetUserInfo(); + } }, authorize({ loginName, password }) { const settingsStore = useSettingsStore(); @@ -204,6 +208,10 @@ export const useRootStore = defineStore('root', { }); }); }, + lock() { + userState.clearSessionToken(); + this.resetAllStates(false); + }, logout() { const self = this; @@ -218,7 +226,7 @@ export const useRootStore = defineStore('root', { userState.clearTokenAndUserInfo(true); userState.clearWebAuthnConfig(); - self.resetAllStates(); + self.resetAllStates(true); resolve(data.result); }).catch(error => { @@ -237,7 +245,7 @@ export const useRootStore = defineStore('root', { forceLogout() { userState.clearTokenAndUserInfo(true); userState.clearWebAuthnConfig(); - this.resetAllStates(); + this.resetAllStates(true); }, updateUserProfile({ profile, currentPassword }) { return new Promise((resolve, reject) => { diff --git a/src/views/desktop/MainLayout.vue b/src/views/desktop/MainLayout.vue index 5755fd59..12a067b6 100644 --- a/src/views/desktop/MainLayout.vue +++ b/src/views/desktop/MainLayout.vue @@ -144,6 +144,10 @@ :title="$t('Application Settings')" to="/app/settings"> + 0; }, + lock() { + this.rootStore.lock(); + this.$router.replace('/unlock'); + }, logout() { const self = this;