Browse Source

working on javascript compatibility for old browsers

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
sqlite
Stephan Richter 11 months ago
parent
commit
522ee26e88
  1. 2
      de.srsoftware.oidc.web/src/main/resources/en/scripts/clients.js
  2. 17
      de.srsoftware.oidc.web/src/main/resources/en/scripts/reset.js
  3. 53
      de.srsoftware.oidc.web/src/main/resources/en/scripts/settings.js

2
de.srsoftware.oidc.web/src/main/resources/en/scripts/clients.js

@ -31,7 +31,7 @@ function handleRemove(response){
function remove(clientId){ function remove(clientId){
var message = document.getElementById('message').innerHTML; var message = document.getElementById('message').innerHTML;
if (confirm(message.replace("{}",clientId))) { if (confirm(message.replace("{}",clientId))) {
fetch(client_controller+"/delete",{ fetch(client_controller,{
method: 'DELETE', method: 'DELETE',
body : JSON.stringify({ client_id : clientId }), body : JSON.stringify({ client_id : clientId }),
credentials:'include' credentials:'include'

17
de.srsoftware.oidc.web/src/main/resources/en/scripts/reset.js

@ -1,20 +1,20 @@
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token'); const token = urlParams.get('token');
async function handlePasswordResponse(response){ function handlePasswordResponse(response){
if (response.ok){ if (response.ok){
console.log(response);
setText('passBtn', 'saved.'); setText('passBtn', 'saved.');
if (response.redirected){ if (response.redirected){
redirect(response.url); redirect(response.url);
} }
} else { } else {
setText('passBtn', 'Update failed!'); setText('passBtn', 'Update failed!');
var text = await response.text(); response.text().then(text => {
if (text == 'invalid token') show('invalid_token'); if (text == 'invalid token') show('invalid_token');
if (text == 'token missing') show('missing_token'); if (text == 'token missing') show('missing_token');
if (text == 'password mismatch') show('password_mismatch'); if (text == 'password mismatch') show('password_mismatch');
if (text == 'weak password') show('weak_password'); if (text == 'weak password') show('weak_password');
});
} }
enable('passBtn'); enable('passBtn');
setTimeout(function(){ setTimeout(function(){
@ -41,7 +41,8 @@ function updatePass(){
headers : { headers : {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body : JSON.stringify(newData) body : JSON.stringify(newData),
credentials:'include'
}).then(handlePasswordResponse); }).then(handlePasswordResponse);
setText('passBtn','sent…'); setText('passBtn','sent…');
} }

53
de.srsoftware.oidc.web/src/main/resources/en/scripts/settings.js

@ -14,18 +14,17 @@ function fillForm(){
} }
} }
function handlePasswordResponse(response){
async function handlePasswordResponse(response){
if (response.ok){ if (response.ok){
hide('wrong_password'); hide('wrong_password');
hide('password_mismatch'); hide('password_mismatch');
setText('passBtn', 'saved.'); setText('passBtn', 'saved.');
} else { } else {
setText('passBtn', 'Update failed!'); setText('passBtn', 'Update failed!');
var text = await response.text(); response.text().then(text => {
if (text == 'wrong password') show('wrong_password'); if (text == 'wrong password') show('wrong_password');
if (text == 'password mismatch') show('password_mismatch'); if (text == 'password mismatch') show('password_mismatch');
});
} }
enable('passBtn'); enable('passBtn');
setTimeout(function(){ setTimeout(function(){
@ -33,16 +32,17 @@ async function handlePasswordResponse(response){
},10000); },10000);
} }
async function handleSmtpResponse(response){ function handleSmtpResponse(response){
if (response.ok){ if (response.ok){
hide('wrong_password'); hide('wrong_password');
hide('password_mismatch'); hide('password_mismatch');
setText('smtpBtn', 'saved.'); setText('smtpBtn', 'saved.');
} else { } else {
setText('smtpBtn', 'Update failed!'); setText('smtpBtn', 'Update failed!');
var text = await response.text(); response.text().then(text => {
if (text == 'wrong password') show('wrong_password'); if (text == 'wrong password') show('wrong_password');
if (text == 'password mismatch') show('password_mismatch'); if (text == 'password mismatch') show('password_mismatch');
});
} }
setTimeout(function(){ setTimeout(function(){
@ -65,17 +65,15 @@ function handleResponse(response){
},10000); },10000);
} }
async function handleSettings(response){ function handleSettings(response){
console.log('handleSettings(…)',response); console.log('handleSettings(…)',response);
if (response.ok){ if (response.ok){
var json = await response.json(); response.json().then(json => {
console.log("json: ",json); for (var key in json) setValue(key,json[key]);
for (var key in json){ get('start_tls').checked = json.start_tls;
setValue(key,json[key]); get('smtp_auth').checked = json.smtp_auth;
} show('mail_settings');
get('start_tls').checked = json.start_tls; });
get('smtp_auth').checked = json.smtp_auth;
show('mail_settings');
} else { } else {
hide('mail_settings'); hide('mail_settings');
} }
@ -100,7 +98,8 @@ function updateSmtp(){
headers : { headers : {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body : JSON.stringify(newData) body : JSON.stringify(newData),
credentials:'include'
}).then(handleSmtpResponse); }).then(handleSmtpResponse);
setText('smtpBtn','sent…'); setText('smtpBtn','sent…');
} }
@ -118,7 +117,8 @@ function updatePass(){
headers : { headers : {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body : JSON.stringify(newData) body : JSON.stringify(newData),
credentials:'include'
}).then(handlePasswordResponse); }).then(handlePasswordResponse);
setText('passBtn','sent…'); setText('passBtn','sent…');
} }
@ -139,7 +139,8 @@ function update(){
headers : { headers : {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body : JSON.stringify(newData) body : JSON.stringify(newData),
credentials:'include'
}).then(handleResponse) }).then(handleResponse)
setText('updateBtn','sent…'); setText('updateBtn','sent…');
} }
@ -176,5 +177,9 @@ function durationUpdate(){
displayDuration(); displayDuration();
} }
setTimeout(fillForm,100);
fetch("/api/email/settings").then(handleSettings); document.addEventListener("DOMContentLoaded", function(event) { // wait until page loaded
alert('loaded settings.js');
fillForm();
fetch("/api/email/settings",{credentials:'include'}).then(handleSettings);
});
Loading…
Cancel
Save