From 8d17037c0f61fce3be61df0953f9fef446e43cc0 Mon Sep 17 00:00:00 2001 From: "eoghan.conlon" Date: Sat, 29 Jul 2023 23:38:04 +0100 Subject: [PATCH] [Modify user] Adding field select to form. #1 --- src/modify.html | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) 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"; + } }