49 lines
No EOL
1.6 KiB
JavaScript
49 lines
No EOL
1.6 KiB
JavaScript
const form = document.getElementById("form");
|
|
form.addEventListener('submit', formHandler);
|
|
|
|
const form_status = document.getElementById("formStatus");
|
|
|
|
const button = document.getElementById("button");
|
|
button.addEventListener('submit', formHandler);
|
|
|
|
async function formHandler(listener) {
|
|
listener.preventDefault();
|
|
const formData = new FormData(form);
|
|
const user = formData.get("user");
|
|
const pass = formData.get("pass");
|
|
const newPW = formData.get("newPW");
|
|
if (newPW !== formData.get("newPWConfirm")) {
|
|
|
|
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: new passwords don't match</span>";
|
|
|
|
return;
|
|
}
|
|
|
|
const body = {auth: {user: user, pass: pass}, field: "userPassword", value: newPW}
|
|
|
|
let url = 'https://api.account.skynet.ie/ldap/update';
|
|
let req;
|
|
|
|
try {
|
|
req = await fetch(url, {
|
|
method: 'POST',
|
|
body: JSON.stringify(body),
|
|
mode: "cors"
|
|
});
|
|
} catch (e) {
|
|
form_status.innerHTML = `<span style='background-color: red; color: white'>${e}</span>`;
|
|
return;
|
|
}
|
|
|
|
if (req.status !== 200) {
|
|
form_status.innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
|
|
return;
|
|
}
|
|
|
|
let temp = await req.json();
|
|
if (temp.result === 'error') {
|
|
form_status.innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
|
|
} else {
|
|
form_status.innerHTML = "<span style='background-color: green; color: white'>Success</span>";
|
|
}
|
|
} |