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>
</head>
<body>
<h1>Password Recovery</h1>
<p>Please reset your password below</p>
<form id="reset">
<label for="pass1">Password</label>
<input type="password" id="pass1" name="password" /> <br />
<label for="pass2">Confirm</label>
<input type="password" id="pass2" name="confirm" /> <br />
<input type="submit" />
</form>
<p id="formStatus"></p>
<footer>
UL Computer Society 2023-<span id="year">2023</span>
</footer>
<script>
document.getElementById('year').textContent = new Date().getFullYear().toString()
</script>
<script>
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
<h1>Password Recovery</h1>
<p>Please reset your password below</p>
<form id="reset">
<label for="pass1">Password</label>
<input type="password" id="pass1" name="password"/> <br/>
<label for="pass2">Confirm</label>
<input type="password" id="pass2" name="confirm"/> <br/>
<input type="submit"/>
</form>
<p id="formStatus"></p>
<footer>
UL Computer Society 2023-<span id="year">2023</span>
</footer>
<script>
document.getElementById('year').textContent = new Date().getFullYear().toString()
</script>
<script>
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener){
listener.preventDefault();
const formData = new FormData(formEl);
const pass = formData.get("password");
if(pass === formData.get("confirm")){
const url = new URL(window.location.href);
const urlParam = new URLSearchParams(url.search);
const auth = urlParam.get("auth");
const object = {auth: auth, pass: pass };
fetch("https://api.account.skynet.ie/ldap/recover/auth", {
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 = "<span style='background-color: red; color: white'>Failure</span>";
function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(formEl);
const pass = formData.get("password");
if (pass === formData.get("confirm")) {
const url = new URL(window.location.href);
const urlParam = new URLSearchParams(url.search);
const auth = urlParam.get("auth");
const object = {auth: auth, pass: pass};
fetch("https://api.account.skynet.ie/ldap/recover/auth", {
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 = "<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 {
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'){
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 {
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: red; color: white'>Failure: Passwords don't match</span>";
}
</script>
}
</script>
</body>
</html>