UX-parannukset postilaatikon asetuksiin
- Poista SMTP override-testikentät (ei tarpeen enää) - Tallennus pitää lomakkeen auki + näyttää "Tallennettu" -ilmoituksen - SMTP-kenttäjärjestys samaksi kuin IMAP: Palvelin → Portti → Tunnus → Salasana → Salaus Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
8
api.php
8
api.php
@@ -2996,19 +2996,12 @@ switch ($action) {
|
|||||||
'smtp_encryption' => $mailbox['smtp_encryption'] ?? '',
|
'smtp_encryption' => $mailbox['smtp_encryption'] ?? '',
|
||||||
'smtp_from_email' => $mailbox['smtp_from_email'] ?? '',
|
'smtp_from_email' => $mailbox['smtp_from_email'] ?? '',
|
||||||
];
|
];
|
||||||
// Override: käyttäjä voi antaa tunnukset suoraan testiin (ohittaa DB:n)
|
|
||||||
$overrideUser = trim($input['override_user'] ?? '');
|
|
||||||
$overridePass = $input['override_pass'] ?? '';
|
|
||||||
// Laske fallback-arvot
|
// Laske fallback-arvot
|
||||||
$effectiveUser = $mailbox['smtp_user'] ?? '';
|
$effectiveUser = $mailbox['smtp_user'] ?? '';
|
||||||
if ($effectiveUser === '') $effectiveUser = $mailbox['imap_user'] ?? '';
|
if ($effectiveUser === '') $effectiveUser = $mailbox['imap_user'] ?? '';
|
||||||
if ($effectiveUser === '') $effectiveUser = $mailbox['smtp_from_email'] ?? '';
|
if ($effectiveUser === '') $effectiveUser = $mailbox['smtp_from_email'] ?? '';
|
||||||
$effectivePass = $mailbox['smtp_password'] ?? '';
|
$effectivePass = $mailbox['smtp_password'] ?? '';
|
||||||
if ($effectivePass === '') $effectivePass = $mailbox['imap_password'] ?? '';
|
if ($effectivePass === '') $effectivePass = $mailbox['imap_password'] ?? '';
|
||||||
// Jos override annettu, käytä sitä
|
|
||||||
$usingOverride = false;
|
|
||||||
if ($overrideUser !== '') { $effectiveUser = $overrideUser; $usingOverride = true; }
|
|
||||||
if ($overridePass !== '') { $effectivePass = $overridePass; $usingOverride = true; }
|
|
||||||
$host = $mailbox['smtp_host'] ?? '';
|
$host = $mailbox['smtp_host'] ?? '';
|
||||||
$port = (int)($mailbox['smtp_port'] ?? 587);
|
$port = (int)($mailbox['smtp_port'] ?? 587);
|
||||||
$encryption = $mailbox['smtp_encryption'] ?? 'tls';
|
$encryption = $mailbox['smtp_encryption'] ?? 'tls';
|
||||||
@@ -3022,7 +3015,6 @@ switch ($action) {
|
|||||||
'effective_user' => $effectiveUser,
|
'effective_user' => $effectiveUser,
|
||||||
'effective_pass_hint' => $passHint,
|
'effective_pass_hint' => $passHint,
|
||||||
'effective_pass_len' => strlen($effectivePass),
|
'effective_pass_len' => strlen($effectivePass),
|
||||||
'using_override' => $usingOverride,
|
|
||||||
'steps' => [],
|
'steps' => [],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
10
index.html
10
index.html
@@ -831,11 +831,11 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group"><label>Palvelin</label><input type="text" id="mailbox-form-smtp-host" placeholder="smtp.yritys.fi"></div>
|
<div class="form-group"><label>Palvelin</label><input type="text" id="mailbox-form-smtp-host" placeholder="smtp.yritys.fi"></div>
|
||||||
|
<div class="form-group"><label>Portti</label><input type="number" id="mailbox-form-smtp-port" value="587" placeholder="587"></div>
|
||||||
<div id="smtp-custom-fields">
|
<div id="smtp-custom-fields">
|
||||||
<div class="form-group"><label>Käyttäjätunnus</label><input type="text" id="mailbox-form-smtp-user" placeholder="asiakaspalvelu@yritys.fi"></div>
|
<div class="form-group"><label>Käyttäjätunnus</label><input type="text" id="mailbox-form-smtp-user" placeholder="asiakaspalvelu@yritys.fi"></div>
|
||||||
<div class="form-group"><label>Salasana</label><input type="password" id="mailbox-form-smtp-pass" placeholder="••••••••"></div>
|
<div class="form-group"><label>Salasana</label><input type="password" id="mailbox-form-smtp-pass" placeholder="••••••••"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group"><label>Portti</label><input type="number" id="mailbox-form-smtp-port" value="587" placeholder="587"></div>
|
|
||||||
<div class="form-group"><label>Salaus</label>
|
<div class="form-group"><label>Salaus</label>
|
||||||
<select id="mailbox-form-smtp-encryption">
|
<select id="mailbox-form-smtp-encryption">
|
||||||
<option value="tls">STARTTLS</option>
|
<option value="tls">STARTTLS</option>
|
||||||
@@ -862,14 +862,6 @@
|
|||||||
<button class="btn-secondary" id="btn-test-smtp" style="background:#2196F3;color:#fff;border:none;">🔌 Testaa SMTP</button>
|
<button class="btn-secondary" id="btn-test-smtp" style="background:#2196F3;color:#fff;border:none;">🔌 Testaa SMTP</button>
|
||||||
<button class="btn-secondary" id="btn-cancel-mailbox">Peruuta</button>
|
<button class="btn-secondary" id="btn-cancel-mailbox">Peruuta</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="smtp-test-override" style="display:none;margin-top:0.5rem;padding:0.75rem;background:#f0f4ff;border-radius:6px;">
|
|
||||||
<div style="font-size:0.8rem;color:#666;margin-bottom:0.4rem;">Testaa eri tunnuksilla (ohittaa tietokannan):</div>
|
|
||||||
<div style="display:flex;gap:0.5rem;align-items:center;flex-wrap:wrap;">
|
|
||||||
<input type="text" id="smtp-test-user" placeholder="Käyttäjä (tyhjä = DB)" style="flex:1;min-width:150px;padding:0.3rem 0.5rem;font-size:0.85rem;">
|
|
||||||
<input type="password" id="smtp-test-pass" placeholder="Salasana (tyhjä = DB)" style="flex:1;min-width:150px;padding:0.3rem 0.5rem;font-size:0.85rem;">
|
|
||||||
<button class="btn-secondary" id="btn-test-smtp-override" style="background:#FF9800;color:#fff;border:none;padding:0.3rem 0.7rem;font-size:0.85rem;">Testaa näillä</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<pre id="smtp-test-result" style="display:none;background:#1a1a2e;color:#0f0;padding:0.75rem;border-radius:6px;font-size:0.8rem;max-height:300px;overflow:auto;margin-top:0.5rem;white-space:pre-wrap;"></pre>
|
<pre id="smtp-test-result" style="display:none;background:#1a1a2e;color:#0f0;padding:0.75rem;border-radius:6px;font-size:0.8rem;max-height:300px;overflow:auto;margin-top:0.5rem;white-space:pre-wrap;"></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
32
script.js
32
script.js
@@ -2590,9 +2590,17 @@ document.getElementById('btn-save-mailbox').addEventListener('click', async () =
|
|||||||
aktiivinen: true,
|
aktiivinen: true,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
await apiCall('mailbox_save', 'POST', data);
|
const saved = await apiCall('mailbox_save', 'POST', data);
|
||||||
document.getElementById('mailbox-form-container').style.display = 'none';
|
// Päivitä lomakkeen ID (uusi laatikko saa ID:n backendiltä)
|
||||||
|
if (saved.id) document.getElementById('mailbox-form-id').value = saved.id;
|
||||||
|
// Päivitä lista taustalle mutta pidä lomake auki
|
||||||
loadMailboxes();
|
loadMailboxes();
|
||||||
|
// Näytä lyhyt "Tallennettu" -ilmoitus
|
||||||
|
const btn = document.getElementById('btn-save-mailbox');
|
||||||
|
const orig = btn.textContent;
|
||||||
|
btn.textContent = '✓ Tallennettu';
|
||||||
|
btn.style.background = '#4caf50';
|
||||||
|
setTimeout(() => { btn.textContent = orig; btn.style.background = ''; }, 2000);
|
||||||
} catch (e) { alert(e.message); }
|
} catch (e) { alert(e.message); }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2601,7 +2609,7 @@ document.getElementById('btn-cancel-mailbox').addEventListener('click', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// SMTP-testaus
|
// SMTP-testaus
|
||||||
async function runSmtpTest(overrideUser = '', overridePass = '') {
|
document.getElementById('btn-test-smtp').addEventListener('click', async () => {
|
||||||
const mailboxId = document.getElementById('mailbox-form-id').value;
|
const mailboxId = document.getElementById('mailbox-form-id').value;
|
||||||
const resultEl = document.getElementById('smtp-test-result');
|
const resultEl = document.getElementById('smtp-test-result');
|
||||||
if (!mailboxId) {
|
if (!mailboxId) {
|
||||||
@@ -2611,13 +2619,8 @@ async function runSmtpTest(overrideUser = '', overridePass = '') {
|
|||||||
}
|
}
|
||||||
resultEl.style.display = '';
|
resultEl.style.display = '';
|
||||||
resultEl.textContent = '⏳ Testataan SMTP-yhteyttä...';
|
resultEl.textContent = '⏳ Testataan SMTP-yhteyttä...';
|
||||||
// Näytä override-kentät
|
|
||||||
document.getElementById('smtp-test-override').style.display = '';
|
|
||||||
try {
|
try {
|
||||||
const payload = { mailbox_id: mailboxId };
|
const res = await apiCall('smtp_test', 'POST', { mailbox_id: mailboxId });
|
||||||
if (overrideUser) payload.override_user = overrideUser;
|
|
||||||
if (overridePass) payload.override_pass = overridePass;
|
|
||||||
const res = await apiCall('smtp_test', 'POST', payload);
|
|
||||||
let output = '=== TIETOKANNAN ARVOT ===\n';
|
let output = '=== TIETOKANNAN ARVOT ===\n';
|
||||||
if (res.db_values) {
|
if (res.db_values) {
|
||||||
for (const [k, v] of Object.entries(res.db_values)) {
|
for (const [k, v] of Object.entries(res.db_values)) {
|
||||||
@@ -2625,27 +2628,16 @@ async function runSmtpTest(overrideUser = '', overridePass = '') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
output += `\n=== KÄYTETTÄVÄT ARVOT ===\n`;
|
output += `\n=== KÄYTETTÄVÄT ARVOT ===\n`;
|
||||||
if (res.using_override) output += ` ⚠️ KÄYTETÄÄN OVERRIDE-TUNNUKSIA\n`;
|
|
||||||
output += ` Käyttäjä: ${res.effective_user || '(tyhjä)'}\n`;
|
output += ` Käyttäjä: ${res.effective_user || '(tyhjä)'}\n`;
|
||||||
output += ` Salasana: ${res.effective_pass_hint || '?'} (${res.effective_pass_len} merkkiä)\n\n`;
|
output += ` Salasana: ${res.effective_pass_hint || '?'} (${res.effective_pass_len} merkkiä)\n\n`;
|
||||||
output += `=== TESTIN VAIHEET ===\n`;
|
output += `=== TESTIN VAIHEET ===\n`;
|
||||||
if (res.steps) {
|
if (res.steps) {
|
||||||
res.steps.forEach(s => { output += ` ${s}\n`; });
|
res.steps.forEach(s => { output += ` ${s}\n`; });
|
||||||
}
|
}
|
||||||
if (res.ehlo_capabilities_tls) {
|
|
||||||
output += `\n=== EHLO (TLS jälkeen) ===\n${res.ehlo_capabilities_tls}\n`;
|
|
||||||
}
|
|
||||||
resultEl.textContent = output;
|
resultEl.textContent = output;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resultEl.textContent = '❌ Virhe: ' + e.message;
|
resultEl.textContent = '❌ Virhe: ' + e.message;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('btn-test-smtp').addEventListener('click', () => runSmtpTest());
|
|
||||||
document.getElementById('btn-test-smtp-override').addEventListener('click', () => {
|
|
||||||
const user = document.getElementById('smtp-test-user').value;
|
|
||||||
const pass = document.getElementById('smtp-test-pass').value;
|
|
||||||
runSmtpTest(user, pass);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ==================== YRITYKSEN KÄYTTÄJÄOIKEUDET ====================
|
// ==================== YRITYKSEN KÄYTTÄJÄOIKEUDET ====================
|
||||||
|
|||||||
Reference in New Issue
Block a user