Changed from recieving strings to JSON

This commit is contained in:
Luna 2021-07-18 10:32:40 -07:00
parent ddac236778
commit dc63fcdc3e
3 changed files with 7 additions and 24 deletions

View file

@ -9,31 +9,16 @@ form.addEventListener("submit", async function(event) {
uname = formData.get('uname');
pin = formData.get('pin');
try {
const loginInfo = await loginFetch();
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.'
const response = await fetch(`/users/${uname}/${pin}`);
const loginInfo = await response.json();
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}`

View file

@ -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: ""
});

View file

@ -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: ""
});