Code clean-up

Signed-off-by: Eoghan Conlon <eoghanconlon73@skynet.ie>
This commit is contained in:
eoghanconlon73 2023-08-27 21:37:26 +01:00
parent de2dc0b459
commit 16e6ce9a98

View file

@ -5,60 +5,60 @@
<title>SSH key recovery</title> <title>SSH key recovery</title>
</head> </head>
<body> <body>
<h1>SSH key recovery</h1> <h1>SSH key recovery</h1>
<form id="form"> <form id="form">
<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="mail">Email</label> <label for="mail">Email</label>
<input type="email" id="mail" name="mail" /> <br /> <input type="email" id="mail" name="mail"/> <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("form"); const formEl = document.getElementById("form");
formEl.addEventListener('submit', formHandler); formEl.addEventListener('submit', formHandler);
function formHandler(listener){ function formHandler(listener) {
listener.preventDefault(); listener.preventDefault();
const formData = new FormData(formEl); const formData = new FormData(formEl);
const object = { user: formData.get('user'), email: formData.get('mail')}; const object = {user: formData.get('user'), email: formData.get('mail')};
fetch('https://api.account.skynet.ie/ldap/recover/ssh/request', { fetch('https://api.account.skynet.ie/ldap/recover/ssh/request', {
method: 'POST', method: 'POST',
body: JSON.stringify(object), body: JSON.stringify(object),
mode: "cors" mode: "cors"
}) })
.then(status) .then(status)
.then(json) .then(json)
.catch(() => { .catch(() => {
document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>"; document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>";
}); });
}
function status(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>";
} }
}
function status(res){ function json(temp) {
if(res.status === 200){ if (temp) {
return res.json(); if (temp.result === 'error') {
} else if (res.status === 500){ 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</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>";
} }
} }
}
function json(temp){ </script>
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>";
}
}
}
</script>
</body> </body>
</html> </html>