Merge branch 'main' of github.com:23marabi/chat-registration

pull/5/head
~erin 2021-07-18 14:12:27 -04:00
commit 5d4caf1804
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'); uname = formData.get('uname');
pin = formData.get('pin'); pin = formData.get('pin');
try { const response = await fetch(`/api/users/${uname}/${pin}`);
const loginInfo = await loginFetch(); const loginInfo = await response.json();
if (loginInfo === "pin matches") { if (loginInfo.status === "ok") {
login() login()
} else if (loginInfo === "Incorrect pin" || loginInfo === `User ${uname} does not exist.`) { } else {
incorrectLogin() incorrectLogin()
}
} catch {
document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.'
} }
}) })
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() { function login() {
console.log('You have logged in!') console.log('You have logged in!')
document.querySelector("#username").innerHTML = `${uname}` 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}`, { const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'text/plain'
}, },
body: "" body: ""
}); });
document.querySelector("#incorrect").innerHTML = 'Login Changed!' 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() { async function getUname() {
let response = await fetch(`/api/users/${uname}`); let response = await fetch(`$/api/users/${uname}`);
responseText = await response.text(); responseText = await response.text();
return responseText; return responseText;
} }
@ -45,11 +45,10 @@ async function register() {
const rawResponse = await fetch(`/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase().replace("/", ".")}`, { const rawResponse = await fetch(`/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase().replace("/", ".")}`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Accept': 'text/plain'
}, },
body: "" body: ""
}); });
document.querySelector("#taken").innerHTML = 'Registered!' document.querySelector("#taken").innerHTML = 'Registered!'
window.location.replace("/login.html") window.location.replace("http://127.0.0.1:5500/login.html")
} }