Changed from recieving strings to JSON
parent
ddac236778
commit
dc63fcdc3e
27
login.js
27
login.js
|
@ -9,31 +9,16 @@ form.addEventListener("submit", async function(event) {
|
|||
uname = formData.get('uname');
|
||||
pin = formData.get('pin');
|
||||
|
||||
try {
|
||||
const loginInfo = await loginFetch();
|
||||
const response = await fetch(`/users/${uname}/${pin}`);
|
||||
const loginInfo = await response.json();
|
||||
|
||||
if (loginInfo === "pin matches") {
|
||||
login()
|
||||
} else if (loginInfo === "Incorrect pin" || loginInfo === `User ${uname} does not exist.`) {
|
||||
incorrectLogin()
|
||||
}
|
||||
} catch {
|
||||
document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.'
|
||||
if (loginInfo.status === "ok") {
|
||||
login()
|
||||
} else {
|
||||
incorrectLogin()
|
||||
}
|
||||
})
|
||||
|
||||
async function loginFetch() {
|
||||
const rawResponse = await fetch(`/api/users/${uname}/${pin}`, {
|
||||
// credentials: "include",
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'text/plain'
|
||||
},
|
||||
});
|
||||
const content = await rawResponse.text();
|
||||
return content
|
||||
}
|
||||
|
||||
function login() {
|
||||
console.log('You have logged in!')
|
||||
document.querySelector("#username").innerHTML = `${uname}`
|
||||
|
|
|
@ -55,7 +55,6 @@ async function loginChange() {
|
|||
const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'text/plain'
|
||||
},
|
||||
body: ""
|
||||
});
|
||||
|
|
|
@ -45,7 +45,6 @@ async function register() {
|
|||
const rawResponse = await fetch(`/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase().replace("/", ".")}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'text/plain'
|
||||
},
|
||||
body: ""
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue