Refactored code to standard using IDE

Signed-off-by: Eoghan Conlon <eoghanconlon73@skynet.ie>
This commit is contained in:
eoghanconlon73 2023-08-27 17:08:23 +01:00
parent a6104b0565
commit d19fcb9c10

View file

@ -5,60 +5,60 @@
<title>Password recovery</title> <title>Password recovery</title>
</head> </head>
<body> <body>
<h1>Password Recovery</h1> <h1>Password Recovery</h1>
<p>Please reset your password below</p> <p>Please reset your password below</p>
<form id="reset"> <form id="reset">
<label for="pass1">Password</label> <label for="pass1">Password</label>
<input type="password" id="pass1" name="password" /> <br /> <input type="password" id="pass1" name="password"/> <br/>
<label for="pass2">Confirm</label> <label for="pass2">Confirm</label>
<input type="password" id="pass2" name="confirm" /> <br /> <input type="password" id="pass2" name="confirm"/> <br/>
<input type="submit" /> <input type="submit"/>
</form> </form>
<p id="formStatus"></p> <p id="formStatus"></p>
<footer> <footer>
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>
</footer> </footer>
<script> <script>
document.getElementById('year').textContent = new Date().getFullYear().toString() document.getElementById('year').textContent = new Date().getFullYear().toString()
</script> </script>
<script> <script>
const formEl = document.getElementById("reset"); const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener)); formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener){ function formHandler(listener) {
listener.preventDefault(); listener.preventDefault();
const formData = new FormData(formEl); const formData = new FormData(formEl);
const pass = formData.get("password"); const pass = formData.get("password");
if(pass === formData.get("confirm")){ 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 object = {auth: auth, pass: pass }; const object = {auth: auth, pass: pass};
fetch("https://api.account.skynet.ie/ldap/recover/auth", { fetch("https://api.account.skynet.ie/ldap/recover/auth", {
method: 'POST', method: 'POST',
body: JSON.stringify(object), body: JSON.stringify(object),
mode: "cors" mode: "cors"
}).then(res => { }).then(res => {
if(res.status === 200){ if (res.status === 200) {
return res.json(); return res.json();
} else if (res.status === 500){ } else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>"; 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>";
}
}).then(temp => {
if (temp) {
if (temp.result === 'error') {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
} else { } else {
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: green; color: white'>Success</span>";
} }
}).then(temp => { }
if(temp){ })
if(temp.result === 'error'){ } else {
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'>Failure: Passwords don't match</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
}
}
})
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Passwords don't match</span>";
}
} }
</script> }
</script>
</body> </body>
</html> </html>