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,12 +27,13 @@
function formHandler(listener){ function formHandler(listener){
listener.preventDefault(); listener.preventDefault();
const formData = new FormData(formEl); const formData = new FormData(formEl);
const pass = formData.get("pass");
if(pass === formData.get("confirm")) {
const url = new URL(window.location.href); const url = new URL(window.location.href);
const urlParam = new URLSearchParams(url.search); const urlParam = new URLSearchParams(url.search);
const auth = urlParam.get("auth"); const auth = urlParam.get("auth");
const user = formData.get("user"); const user = formData.get("user");
const pass = formData.get("pass"); const object = {auth: auth, user: user, pass: pass};
const object = { auth: auth, user: user, pass: pass };
fetch('https://api.sso.skynet.ie/ldap/new', { fetch('https://api.sso.skynet.ie/ldap/new', {
method: 'POST', method: 'POST',
body: JSON.stringify(object), body: JSON.stringify(object),
@ -45,8 +48,8 @@
} }
}) })
.then((temp) => { .then((temp) => {
if(temp){ if (temp) {
if(temp.result === 'error'){ if (temp.result === 'error') {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`; document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
} else { } else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>"; document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
@ -54,6 +57,9 @@
} }
}) })
.catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</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>