Feat. Password confrim box added and related logic implemented

#3
This commit is contained in:
eoghan.conlon 2023-08-05 16:42:52 +01:00
parent 20e284fb13
commit f105b8dcc0

View file

@ -11,7 +11,9 @@
<label for="user">Username</label> <label for="user">Username</label>
<input type="text" id="user" name="user" /> <br /> <input type="text" id="user" name="user" /> <br />
<label for="pass">Password</label> <label for="pass">Password</label>
<input type="password" id="pass" name="pass" /> <input type="password" id="pass" name="pass" /> <br />
<label for="confirm">Confirm</label>
<input type="password" id="confirm" name="confirm" />
<input type="Submit" value="Submit"/> <input type="Submit" value="Submit"/>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
@ -25,35 +27,39 @@
function formHandler(listener){ function formHandler(listener){
listener.preventDefault(); listener.preventDefault();
const formData = new FormData(formEl); const formData = new FormData(formEl);
const url = new URL(window.location.href);
const urlParam = new URLSearchParams(url.search);
const auth = urlParam.get("auth");
const user = formData.get("user");
const pass = formData.get("pass"); const pass = formData.get("pass");
const object = { auth: auth, user: user, pass: pass }; if(pass === formData.get("confirm")) {
fetch('https://api.sso.skynet.ie/ldap/new', { const url = new URL(window.location.href);
method: 'POST', const urlParam = new URLSearchParams(url.search);
body: JSON.stringify(object), const auth = urlParam.get("auth");
mode: "cors" const user = formData.get("user");
}).then(res => { const object = {auth: auth, user: user, pass: pass};
if (res.status === 200) { fetch('https://api.sso.skynet.ie/ldap/new', {
return res.json(); method: 'POST',
} else if (res.status === 500) { body: JSON.stringify(object),
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>"; mode: "cors"
} else { }).then(res => {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>"; if (res.status === 200) {
} return res.json();
}) } else if (res.status === 500) {
.then((temp) => { document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
if(temp){ } else {
if(temp.result === 'error'){ document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
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>";
}
} }
}) })
.catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>"); .then((temp) => {
if (temp) {
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>";
}
}
})
.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'>Passwords don't match</span>`;
}
} }
</script> </script>
</body> </body>