[Modify user] Refactored existing form handling code for what this form will be used for

#1
This commit is contained in:
eoghan.conlon 2023-07-29 23:07:15 +01:00
parent 5235c785b0
commit 13270f2f4e

View file

@ -13,8 +13,6 @@
<input type="password" id="pass" name="pass" /> <br />
<label for="newEmail">New email</label>
<input type="email" id="newEmail" name="newPW" /> <br />
<label for="newEmail2">Confirm</label>
<input type="email" id="newEmail2" name="newPWConfirm" /> <br />
<input type="Submit" value="Submit" />
</form>
<p id="formStatus"></p>
@ -31,23 +29,19 @@
const user = formData.get("user");
const pass = formData.get("pass");
const newEmail = formData.get("newEmail");
if(newEmail === formData.get("newEmail2")){
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>");
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: new passwords don't match</span>";
}
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>");
}
</script>
</body>