Code clean-up
Signed-off-by: Eoghan Conlon <eoghanconlon73@skynet.ie>
This commit is contained in:
parent
de2dc0b459
commit
16e6ce9a98
1 changed files with 49 additions and 49 deletions
|
@ -5,60 +5,60 @@
|
|||
<title>SSH key recovery</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>SSH key recovery</h1>
|
||||
<form id="form">
|
||||
<label for="user">Username</label>
|
||||
<input type="text" id="user" name="user" /> <br />
|
||||
<label for="mail">Email</label>
|
||||
<input type="email" id="mail" name="mail" /> <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("form");
|
||||
formEl.addEventListener('submit', formHandler);
|
||||
<h1>SSH key recovery</h1>
|
||||
<form id="form">
|
||||
<label for="user">Username</label>
|
||||
<input type="text" id="user" name="user"/> <br/>
|
||||
<label for="mail">Email</label>
|
||||
<input type="email" id="mail" name="mail"/> <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("form");
|
||||
formEl.addEventListener('submit', formHandler);
|
||||
|
||||
function formHandler(listener){
|
||||
listener.preventDefault();
|
||||
const formData = new FormData(formEl);
|
||||
const object = { user: formData.get('user'), email: formData.get('mail')};
|
||||
fetch('https://api.account.skynet.ie/ldap/recover/ssh/request', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(object),
|
||||
mode: "cors"
|
||||
})
|
||||
.then(status)
|
||||
.then(json)
|
||||
.catch(() => {
|
||||
document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>";
|
||||
});
|
||||
function formHandler(listener) {
|
||||
listener.preventDefault();
|
||||
const formData = new FormData(formEl);
|
||||
const object = {user: formData.get('user'), email: formData.get('mail')};
|
||||
fetch('https://api.account.skynet.ie/ldap/recover/ssh/request', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(object),
|
||||
mode: "cors"
|
||||
})
|
||||
.then(status)
|
||||
.then(json)
|
||||
.catch(() => {
|
||||
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){
|
||||
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 json(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>";
|
||||
}
|
||||
}
|
||||
|
||||
function json(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>";
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue