From f105b8dcc09b0e053cc988b3ec6b094dbcf3ad7f Mon Sep 17 00:00:00 2001 From: "eoghan.conlon" Date: Sat, 5 Aug 2023 16:42:52 +0100 Subject: [PATCH] Feat. Password confrim box added and related logic implemented #3 --- src/register.html | 60 ++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/src/register.html b/src/register.html index ff25e61..cfd3079 100644 --- a/src/register.html +++ b/src/register.html @@ -11,7 +11,9 @@
- +
+ +

@@ -25,35 +27,39 @@ function formHandler(listener){ listener.preventDefault(); 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 object = { auth: auth, user: user, pass: pass }; - fetch('https://api.sso.skynet.ie/ldap/new', { - method: 'POST', - body: JSON.stringify(object), - mode: "cors" - }).then(res => { - if (res.status === 200) { - return res.json(); - } else if (res.status === 500) { - document.getElementById('formStatus').innerHTML = "Failure"; - } else { - document.getElementById('formStatus').innerHTML = "Failure: Failed to communicate to server"; - } - }) - .then((temp) => { - if(temp){ - if(temp.result === 'error'){ - document.getElementById('formStatus').innerHTML = `${temp.error}`; - } else { - document.getElementById('formStatus').innerHTML = "Success"; - } + if(pass === formData.get("confirm")) { + const url = new URL(window.location.href); + const urlParam = new URLSearchParams(url.search); + const auth = urlParam.get("auth"); + const user = formData.get("user"); + const object = {auth: auth, user: user, pass: pass}; + fetch('https://api.sso.skynet.ie/ldap/new', { + method: 'POST', + body: JSON.stringify(object), + mode: "cors" + }).then(res => { + if (res.status === 200) { + return res.json(); + } 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"); + .then((temp) => { + if (temp) { + if (temp.result === 'error') { + document.getElementById('formStatus').innerHTML = `${temp.error}`; + } else { + document.getElementById('formStatus').innerHTML = "Success"; + } + } + }) + .catch(() => document.getElementById('formStatus').innerHTML = "Please try again"); + } else { + document.getElementById('formStatus').innerHTML = `Passwords don't match`; + } }