feat: Moved the JS out of the ssh recovery page into its own file
Related to #9
This commit is contained in:
parent
ae433303b8
commit
741bb8c7ca
2 changed files with 45 additions and 42 deletions
|
@ -15,7 +15,9 @@
|
|||
<main class="page-body">
|
||||
<h1>SSH key recovery</h1>
|
||||
<p>
|
||||
Recover a legacy skynet account using your username and set a new email address to link to the account. Use this only if you do not remember the account password and the linked account email is lost or incorrect.<br> Enter skynet username & email you have used with UL Wolves. </br>
|
||||
Recover a legacy skynet account using your username and set a new email address to link to the account. Use this only if you do not remember the account password and the linked account email is lost or incorrect.
|
||||
<br>
|
||||
Enter skynet username & email you have used with UL Wolves.
|
||||
</p>
|
||||
|
||||
<form id="form">
|
||||
|
@ -29,51 +31,12 @@
|
|||
<td><input id="mail" name="mail" type="email"/> <br/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><input type="submit" value="submit"/></td>
|
||||
<td colspan="2"><input id="button" type="submit" value="submit"/></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<p id="formStatus"></p>
|
||||
<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 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 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 src="ssh-request.js"></script>
|
||||
</main>
|
||||
<footer class="page-footer">
|
||||
UL Computer Society 2023-<span id="year">2023</span>
|
||||
|
|
40
src/recovery/ssh-request.js
Normal file
40
src/recovery/ssh-request.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const form = document.getElementById("form");
|
||||
form.addEventListener('submit', formHandler);
|
||||
|
||||
const form_status = document.getElementById("formStatus");
|
||||
|
||||
const button = document.getElementById("button");
|
||||
button.addEventListener('submit', formHandler);
|
||||
|
||||
|
||||
async function formHandler(listener) {
|
||||
listener.preventDefault();
|
||||
const formData = new FormData(form);
|
||||
const body = {user: formData.get('user'), email: formData.get('mail')};
|
||||
|
||||
let url = 'https://api.account.skynet.ie/ldap/recover/ssh/request';
|
||||
let req;
|
||||
|
||||
try {
|
||||
req = await fetch(url, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
mode: "cors"
|
||||
});
|
||||
} catch (e) {
|
||||
form_status.innerHTML = `<span style='background-color: red; color: white'>${e}</span>`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.status !== 200) {
|
||||
form_status.innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
|
||||
return;
|
||||
}
|
||||
|
||||
let temp = await req.json();
|
||||
if (temp.result === 'error') {
|
||||
form_status.innerHTML = `<span style='background-color: red; color: white'>${temp.error}</span>`;
|
||||
} else {
|
||||
form_status.innerHTML = "<span style='background-color: green; color: white'>Success</span>";
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue