2023-08-08 17:24:55 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en-ie">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8"/>
|
|
|
|
<title>Account Recovery</title>
|
|
|
|
<link rel="icon" type="image/png" href="images/favicon/favicon-16x16.png"/>
|
|
|
|
</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 18:07:43 +01:00
|
|
|
</select> <br />
|
|
|
|
<label for="value">Value</label>
|
2023-08-08 18:13:11 +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 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));
|
|
|
|
|
|
|
|
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();
|
|
|
|
if(option === ''){
|
|
|
|
alert("Need to implement this");
|
|
|
|
} else {
|
|
|
|
const formData = new FormData(formEl);
|
|
|
|
const value = formData.get('value');
|
|
|
|
let object;
|
|
|
|
if (option === 'email'){
|
|
|
|
object = { email: value };
|
|
|
|
} else {
|
|
|
|
object = { user: value };
|
|
|
|
}
|
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 => {
|
|
|
|
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>";
|
|
|
|
})
|
2023-08-08 18:48:22 +01:00
|
|
|
}
|
2023-08-08 18:13:11 +01:00
|
|
|
}
|
|
|
|
|
2023-08-08 18:22:03 +01:00
|
|
|
function selectField(){
|
|
|
|
const field = document.getElementById('options').value;
|
|
|
|
const inputEl = document.getElementById('value');
|
|
|
|
if(field === "email"){
|
|
|
|
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>
|