fix(settings): prevent SMTP config overwrite and stabilize test after refresh
This commit is contained in:
@@ -1580,7 +1580,7 @@
|
||||
<button
|
||||
type="button"
|
||||
@click="testSmtpConnection"
|
||||
:disabled="testingSmtp"
|
||||
:disabled="testingSmtp || loadFailed"
|
||||
class="btn btn-secondary btn-sm"
|
||||
>
|
||||
<svg v-if="testingSmtp" class="h-4 w-4 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
@@ -1650,6 +1650,11 @@
|
||||
v-model="form.smtp_password"
|
||||
type="password"
|
||||
class="input"
|
||||
autocomplete="new-password"
|
||||
autocapitalize="off"
|
||||
spellcheck="false"
|
||||
@keydown="smtpPasswordManuallyEdited = true"
|
||||
@paste="smtpPasswordManuallyEdited = true"
|
||||
:placeholder="
|
||||
form.smtp_password_configured
|
||||
? t('admin.settings.smtp.passwordConfiguredPlaceholder')
|
||||
@@ -1732,7 +1737,7 @@
|
||||
<button
|
||||
type="button"
|
||||
@click="sendTestEmail"
|
||||
:disabled="sendingTestEmail || !testEmailAddress"
|
||||
:disabled="sendingTestEmail || !testEmailAddress || loadFailed"
|
||||
class="btn btn-secondary"
|
||||
>
|
||||
<svg
|
||||
@@ -1778,7 +1783,7 @@
|
||||
|
||||
<!-- Save Button -->
|
||||
<div v-show="activeTab !== 'backup' && activeTab !== 'data'" class="flex justify-end">
|
||||
<button type="submit" :disabled="saving" class="btn btn-primary">
|
||||
<button type="submit" :disabled="saving || loadFailed" class="btn btn-primary">
|
||||
<svg v-if="saving" class="h-4 w-4 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
<circle
|
||||
class="opacity-25"
|
||||
@@ -1849,9 +1854,11 @@ const settingsTabs = [
|
||||
const { copyToClipboard } = useClipboard()
|
||||
|
||||
const loading = ref(true)
|
||||
const loadFailed = ref(false)
|
||||
const saving = ref(false)
|
||||
const testingSmtp = ref(false)
|
||||
const sendingTestEmail = ref(false)
|
||||
const smtpPasswordManuallyEdited = ref(false)
|
||||
const testEmailAddress = ref('')
|
||||
const registrationEmailSuffixWhitelistTags = ref<string[]>([])
|
||||
const registrationEmailSuffixWhitelistDraft = ref('')
|
||||
@@ -2116,6 +2123,7 @@ function moveMenuItem(index: number, direction: -1 | 1) {
|
||||
|
||||
async function loadSettings() {
|
||||
loading.value = true
|
||||
loadFailed.value = false
|
||||
try {
|
||||
const settings = await adminAPI.settings.getSettings()
|
||||
Object.assign(form, settings)
|
||||
@@ -2133,9 +2141,11 @@ async function loadSettings() {
|
||||
)
|
||||
registrationEmailSuffixWhitelistDraft.value = ''
|
||||
form.smtp_password = ''
|
||||
smtpPasswordManuallyEdited.value = false
|
||||
form.turnstile_secret_key = ''
|
||||
form.linuxdo_connect_client_secret = ''
|
||||
} catch (error: any) {
|
||||
loadFailed.value = true
|
||||
appStore.showError(
|
||||
t('admin.settings.failedToLoad') + ': ' + (error.message || t('common.unknownError'))
|
||||
)
|
||||
@@ -2257,6 +2267,7 @@ async function saveSettings() {
|
||||
)
|
||||
registrationEmailSuffixWhitelistDraft.value = ''
|
||||
form.smtp_password = ''
|
||||
smtpPasswordManuallyEdited.value = false
|
||||
form.turnstile_secret_key = ''
|
||||
form.linuxdo_connect_client_secret = ''
|
||||
// Refresh cached settings so sidebar/header update immediately
|
||||
@@ -2275,11 +2286,12 @@ async function saveSettings() {
|
||||
async function testSmtpConnection() {
|
||||
testingSmtp.value = true
|
||||
try {
|
||||
const smtpPasswordForTest = smtpPasswordManuallyEdited.value ? form.smtp_password : ''
|
||||
const result = await adminAPI.settings.testSmtpConnection({
|
||||
smtp_host: form.smtp_host,
|
||||
smtp_port: form.smtp_port,
|
||||
smtp_username: form.smtp_username,
|
||||
smtp_password: form.smtp_password,
|
||||
smtp_password: smtpPasswordForTest,
|
||||
smtp_use_tls: form.smtp_use_tls
|
||||
})
|
||||
// API returns { message: "..." } on success, errors are thrown as exceptions
|
||||
@@ -2301,12 +2313,13 @@ async function sendTestEmail() {
|
||||
|
||||
sendingTestEmail.value = true
|
||||
try {
|
||||
const smtpPasswordForSend = smtpPasswordManuallyEdited.value ? form.smtp_password : ''
|
||||
const result = await adminAPI.settings.sendTestEmail({
|
||||
email: testEmailAddress.value,
|
||||
smtp_host: form.smtp_host,
|
||||
smtp_port: form.smtp_port,
|
||||
smtp_username: form.smtp_username,
|
||||
smtp_password: form.smtp_password,
|
||||
smtp_password: smtpPasswordForSend,
|
||||
smtp_from_email: form.smtp_from_email,
|
||||
smtp_from_name: form.smtp_from_name,
|
||||
smtp_use_tls: form.smtp_use_tls
|
||||
|
||||
Reference in New Issue
Block a user