diff --git a/frontend/chat.css b/frontend/chat.css index 27167d8..a66c822 100644 --- a/frontend/chat.css +++ b/frontend/chat.css @@ -10,6 +10,7 @@ form { } input { + margin-top: 1%; padding: 2%; width: 100%; background-color: darkgrey; diff --git a/frontend/chat.js b/frontend/chat.js index 447f995..fb61f3b 100644 --- a/frontend/chat.js +++ b/frontend/chat.js @@ -12,6 +12,7 @@ form.addEventListener("submit", async function (event) { formMessage = formData.get('message').toString(); + //KINDA UNNECESSARY //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE. const response = await fetch(`api/token/${username}/`); const matches = await response.json(); @@ -75,11 +76,10 @@ function printText(text) { //LOGGED IN STUFF //TODO ADD CHECK TO SEE IF USERNAME AND TOKEN MATCHES function loggedIn() { - username = localStorage.getItem('username'); - if (username === null) { + if (username === '' || username === null) { document.querySelector("#loggeduser").innerHTML = 'You are not logged in' } else { - document.querySelector("#loggeduser").innerHTML = `You are logged in as ${username}` + document.querySelector("#loggeduser").innerHTML = `You are logged in as "${username}"` } } diff --git a/frontend/login.js b/frontend/login.js index 6584e8d..67190da 100644 --- a/frontend/login.js +++ b/frontend/login.js @@ -48,10 +48,10 @@ async function loginFetch() { // FUNCTIONS FOR WHETHER THE LOGIN WAS A SUCCESS OR FAILURE function login() { - window.location.replace("/index.html") document.querySelector("#errormessage").innerHTML = '' localStorage.setItem('username', `${uname}`); document.querySelector("#username").innerHTML = `Logged in as ${uname}` + window.location.replace("/index.html") } function incorrectLogin() { diff --git a/frontend/logout.js b/frontend/logout.js index 67b15aa..2d88038 100644 --- a/frontend/logout.js +++ b/frontend/logout.js @@ -1,5 +1,6 @@ -//VARIBLES -myStorage = window.localStorage; +// //VARIBLES +// myStorage = window.localStorage; +// allCookies = document.cookie; //LOGOUT FETCH FUNCTION @@ -19,28 +20,13 @@ async function logout() { loggedIn() } -//CHECKS TO SEE IF USERNAME MATCHES TOKEN -let tokenUpdate = window.setInterval(checkToken, 1000); +// // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT +// if (allCookies !== '' && myStorage.length === 0) { +// logout() +// } -async function checkToken() { - const response = await fetch(`api/token/${username}/`); - const matches = await response.json(); - - //YES THIS IS CONFUSING I KNOW. - if (matches.status === "fail") { - loggedOut() - } - - // IF NO USERNAME BUT HAS A TOKEN THEN LOGOUT - - if (matches.status === "ok" && myStorage.length === 0) { - logout() - } -} - -//AND IF THEY DON'T HAVE A TOKEN CLEARS THE LOCAL STORED USERNAME - -function loggedOut() { - localStorage.removeItem('username') - document.querySelector("#loggeduser").innerHTML = 'You are not logged in' -} \ No newline at end of file +// // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY. +// if (allCookies === '' && myStorage.length !== 0) { +// localStorage.removeItem('username') +// document.querySelector("#loggeduser").innerHTML = 'You are not logged in' +// } \ No newline at end of file