Added Error Handling and Messages

main
Luna 2021-07-18 08:48:08 -07:00
parent 9185cabe76
commit b3adc7c7dd
3 changed files with 17 additions and 4 deletions

View File

@ -11,6 +11,7 @@ form.addEventListener("submit", async function(event) {
uname = formData.get('uname');
pin = formData.get('pin');
try {
const loginInfo = await loginFetch();
if (loginInfo === "pin matches") {
@ -18,7 +19,9 @@ form.addEventListener("submit", async function(event) {
} else if (loginInfo === "Incorrect pin" || loginInfo === `User ${uname} does not exist.`) {
incorrectLogin()
}
} catch {
document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.'
}
})
async function loginFetch() {

View File

@ -32,7 +32,8 @@ form.addEventListener("submit", async function(event) {
if (newPin === '') {
newPin = pin
}
try {
const userNotFound = await getUname();
if (userNotFound !== `User ${uname}`) {
@ -40,6 +41,9 @@ form.addEventListener("submit", async function(event) {
} else {
loginChange()
}
} catch {
document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.'
}
})
async function getUname() {
@ -56,5 +60,6 @@ const rawResponse = await fetch(`${API_URL}/api/users/change/${uname}/${pin}/${n
},
body: ""
});
//rawResponse.then(window.location.replace("http://127.0.0.1:5500/login.html"))
document.querySelector("#incorrect").innerHTML = 'Login Changed!'
window.location.replace("http://127.0.0.1:5500/login.html")
}

View File

@ -22,6 +22,7 @@ form.addEventListener("submit", async function(event) {
pronouns = selected
}
try {
const isTaken = await getUname();
if (isTaken === `User ${uname}`) {
@ -30,6 +31,9 @@ form.addEventListener("submit", async function(event) {
} else {
register()
}
} catch {
document.querySelector("#taken").innerHTML = 'An Error has Occurred. Try again later.'
}
})
async function getUname() {
@ -46,6 +50,7 @@ const rawResponse = await fetch(`${API_URL}/api/register/${uname.toString().toLo
},
body: ""
});
//rawResponse.then(window.location.replace("http://127.0.0.1:5500/login.html"))
document.querySelector("#taken").innerHTML = 'Registered!'
window.location.replace("http://127.0.0.1:5500/login.html")
}