changed the way the js recieves data from strings to json

pull/5/head
Luna 2021-07-18 10:35:34 -07:00
parent d78871a4dd
commit 6cb1d8891a
3 changed files with 10 additions and 27 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,10 +55,9 @@ async function loginChange() {
const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, {
method: 'POST',
headers: {
'Accept': 'text/plain'
},
body: ""
});
document.querySelector("#incorrect").innerHTML = 'Login Changed!'
window.location.replace("/login.html")
window.location.replace("http://127.0.0.1:5500/login.html")
}

View File

@ -36,7 +36,7 @@ form.addEventListener("submit", async function(event) {
})
async function getUname() {
let response = await fetch(`/api/users/${uname}`);
let response = await fetch(`$/api/users/${uname}`);
responseText = await response.text();
return responseText;
}
@ -45,11 +45,10 @@ 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: ""
});
document.querySelector("#taken").innerHTML = 'Registered!'
window.location.replace("/login.html")
window.location.replace("http://127.0.0.1:5500/login.html")
}