Merge branch 'UsernameRecovery' into 'main'

Add username recovery

See merge request compsoc1/skynet/ldap/frontend!9
This commit is contained in:
evanc 2023-09-18 14:07:24 +00:00
commit 2e7b8240ee
2 changed files with 64 additions and 0 deletions

View file

@ -21,6 +21,10 @@
<p>
Please use this service to modify your user data (email, login ssh key, etc.)
</p>
<h2><a href="username.html">Forgot your username?</a></h2>
<p>
Please use this service to get a reminder email with your skynet username
</p>
</div>
<!--testing2-->

60
src/username.html Normal file
View file

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en-ie">
<head>
<meta charset="UTF-8"/>
<title>Forgot Username</title>
<link rel="icon" type="image/png" href="images/favicon/favicon-16x16.png"/>
<link rel="stylesheet" type="text/css" href="stylesheets/index.css"/>
</head>
<body>
<div id="title">
<a href="./"><img src="images/sharky_vector_svg.svg" alt="Picture of Sharky, the mascot of skynet" width="145"
height="81.56"/> </a>
<h1>Skynet Password Reset & Sign-up service</h1>
</div>
<div class="boxes">
<h2>Forgot Username</h2>
<p>Please use this page to get a reminder email with your skynet username in it.</p>
<form id="reset">
<table id="table">
<tr>
<td><label for="email">Email Address</label></td>
<td><input type="text" id="email" name="email"/> <br/></td>
</tr>
<tr>
<td colspan="2"><input type="Submit" value="Submit"/></td>
</tr>
</table>
</form>
<p id="formStatus"></p>
</div>
<footer>
UL Computer Society 2023-<span id="year">2023</span>
</footer>
<script>
const formEl = document.getElementById("reset");
formEl.addEventListener('submit', (listener) => formHandler(listener));
function formHandler(listener) {
listener.preventDefault();
const formData = new FormData(formEl);
const email = formData.get("email");
const object = {email: email};
fetch('https://api.account.skynet.ie/ldap/recover/username', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if (res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} 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>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
}
</script>
</body>
<script></script>
</html>