Merge pull request #892 from BlackDex/smtp-test-button

Relocated SMTP test input+button.
This commit is contained in:
Daniel García 2020-03-05 00:05:52 +01:00 committed by GitHub
commit 161cccca30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,16 +72,6 @@
environment. environment.
</div> </div>
<div id="smtp-test-form-block" class="align-items-center mb-3 text-white-50 bg-secondary">
<h6 class="mb-0 text-white">SMTP Test</h6>
<small>Email:</small>
<form class="form-inline" id="smtp-test-form" onsubmit="smtpTest(); return false;">
<input type="email" class="form-control w-50 mr-2" id="smtp-test-email" placeholder="Enter email">
<button type="submit" class="btn btn-primary">Send test email</button>
</form>
</div>
<form class="form accordion" id="config-form" onsubmit="saveConfig(); return false;"> <form class="form accordion" id="config-form" onsubmit="saveConfig(); return false;">
{{#each config}} {{#each config}}
{{#if groupdoc}} {{#if groupdoc}}
@ -121,6 +111,17 @@
</div> </div>
{{/if}} {{/if}}
{{/each}} {{/each}}
{{#case group "smtp"}}
<div class="form-group row pt-3 border-top" title="Send a test email to given email address">
<label for="smtp-test-email" class="col-sm-3 col-form-label">Test SMTP</label>
<div class="col-sm-8 input-group">
<input class="form-control" id="smtp-test-email" type="email" placeholder="Enter test email">
<div class="input-group-append">
<button type="button" class="btn btn-outline-primary" onclick="smtpTest(); return false;">Send test email</button>
</div>
</div>
</div>
{{/case}}
</div> </div>
</div> </div>
{{/if}} {{/if}}
@ -202,7 +203,10 @@
<script> <script>
function reload() { window.location.reload(); } function reload() { window.location.reload(); }
function msg(text) { text && alert(text); reload(); } function msg(text, reload_page = true) {
text && alert(text);
reload_page && reload();
}
function identicon(email) { function identicon(email) {
const data = new Identicon(md5(email), { size: 48, format: 'svg' }); const data = new Identicon(md5(email), { size: 48, format: 'svg' });
return "data:image/svg+xml;base64," + data.toString(); return "data:image/svg+xml;base64," + data.toString();
@ -217,7 +221,7 @@
} }
return false; return false;
} }
function _post(url, successMsg, errMsg, body) { function _post(url, successMsg, errMsg, body, reload_page = true) {
fetch(url, { fetch(url, {
method: 'POST', method: 'POST',
body: body, body: body,
@ -225,7 +229,7 @@
credentials: "same-origin", credentials: "same-origin",
headers: { "Content-Type": "application/json" } headers: { "Content-Type": "application/json" }
}).then( resp => { }).then( resp => {
if (resp.ok) { msg(successMsg); return Promise.reject({error: false}); } if (resp.ok) { msg(successMsg, reload_page); return Promise.reject({error: false}); }
respStatus = resp.status; respStatus = resp.status;
respStatusText = resp.statusText; respStatusText = resp.statusText;
return resp.text(); return resp.text();
@ -237,10 +241,10 @@
return Promise.reject({body:respStatus + ' - ' + respStatusText, error: true}); return Promise.reject({body:respStatus + ' - ' + respStatusText, error: true});
} }
}).then( apiMsg => { }).then( apiMsg => {
msg(errMsg + "\n" + apiMsg); msg(errMsg + "\n" + apiMsg, reload_page);
}).catch( e => { }).catch( e => {
if (e.error === false) { return true; } if (e.error === false) { return true; }
else { msg(errMsg + "\n" + e.body); } else { msg(errMsg + "\n" + e.body, reload_page); }
}); });
} }
function deleteUser(id, mail) { function deleteUser(id, mail) {
@ -283,12 +287,11 @@
return false; return false;
} }
function smtpTest() { function smtpTest() {
inv = document.getElementById("smtp-test-email"); test_email = document.getElementById("smtp-test-email");
data = JSON.stringify({ "email": inv.value }); data = JSON.stringify({ "email": test_email.value });
inv.value = "";
_post("{{urlpath}}/admin/test/smtp/", _post("{{urlpath}}/admin/test/smtp/",
"SMTP Test email sent correctly", "SMTP Test email sent correctly",
"Error sending SMTP test email", data); "Error sending SMTP test email", data, false);
return false; return false;
} }
function getFormData() { function getFormData() {
@ -329,7 +332,7 @@
function backupDatabase() { function backupDatabase() {
_post("{{urlpath}}/admin/config/backup_db", _post("{{urlpath}}/admin/config/backup_db",
"Backup created successfully", "Backup created successfully",
"Error creating backup"); "Error creating backup", null, false);
return false; return false;
} }
function masterCheck(check_id, inputs_query) { function masterCheck(check_id, inputs_query) {