2023-08-08 17:24:55 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en-ie">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8"/>
|
|
|
|
<title>Account Recovery</title>
|
2023-08-08 19:15:51 +01:00
|
|
|
<link rel="icon" type="image/png" href="../images/favicon/favicon-16x16.png"/>
|
2023-08-08 17:24:55 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
2023-08-08 18:07:43 +01:00
|
|
|
<form id="recovery">
|
|
|
|
<label for="options">Options</label>
|
2023-08-08 18:22:03 +01:00
|
|
|
<select onChange="selectField()" id="options">
|
2023-08-08 18:07:43 +01:00
|
|
|
<option value="" selected="selected">Please select an option</option>
|
|
|
|
<option value="user">Username</option>
|
2023-08-08 18:22:53 +01:00
|
|
|
<option value="email">Email</option>
|
2023-08-08 19:18:58 +01:00
|
|
|
</select> <br/>
|
2023-08-08 18:07:43 +01:00
|
|
|
<label for="value">Value</label>
|
2023-08-08 19:18:58 +01:00
|
|
|
<input type="text" id="value" name="value"/> <br/>
|
|
|
|
<input type="submit" value="submit"/>
|
2023-08-08 18:07:43 +01:00
|
|
|
</form>
|
2023-08-08 18:58:31 +01:00
|
|
|
<p id="formStatus"></p>
|
2023-08-08 17:24:55 +01:00
|
|
|
<footer>
|
|
|
|
UL Computer Society 2023-<span id="year">2023</span>
|
|
|
|
</footer>
|
2023-08-08 18:13:11 +01:00
|
|
|
<script>
|
|
|
|
const formEl = document.getElementById('recovery');
|
|
|
|
formEl.addEventListener('submit', (listener) => formHandler(listener));
|
|
|
|
|
2023-08-08 19:18:58 +01:00
|
|
|
function formHandler(listener) {
|
2023-08-08 18:38:13 +01:00
|
|
|
listener.preventDefault();
|
2023-08-08 18:48:22 +01:00
|
|
|
const option = document.getElementById('options').value.toString();
|
2023-08-08 19:18:58 +01:00
|
|
|
if (option === '') {
|
2023-08-27 17:12:19 +01:00
|
|
|
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Please select an option, then try again</span>";
|
2023-08-08 18:48:22 +01:00
|
|
|
} else {
|
|
|
|
const formData = new FormData(formEl);
|
|
|
|
const value = formData.get('value');
|
|
|
|
let object;
|
2023-08-08 19:18:58 +01:00
|
|
|
if (option === 'email') {
|
|
|
|
object = {email: value};
|
2023-08-08 18:48:22 +01:00
|
|
|
} else {
|
2023-08-08 19:18:58 +01:00
|
|
|
object = {user: value};
|
2023-08-08 18:48:22 +01:00
|
|
|
}
|
2023-08-08 18:58:05 +01:00
|
|
|
fetch('https://api.account.skynet.ie/ldap/recover/password', {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify(object),
|
|
|
|
mode: "cors"
|
|
|
|
}).then(res => {
|
2023-08-08 19:18:58 +01:00
|
|
|
if (res.status === 200) {
|
2023-08-08 18:58:05 +01:00
|
|
|
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
|
2023-08-08 19:18:58 +01:00
|
|
|
} else if (res.status === 500) {
|
2023-08-08 18:58:05 +01:00
|
|
|
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>";
|
2023-08-08 19:18:58 +01:00
|
|
|
});
|
2023-08-08 18:48:22 +01:00
|
|
|
}
|
2023-08-08 18:13:11 +01:00
|
|
|
}
|
|
|
|
|
2023-08-08 19:18:58 +01:00
|
|
|
function selectField() {
|
2023-08-08 18:22:03 +01:00
|
|
|
const field = document.getElementById('options').value;
|
|
|
|
const inputEl = document.getElementById('value');
|
2023-08-08 19:18:58 +01:00
|
|
|
if (field === "email") {
|
2023-08-08 18:22:03 +01:00
|
|
|
inputEl.type = 'email';
|
|
|
|
} else {
|
|
|
|
inputEl.type = 'text';
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 18:13:11 +01:00
|
|
|
</script>
|
2023-08-08 17:24:55 +01:00
|
|
|
</body>
|
|
|
|
<script>
|
|
|
|
document.getElementById('year').textContent = new Date().getFullYear().toString()
|
|
|
|
</script>
|
|
|
|
</html>
|