Added Error Handling and Messages
parent
9185cabe76
commit
b3adc7c7dd
5
login.js
5
login.js
|
@ -11,6 +11,7 @@ form.addEventListener("submit", async function(event) {
|
||||||
uname = formData.get('uname');
|
uname = formData.get('uname');
|
||||||
pin = formData.get('pin');
|
pin = formData.get('pin');
|
||||||
|
|
||||||
|
try {
|
||||||
const loginInfo = await loginFetch();
|
const loginInfo = await loginFetch();
|
||||||
|
|
||||||
if (loginInfo === "pin matches") {
|
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.`) {
|
} else if (loginInfo === "Incorrect pin" || loginInfo === `User ${uname} does not exist.`) {
|
||||||
incorrectLogin()
|
incorrectLogin()
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function loginFetch() {
|
async function loginFetch() {
|
||||||
|
|
|
@ -32,7 +32,8 @@ form.addEventListener("submit", async function(event) {
|
||||||
if (newPin === '') {
|
if (newPin === '') {
|
||||||
newPin = pin
|
newPin = pin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const userNotFound = await getUname();
|
const userNotFound = await getUname();
|
||||||
|
|
||||||
if (userNotFound !== `User ${uname}`) {
|
if (userNotFound !== `User ${uname}`) {
|
||||||
|
@ -40,6 +41,9 @@ form.addEventListener("submit", async function(event) {
|
||||||
} else {
|
} else {
|
||||||
loginChange()
|
loginChange()
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getUname() {
|
async function getUname() {
|
||||||
|
@ -56,5 +60,6 @@ const rawResponse = await fetch(`${API_URL}/api/users/change/${uname}/${pin}/${n
|
||||||
},
|
},
|
||||||
body: ""
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ form.addEventListener("submit", async function(event) {
|
||||||
pronouns = selected
|
pronouns = selected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const isTaken = await getUname();
|
const isTaken = await getUname();
|
||||||
|
|
||||||
if (isTaken === `User ${uname}`) {
|
if (isTaken === `User ${uname}`) {
|
||||||
|
@ -30,6 +31,9 @@ form.addEventListener("submit", async function(event) {
|
||||||
} else {
|
} else {
|
||||||
register()
|
register()
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
document.querySelector("#taken").innerHTML = 'An Error has Occurred. Try again later.'
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getUname() {
|
async function getUname() {
|
||||||
|
@ -46,6 +50,7 @@ const rawResponse = await fetch(`${API_URL}/api/register/${uname.toString().toLo
|
||||||
},
|
},
|
||||||
body: ""
|
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue