[Modify user] Adding field select to form.

#1
This commit is contained in:
eoghan.conlon 2023-07-29 23:38:04 +01:00
parent e689c05fca
commit 8d17037c0f

View file

@ -14,7 +14,11 @@
<label for="field">Field</label>
<select id="field">
<option value="" selected="selected">Please select an option</option>
<option value="email">Email</option>
<option value="mail">Email</option>
<option value="sshPublicKey">SSH key</option>
<option value="cn">First name & Surname</option>
<option value="sn">Surname</option>
<option value="skDiscord">Discord username</option>
</select>
<br />
<label for="value">Value</label>
@ -29,25 +33,30 @@
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener){
function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(formEl);
const user = formData.get("user");
const pass = formData.get("pass");
const newEmail = formData.get("value");
const object = {user: user, pass: pass, field: "mail", value: newEmail}
fetch('https://api.sso.skynet.ie/ldap/update', {
method: 'POST',
body: JSON.stringify(object)
}).then(res => {
if(res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} else if (res.status === 500){
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
const field = formData.get("field");
if (field !== "") {
const user = formData.get("user");
const pass = formData.get("pass");
const value = formData.get("value");
const object = {user: user, pass: pass, field: field, value: value}
fetch('https://api.sso.skynet.ie/ldap/update', {
method: 'POST',
body: JSON.stringify(object)
}).then(res => {
if (res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Please select a field to modify</span>";
}
}
</script>
</body>