fix: 防止在设置中意外清空 CAPTCHA 密钥

This commit is contained in:
Baobhan Sith
2025-05-04 07:36:44 +08:00
parent b8ddfe1528
commit dbb6805268
+11 -3
View File
@@ -1269,15 +1269,23 @@ const handleUpdateCaptchaSettings = async () => {
captchaMessage.value = ''; captchaMessage.value = '';
captchaSuccess.value = false; captchaSuccess.value = false;
try { try {
// Prepare DTO, ensuring keys are present even if empty // Prepare DTO, only sending secret keys if they have been entered
const dto: UpdateCaptchaSettingsDto = { const dto: UpdateCaptchaSettingsDto = {
enabled: captchaForm.enabled, enabled: captchaForm.enabled,
provider: captchaForm.provider, provider: captchaForm.provider,
// Site keys are not sensitive, send them if present
hcaptchaSiteKey: captchaForm.hcaptchaSiteKey || '', hcaptchaSiteKey: captchaForm.hcaptchaSiteKey || '',
hcaptchaSecretKey: captchaForm.hcaptchaSecretKey || '', // Send secret key
recaptchaSiteKey: captchaForm.recaptchaSiteKey || '', recaptchaSiteKey: captchaForm.recaptchaSiteKey || '',
recaptchaSecretKey: captchaForm.recaptchaSecretKey || '', // Send secret key
}; };
// Only include secret keys in the DTO if the user entered a value
if (captchaForm.hcaptchaSecretKey) {
dto.hcaptchaSecretKey = captchaForm.hcaptchaSecretKey;
}
if (captchaForm.recaptchaSecretKey) {
dto.recaptchaSecretKey = captchaForm.recaptchaSecretKey;
}
await settingsStore.updateCaptchaSettings(dto); await settingsStore.updateCaptchaSettings(dto);
captchaMessage.value = t('settings.captcha.success.saved'); // Need translation captchaMessage.value = t('settings.captcha.success.saved'); // Need translation
captchaSuccess.value = true; captchaSuccess.value = true;