Skip to content

Commit bd5d9a7

Browse files
committed
Add a second confirmation when setting the unlock password (sheepzh#355)
1 parent a120a1a commit bd5d9a7

File tree

8 files changed

+101
-57
lines changed

8 files changed

+101
-57
lines changed

.codebeatignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
src/**/*.tsx
2-
src/**/*Wrapper.ts
2+
src/**/*Wrapper.ts
3+
test/**
4+
test-e2e/**
5+
webpack/**

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
"license": "MIT",
2828
"devDependencies": {
2929
"@babel/plugin-transform-modules-commonjs": "^7.26.3",
30-
"@babel/preset-env": "^7.26.7",
30+
"@babel/preset-env": "^7.26.9",
3131
"@crowdin/crowdin-api-client": "^1.41.1",
3232
"@rsdoctor/webpack-plugin": "^0.4.13",
33-
"@swc/core": "^1.10.15",
33+
"@swc/core": "^1.10.16",
3434
"@swc/jest": "^0.2.37",
3535
"@types/chrome": "0.0.304",
3636
"@types/decompress": "^4.2.7",
3737
"@types/echarts": "^5.0.0",
3838
"@types/generate-json-webpack-plugin": "^0.3.7",
3939
"@types/jest": "^29.5.14",
40-
"@types/node": "^22.13.1",
40+
"@types/node": "^22.13.4",
4141
"@types/psl": "^1.1.3",
4242
"@types/punycode": "^2.1.4",
4343
"@types/webpack": "^5.28.5",
@@ -46,31 +46,31 @@
4646
"copy-webpack-plugin": "^12.0.2",
4747
"css-loader": "^7.1.2",
4848
"decompress": "^4.2.1",
49-
"eslint": "^9.20.0",
49+
"eslint": "^9.20.1",
5050
"filemanager-webpack-plugin": "^8.0.0",
5151
"generate-json-webpack-plugin": "^2.0.0",
5252
"html-webpack-plugin": "^5.6.3",
5353
"jest": "^29.7.0",
5454
"jest-environment-jsdom": "^29.7.0",
5555
"mini-css-extract-plugin": "^2.9.2",
56-
"postcss": "^8.5.1",
56+
"postcss": "^8.5.2",
5757
"postcss-loader": "^8.1.1",
5858
"postcss-rtlcss": "^5.6.0",
59-
"puppeteer": "^24.2.0",
60-
"sass": "^1.84.0",
61-
"sass-loader": "^16.0.4",
59+
"puppeteer": "^24.2.1",
60+
"sass": "^1.85.0",
61+
"sass-loader": "^16.0.5",
6262
"style-loader": "^4.0.0",
6363
"ts-loader": "^9.5.2",
6464
"ts-node": "^10.9.2",
6565
"tsconfig-paths": "^4.2.0",
6666
"typescript": "5.7.3",
6767
"url-loader": "^4.1.1",
68-
"webpack": "^5.97.1",
68+
"webpack": "^5.98.0",
6969
"webpack-cli": "^6.0.1"
7070
},
7171
"dependencies": {
7272
"@element-plus/icons-vue": "^2.3.1",
73-
"@vueuse/core": "^12.5.0",
73+
"@vueuse/core": "^12.7.0",
7474
"countup.js": "^2.8.0",
7575
"echarts": "^5.6.0",
7676
"element-plus": "2.9.4",
@@ -83,4 +83,4 @@
8383
"engines": {
8484
"node": ">=20"
8585
}
86-
}
86+
}

src/i18n/message/app/option-resource.json

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"strict": "不允许手动解锁",
7373
"strictTitle": "危险操作",
7474
"strictContent": "当您选择这个选项之后,如果某个站点触发了每日限制,除了等到第二天自动解锁以外,不允许您手动解锁。如果规则设置不当,很有可能会阻碍您的日常工作!",
75-
"passwordContent": "请设置您的解锁密码"
75+
"pswFormLabel": "解锁密码",
76+
"pswFormAgain": "再次输入"
7677
}
7778
},
7879
"backup": {
@@ -201,8 +202,7 @@
201202
},
202203
"strict": "不允許手動解鎖",
203204
"strictTitle": "危險操作",
204-
"strictContent": "當您選擇這個選項之後,如果某個網站觸發了每日限制,除了等到第二天自動解鎖以外,不允許您手動解鎖。 如果規則設定不當,很有可能會阻礙您的日常工作!",
205-
"passwordContent": "請設定您的解鎖密碼"
205+
"strictContent": "當您選擇這個選項之後,如果某個網站觸發了每日限制,除了等到第二天自動解鎖以外,不允許您手動解鎖。 如果規則設定不當,很有可能會阻礙您的日常工作!"
206206
}
207207
},
208208
"backup": {
@@ -331,7 +331,8 @@
331331
"strict": "Not allow unlocking anyway",
332332
"strictTitle": "Operation confirm",
333333
"strictContent": "When you select this option, if a site triggers daily limit, you will not be allowed to manually unblock it other than waiting until the next day. If rules are not set up properly, they can very well hinder your routines!",
334-
"passwordContent": "Please set your unlock password"
334+
"pswFormLabel": "Password",
335+
"pswFormAgain": "Re-enter"
335336
}
336337
},
337338
"backup": {
@@ -460,8 +461,7 @@
460461
},
461462
"strict": "とにかくロック解除を許可しない",
462463
"strictTitle": "操作確認",
463-
"strictContent": "このオプションを選択した場合、サイトが毎日の制限をトリガーする場合 手動でブロックを解除することは翌日まで待つ以外はできません ルールが適切に設定されていない場合、彼らはあなたのルーチンを非常によく妨げることができます!",
464-
"passwordContent": "ロック解除パスワードを設定してください"
464+
"strictContent": "このオプションを選択した場合、サイトが毎日の制限をトリガーする場合 手動でブロックを解除することは翌日まで待つ以外はできません ルールが適切に設定されていない場合、彼らはあなたのルーチンを非常によく妨げることができます!"
465465
}
466466
},
467467
"backup": {
@@ -589,8 +589,7 @@
589589
},
590590
"strict": "Não permitir desbloqueio mesmo assim",
591591
"strictTitle": "Confirmação de operação",
592-
"strictContent": "Ao selecionar esta opção, se um site acionar o limite diário, você não poderá desbloqueá-lo manualmente, a não ser esperar até o dia seguinte. Se as regras não forem configuradas corretamente, elas podem atrapalhar suas rotinas!",
593-
"passwordContent": "Por favor, defina a sua palavra-passe de desbloqueio"
592+
"strictContent": "Ao selecionar esta opção, se um site acionar o limite diário, você não poderá desbloqueá-lo manualmente, a não ser esperar até o dia seguinte. Se as regras não forem configuradas corretamente, elas podem atrapalhar suas rotinas!"
594593
}
595594
},
596595
"backup": {
@@ -717,8 +716,7 @@
717716
},
718717
"strict": "Не дозволяти розблокування",
719718
"strictTitle": "Підтвердження операції",
720-
"strictContent": "Коли ви вибираєте цю опцію, якщо сайт активує щоденний ліміт, ви не зможете розблокувати його вручну до наступного дня. Якщо не налаштувати правила належним чином, вони можуть дуже заважати вашій роботі!",
721-
"passwordContent": "Встановіть пароль розблокування"
719+
"strictContent": "Коли ви вибираєте цю опцію, якщо сайт активує щоденний ліміт, ви не зможете розблокувати його вручну до наступного дня. Якщо не налаштувати правила належним чином, вони можуть дуже заважати вашій роботі!"
722720
}
723721
},
724722
"backup": {
@@ -845,8 +843,7 @@
845843
},
846844
"strict": "No permitir desbloquear de ningún modo",
847845
"strictTitle": "Confirmación de operación",
848-
"strictContent": "Al seleccionar esta opción, si un sitio activa el límite diario, no se te permitirá desbloquearlo manualmente, más que esperar hasta el día siguiente. ¡Si las reglas no se establecen correctamente, pueden entorpecer tus rutinas!",
849-
"passwordContent": "Por favor, configure su contraseña de desbloqueo"
846+
"strictContent": "Al seleccionar esta opción, si un sitio activa el límite diario, no se te permitirá desbloquearlo manualmente, más que esperar hasta el día siguiente. ¡Si las reglas no se establecen correctamente, pueden entorpecer tus rutinas!"
850847
}
851848
},
852849
"backup": {
@@ -973,8 +970,7 @@
973970
},
974971
"strict": "Entsperren trotzdem nicht zulassen",
975972
"strictTitle": "Operation bestätigen",
976-
"strictContent": "Wenn Sie diese Option wählen, wenn eine Site Tageslimit auslöst, Sie dürfen die Blockierung nur bis zum nächsten Tag manuell entsperren. Wenn Regeln nicht richtig eingerichtet sind, können sie sehr gut Ihre Routinen behindern!",
977-
"passwordContent": "Bitte Passwort zum Entsperren festlegen"
973+
"strictContent": "Wenn Sie diese Option wählen, wenn eine Site Tageslimit auslöst, Sie dürfen die Blockierung nur bis zum nächsten Tag manuell entsperren. Wenn Regeln nicht richtig eingerichtet sind, können sie sehr gut Ihre Routinen behindern!"
978974
}
979975
},
980976
"backup": {
@@ -1101,8 +1097,7 @@
11011097
},
11021098
"strict": "Ne pas autoriser le déblocage quand même",
11031099
"strictTitle": "Confirmation de l'opération",
1104-
"strictContent": "Lorsque vous sélectionnez cette option, si un site déclenche une limite quotidienne, vous ne serez pas autorisé à le débloquer manuellement sauf en attendant le lendemain. Si les règles ne sont pas correctement configurées, elles peuvent très bien gêner vos routines !",
1105-
"passwordContent": "Veuillez définir votre mot de passe de déverrouillage"
1100+
"strictContent": "Lorsque vous sélectionnez cette option, si un site déclenche une limite quotidienne, vous ne serez pas autorisé à le débloquer manuellement sauf en attendant le lendemain. Si les règles ne sont pas correctement configurées, elles peuvent très bien gêner vos routines !"
11061101
}
11071102
},
11081103
"backup": {

src/i18n/message/app/option.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export type OptionMessage = {
7272
}
7373
strictTitle: string
7474
strictContent: string
75-
passwordContent: string
75+
pswFormLabel: string
76+
pswFormAgain: string
7677
}
7778
}
7879
backup: {

src/pages/app/components/Limit/LimitTable/column/LimitEnabledColumn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const _default = defineComponent({
2020
setup(_, ctx) {
2121
const handleChange = async (row: timer.limit.Item, newVal: boolean) => {
2222
try {
23-
newVal && await verifyCanModify(row)
23+
!newVal && await verifyCanModify(row)
2424
row.enabled = newVal
2525
ctx.emit("rowChange", toRaw(row), newVal)
2626
} catch (e) {

src/pages/app/components/Option/components/LimitOption/index.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
*/
77
import { t } from "@app/locale"
88
import { processVerification } from "@app/util/limit"
9-
import { Edit, Lock } from "@element-plus/icons-vue"
9+
import { Edit } from "@element-plus/icons-vue"
1010
import { defaultDailyLimit } from "@util/constant/option"
1111
import { ElButton, ElInput, ElInputNumber, ElMessage, ElMessageBox, ElOption, ElSelect, ElSwitch } from "element-plus"
1212
import { defineComponent } from "vue"
1313
import { type OptionInstance } from "../../common"
1414
import { useOption } from "../../useOption"
1515
import OptionItem from "../OptionItem"
1616
import "./limit-option.sass"
17+
import { usePswEdit } from "./usePswEdit"
1718
import { useVerify } from "./useVerify"
1819

1920
const ALL_LEVEL: timer.limit.RestrictionLevel[] = [
@@ -59,34 +60,10 @@ const confirm4Strict = async (): Promise<void> => {
5960
})
6061
}
6162

62-
const modifyPsw = async (oldPsw?: string): Promise<string> => {
63-
const content = t(msg => msg.option.dailyLimit.level.passwordContent)
64-
const data = await ElMessageBox({
65-
message: content,
66-
type: 'success',
67-
icon: <Lock />,
68-
confirmButtonText: t(msg => msg.button.save),
69-
showCancelButton: true,
70-
cancelButtonText: t(msg => msg.button.cancel),
71-
showInput: true,
72-
inputValue: oldPsw,
73-
closeOnClickModal: false,
74-
})
75-
const { action, value } = data || {}
76-
if (action !== 'confirm') {
77-
ElMessage.warning("Unknown action: " + action)
78-
throw "Ignore this message"
79-
} else if (!value) {
80-
ElMessage.error("No password filled in")
81-
throw "No password filled in"
82-
}
83-
return value
84-
}
85-
8663
const _default = defineComponent((_, ctx) => {
8764
const { option } = useOption({ defaultValue: defaultDailyLimit, copy })
88-
8965
const { verified, verify } = useVerify(option)
66+
const { modifyPsw } = usePswEdit({ reset: () => option.limitPassword })
9067

9168
ctx.expose({
9269
reset: () => verify().then(() => reset(option)).catch(() => { })
@@ -109,7 +86,7 @@ const _default = defineComponent((_, ctx) => {
10986
const handlePswEdit = async () => {
11087
try {
11188
await verify()
112-
option.limitPassword = await modifyPsw(option.limitPassword)
89+
option.limitPassword = await modifyPsw()
11390
ElMessage.success(t(msg => msg.operation.successMsg))
11491
} catch (e) {
11592
console.log("Failed to verify", e)

src/pages/app/components/Option/components/LimitOption/limit-option.sass

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
.option-daily-limit-psw-box
2+
.el-message-box__container
3+
padding: 15px 10px
4+
.el-message-box__status
5+
display: none
6+
.el-message-box__message
7+
flex: 1
8+
19
.option-daily-limit-level-select>.el-select__wrapper
210
width: 100% !important
311

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { t } from "@app/locale"
2+
import { useState } from "@hooks/useState"
3+
import { ElForm, ElFormItem, ElInput, ElMessage, ElMessageBox } from "element-plus"
4+
5+
type Options = {
6+
reset: () => string
7+
}
8+
9+
export const usePswEdit = (options: Options) => {
10+
const { reset } = options || {}
11+
12+
const [psw, setPsw] = useState(reset?.())
13+
const [confirmPsw, setConfirmPsw, resetConfirmPsw] = useState('')
14+
15+
const modifyPsw = async (): Promise<string> => {
16+
setPsw(reset?.())
17+
resetConfirmPsw()
18+
19+
const action = await ElMessageBox({
20+
title: t(msg => msg.option.dailyLimit.level.password),
21+
message: (
22+
<ElForm labelWidth={120} labelPosition="left">
23+
<ElFormItem required label={t(msg => msg.option.dailyLimit.level.pswFormLabel)}>
24+
<ElInput modelValue={psw.value} onInput={setPsw} />
25+
</ElFormItem>
26+
<ElFormItem required label={t(msg => msg.option.dailyLimit.level.pswFormAgain)}>
27+
<ElInput modelValue={confirmPsw.value} onInput={setConfirmPsw} />
28+
</ElFormItem>
29+
</ElForm>
30+
),
31+
customClass: 'option-daily-limit-psw-box',
32+
confirmButtonText: t(msg => msg.button.confirm),
33+
showCancelButton: true,
34+
cancelButtonText: t(msg => msg.button.cancel),
35+
closeOnClickModal: false,
36+
beforeClose(action, instance, done) {
37+
if (action === 'confirm') {
38+
// check input
39+
if (!psw.value) {
40+
return ElMessage.error("No password filled in")
41+
} else if (!confirmPsw.value) {
42+
return ElMessage.error("Please re-enter the password")
43+
} else if (psw.value !== confirmPsw.value) {
44+
return ElMessage.error("The two passwords you entered are different")
45+
} else {
46+
instance.action = action
47+
instance.inputValue = psw.value
48+
}
49+
}
50+
done()
51+
},
52+
})
53+
if (action !== 'confirm') {
54+
ElMessage.warning("Unknown action: " + action)
55+
throw "Ignore this message"
56+
}
57+
return psw.value
58+
}
59+
return { modifyPsw }
60+
}

0 commit comments

Comments
 (0)