diff --git a/src/modify.html b/src/modify.html index 65c2518..58fff12 100644 --- a/src/modify.html +++ b/src/modify.html @@ -14,7 +14,11 @@
@@ -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 = "Success"; - } else if (res.status === 500){ - document.getElementById('formStatus').innerHTML = "Failure"; - } else { - document.getElementById('formStatus').innerHTML = "Failure: Failed to communicate to server"; - } - }).catch(() => document.getElementById('formStatus').innerHTML = "Please try again"); + 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 = "Success"; + } else if (res.status === 500) { + document.getElementById('formStatus').innerHTML = "Failure"; + } else { + document.getElementById('formStatus').innerHTML = "Failure: Failed to communicate to server"; + } + }).catch(() => document.getElementById('formStatus').innerHTML = "Please try again"); + } else { + document.getElementById('formStatus').innerHTML = "Please select a field to modify"; + } }