Fix errors not being propogated to teh end user. #23

Merged
silver merged 10 commits from #9-not-correctly-showing-errors into main 2024-01-01 10:11:02 +00:00
16 changed files with 64 additions and 176 deletions
Showing only changes of commit 9042ce0df9 - Show all commits

28
src/js/lib.js Normal file
View file

@ -0,0 +1,28 @@
export async function post_request(url, body, form_status){
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>";
}
}

View file

@ -49,7 +49,7 @@
</table>
</form>
<p id="formStatus"></p>
<script src="modify.js"></script>
<script type="module" src="modify.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -1,6 +1,10 @@
import {post_request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
const form_status = document.getElementById("formStatus");
const button = document.getElementById("button");
button.addEventListener('submit', formHandler);
@ -13,7 +17,7 @@ async function formHandler(listener) {
const dropdown_value = dropdown.value;
if (dropdown_value === "") {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Please select a field to modify</span>";
form_status.innerHTML = "<span style='background-color: red; color: white'>Please select a field to modify</span>";
return;
}
@ -23,30 +27,7 @@ async function formHandler(listener) {
const body = {auth: {user: user, pass: pass}, field: dropdown_value, value: value};
let url = 'https://api.account.skynet.ie/ldap/update';
let req;
try {
req = await fetch(url, {
method: 'POST',
body: JSON.stringify(body),
mode: "cors"
});
} catch (e) {
document.getElementById('formStatus').innerHTML = `<span style='background-color: red; color: white'>${e}</span>`;
return;
}
if (req.status !== 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
return;
}
let temp = await req.json();
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>";
}
await post_request(url, body, form_status);
}
function selectField() {

View file

@ -41,7 +41,7 @@
</table>
</form>
<p id="formStatus"></p>
<script src="password.js"></script>
<script type="module" src="password.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -1,3 +1,5 @@
import {post_request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
@ -22,28 +24,5 @@ async function formHandler(listener) {
const body = {auth: {user: user, pass: pass}, field: "userPassword", value: newPW}
let url = 'https://api.account.skynet.ie/ldap/update';
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>";
}
await post_request(url, body, form_status);
}

View file

@ -15,7 +15,9 @@
<main class="page-body">
<h2>Forgot Password</h2>
<p>
Request a password reset sent to your linked email. <br> Enter either email address or skynet username. </br>
Request a password reset sent to your linked email.
<br>
Enter either email address or skynet username.
</p>
<form id="form">
<table id="table">
@ -36,7 +38,7 @@
</table>
</form>
<p id="formStatus"></p>
<script src="password.js"></script>
<script type="module" src="password.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -33,7 +33,7 @@
</table>
</form>
<p id="formStatus"></p>
<script src="password_reset.js"></script>
<script type="module" src="password_reset.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -1,3 +1,5 @@
import {post_request} from "../js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
@ -29,27 +31,7 @@ async function formHandler(listener) {
}
let url = "https://api.account.skynet.ie/ldap/recover/password/auth";
let req;
try {
req = await fetch(url, {
method: 'POST',
body: JSON.stringify({auth: auth, pass: pass}),
mode: "cors"
});
} catch (e) {
form_status.innerHTML = `<span style='background-color: red; color: white'>${e}</span>`;
return;
}
let body = {auth: auth, pass: pass};
if (req.status !== 200) {
form_status.innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
return;
}
let data = await req.json();
if (data.result === 'error') {
form_status.innerHTML = `<span style='background-color: red; color: white'>${data.error}</span>`;
} else {
form_status.innerHTML = "<span style='background-color: green; color: white'>Success</span>";
}
await post_request(url, body, form_status);
}

View file

@ -36,7 +36,7 @@
</table>
</form>
<p id="formStatus"></p>
<script src="ssh-request.js"></script>
<script type="module" src="ssh-request.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -1,3 +1,5 @@
import {post_request} from "../js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
@ -13,28 +15,5 @@ async function formHandler(listener) {
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>";
}
await post_request(url, body, form_status);
}

View file

@ -31,7 +31,7 @@
</form>
<p id="formStatus"></p>
</div>
<script src="username.js"></script>
<script type="module" src="username.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -1,3 +1,5 @@
import {post_request} from "../js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
@ -19,28 +21,5 @@ async function formHandler(listener) {
let url = 'https://api.account.skynet.ie/ldap/recover/username';
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>";
}
await post_request(url, body, form_status);
}

View file

@ -43,7 +43,7 @@
</table>
</form>
<p id="formStatus"></p>
<script src="register.js"></script>
<script type="module" src="register.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -1,3 +1,5 @@
import {post_request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
@ -29,28 +31,5 @@ async function formHandler(listener) {
const body = {auth: auth, user: user, pass: pass};
let url = 'https://api.account.skynet.ie/ldap/new/account';
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>";
}
await post_request(url, body, form_status);
}

View file

@ -46,7 +46,7 @@
<input id="button" type="submit" value="Submit"/>
</form>
<p id="formStatus"></p>
<script src="signup.js"></script>
<script type="module" src="signup.js"></script>
</main>
<footer class="page-footer">
UL Computer Society 2023-<span id="year">2023</span>

View file

@ -1,3 +1,5 @@
import {post_request} from "./js/lib.js";
const form = document.getElementById("form");
form.addEventListener('submit', formHandler);
@ -17,29 +19,6 @@ async function formHandler(listener) {
let url = 'https://api.account.skynet.ie/ldap/new/email';
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>";
}
await post_request(url, body, form_status);
}