implemented:

- altering of mail settings
- sending email

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-08-09 00:27:32 +02:00
parent f3c4c098c0
commit 31afced7f7
10 changed files with 141 additions and 40 deletions

View File

@@ -25,6 +25,10 @@ function hide(id){
get(id).style.display = 'none';
}
function isChecked(id){
return get(id).checked;
}
function login(){
redirect('login.html?return_to='+encodeURIComponent(window.location.href));
}

View File

@@ -28,6 +28,24 @@ async function handlePasswordResponse(response){
},10000);
}
async function handleSmtpResponse(response){
if (response.ok){
hide('wrong_password');
hide('password_mismatch');
setText('smtpBtn', 'saved.');
} else {
setText('smtpBtn', 'Update failed!');
var text = await response.text();
if (text == 'wrong password') show('wrong_password');
if (text == 'password mismatch') show('password_mismatch');
}
setTimeout(function(){
enable('smtpBtn');
setText('smtpBtn','Update');
},10000);
}
function handleResponse(response){
if (response.ok){
hide('update_error')
@@ -36,8 +54,8 @@ function handleResponse(response){
show('update_error');
setText('updateBtn', 'Update failed!');
}
enable('updateBtn');
setTimeout(function(){
enable('updateBtn');
setText('updateBtn','Update');
},10000);
}
@@ -49,6 +67,8 @@ async function handleSettings(response){
for (var key in json){
setValue(key,json[key]);
}
get('start_tls').checked = json.start_tls;
get('smtp_auth').checked = json.smtp_auth;
show('mail_settings');
} else {
hide('mail_settings');
@@ -59,6 +79,25 @@ function passKeyDown(ev){
if (event.keyCode == 13) updatePass();
}
function updateSmtp(){
disable('smtpBtn');
var newData = {
smtp_host : getValue('smtp_host'),
smtp_port : getValue('smtp_port'),
smtp_user : getValue('smtp_user'),
smtp_pass : getValue('smtp_pass'),
smtp_auth : isChecked('smtp_auth'),
start_tls : isChecked('start_tls')
}
fetch("/api/email/settings",{
method : 'POST',
headers : {
'Content-Type': 'application/json'
},
body : JSON.stringify(newData)
}).then(handleSmtpResponse);
setText('smtpBtn','sent…');
}
function updatePass(){

View File

@@ -78,6 +78,7 @@
</tr>
</table>
</fieldset>
<br/>
<fieldset id="mail_settings" style="display: none">
<legend>
Mail settings
@@ -85,20 +86,32 @@
<table>
<tr>
<th>Smtp host</th>
<td><input type="text" id="smtp_host"></td>
<td><input type="text" id="smtp_host" placeholder="smtp host"></td>
</tr>
<tr>
<th>Smtp port</th>
<td><input type="text" id="smtp_port"></td>
<td><input type="number" id="smtp_port"></td>
</tr>
<tr>
<th>Sender email address</th>
<td><input type="text" id="sender_mail"></td>
<th>Smtp user</th>
<td><input type="text" id="smtp_user" placeholder="smtp user"></td>
</tr>
<tr>
<th>Sender password</th>
<td><input type="password" id="sender_password"></td>
<th>Smtp password</th>
<td><input type="password" id="smtp_pass" placeholder="password"></td>
</tr>
<tr>
<th>Security</th>
<td>
<label>
<input type="checkbox" id="smtp_auth"> Auth
</label>
<label>
<input type="checkbox" id="start_tls"> StartTLS
</label>
</td>
</tr>
<tr>
<td></td>
<td><button id="smtpBtn" type="button" onClick="updateSmtp()">Update</button></td>
</tr>