[Sign-up] Fetch implemented

#3
This commit is contained in:
eoghan.conlon 2023-08-01 13:51:02 +01:00
parent f1e819bab9
commit a8de7c72e1

View file

@ -16,6 +16,7 @@
<input type="password" id="pass" name="pass" />
<input type="Submit" value="Submit"/>
</form>
<p id="formStatus"></p>
<footer>
UL Computer Society 2023-<span id="year">2023</span>
</footer>
@ -31,6 +32,24 @@
const pass = formData.get("pass");
const object = { auth: auth, user: user, pass: pass }
alert(JSON.stringify(object));
fetch('https://api.sso.skynet.ie/ldap/new', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if (res.status === 200) {
let temp = res.json();
if(temp.result === 'error'){
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
} else {
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>