From 414084e6b94890b30671e2f086e77a54092f9cf2 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sat, 21 Nov 2020 12:24:27 +0800 Subject: [PATCH] user need input current pin code when disable application lock --- src/lib/userstate.js | 8 ++++ src/locales/en.js | 3 ++ src/locales/zh_Hans.js | 3 ++ src/views/mobile/ApplicationLock.vue | 62 +++++++++++++++++++++++++--- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/lib/userstate.js b/src/lib/userstate.js index b7d9c55e..1abc3084 100644 --- a/src/lib/userstate.js +++ b/src/lib/userstate.js @@ -79,6 +79,13 @@ function decryptToken() { sessionStorage.removeItem(appLockSecretSessionStorageKey); } +function isCorrectPinCode(pinCode) { + const secret = getAppLockSecret(pinCode); + const currentSecret = sessionStorage.getItem(appLockSecretSessionStorageKey); + + return secret === currentSecret; +} + function updateToken(token) { if (utils.isString(token)) { if (settings.isEnableApplicationLock()) { @@ -125,6 +132,7 @@ export default { unlockToken, encryptToken, decryptToken, + isCorrectPinCode, updateToken, updateUserInfo, updateTokenAndUserInfo, diff --git a/src/locales/en.js b/src/locales/en.js index a6f89f11..37184a48 100644 --- a/src/locales/en.js +++ b/src/locales/en.js @@ -410,8 +410,11 @@ export default { 'Are you sure you want to log out?': 'Are you sure you want to log out?', 'Unable to logout': 'Unable to logout', 'Application Lock': 'Application Lock', + 'Application lock has been enabled': 'Application lock has been enabled', + 'Application lock is not enabled': 'Application lock is not enabled', 'PIN Code': 'PIN Code', 'Please input a new PIN code. PIN code would encrypt your local data, so you need input this PIN code when you launch this app. If this PIN code is lost, you should re-login.': 'Please input a new PIN code. PIN code would encrypt your local data, so you need input this PIN code when you launch this app. If this PIN code is lost, you should re-login.', + 'Please enter your current PIN code when disable application lock': 'Please enter your current PIN code when disable application lock', 'Exchange Rates Data': 'Exchange Rates Data', 'Base Currency': 'Base Currency', 'Last Updated': 'Last Updated', diff --git a/src/locales/zh_Hans.js b/src/locales/zh_Hans.js index 90e4412f..542de3a8 100644 --- a/src/locales/zh_Hans.js +++ b/src/locales/zh_Hans.js @@ -410,8 +410,11 @@ export default { 'Are you sure you want to log out?': '您确定是否要退出登录?', 'Unable to logout': '无法退出登录', 'Application Lock': '应用锁', + 'Application lock has been enabled': '应用锁已经启用', + 'Application lock is not enabled': '应用锁没有启用', 'PIN Code': 'PIN码', 'Please input a new PIN code. PIN code would encrypt your local data, so you need input this PIN code when you launch this app. If this PIN code is lost, you should re-login.': '请输入一个新的PIN码,PIN码会加密你的本地数据,所以您每次打开应用时都需要输入PIN码。如果您忘记了PIN码,您需要重新登录。', + 'Please enter your current PIN code when disable application lock': '禁用应用锁时需要输入当前的PIN码', 'Exchange Rates Data': '汇率数据', 'Base Currency': '基准货币', 'Last Updated': '最后更新', diff --git a/src/views/mobile/ApplicationLock.vue b/src/views/mobile/ApplicationLock.vue index 8284e7d0..805e4b4d 100644 --- a/src/views/mobile/ApplicationLock.vue +++ b/src/views/mobile/ApplicationLock.vue @@ -9,7 +9,7 @@ - {{ $t('Disable') }} + {{ $t('Disable') }} @@ -38,13 +38,36 @@ - +
+ + + +
+
{{ $t('PIN Code') }}
+
+
+

{{ $t('Please enter your current PIN code when disable application lock') }}

+ + + + + + +
+ +
+
+
+
@@ -54,22 +77,32 @@ export default { return { isEnableApplicationLock: this.$settings.isEnableApplicationLock(), currentPinCodeForEnable: '', - showInputPinCodeSheetForEnable: false + currentPinCodeForDisable: '', + showInputPinCodeSheetForEnable: false, + showInputPinCodeSheetForDisable: false }; }, computed: { - currentPinCodeValid() { + currentPinCodeForEnableValid() { return this.currentPinCodeForEnable && this.currentPinCodeForEnable.length === 6; + }, + currentPinCodeForDisableValid() { + return this.currentPinCodeForDisable && this.currentPinCodeForDisable.length === 6; } }, methods: { enable(pinCode) { + if (this.$settings.isEnableApplicationLock()) { + this.$alert('Application lock has been enabled'); + return; + } + if (!pinCode) { this.showInputPinCodeSheetForEnable = true; return; } - if (!this.currentPinCodeValid) { + if (!this.currentPinCodeForEnableValid) { this.$alert('PIN code is invalid'); return; } @@ -80,10 +113,27 @@ export default { this.showInputPinCodeSheetForEnable = false; }, - disable() { + disable(pinCode) { + if (!this.$settings.isEnableApplicationLock()) { + this.$alert('Application lock is not enabled'); + return; + } + + if (!pinCode) { + this.showInputPinCodeSheetForDisable = true; + return; + } + + if (!this.$user.isCorrectPinCode(pinCode)) { + this.$alert('PIN code is wrong'); + return; + } + this.$user.decryptToken(); this.$settings.setEnableApplicationLock(false); this.isEnableApplicationLock = false; + + this.showInputPinCodeSheetForDisable = false; } } }