Frontend: misc changes.
parent
971e0e338f
commit
d88f243ee0
|
@ -10,6 +10,7 @@ form {
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
|
margin-top: 1%;
|
||||||
padding: 2%;
|
padding: 2%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: darkgrey;
|
background-color: darkgrey;
|
||||||
|
|
|
@ -12,6 +12,7 @@ form.addEventListener("submit", async function (event) {
|
||||||
|
|
||||||
formMessage = formData.get('message').toString();
|
formMessage = formData.get('message').toString();
|
||||||
|
|
||||||
|
//KINDA UNNECESSARY
|
||||||
//CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE.
|
//CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE.
|
||||||
const response = await fetch(`api/token/${username}/`);
|
const response = await fetch(`api/token/${username}/`);
|
||||||
const matches = await response.json();
|
const matches = await response.json();
|
||||||
|
@ -75,11 +76,10 @@ function printText(text) {
|
||||||
//LOGGED IN STUFF
|
//LOGGED IN STUFF
|
||||||
//TODO ADD CHECK TO SEE IF USERNAME AND TOKEN MATCHES
|
//TODO ADD CHECK TO SEE IF USERNAME AND TOKEN MATCHES
|
||||||
function loggedIn() {
|
function loggedIn() {
|
||||||
username = localStorage.getItem('username');
|
if (username === '' || username === null) {
|
||||||
if (username === null) {
|
|
||||||
document.querySelector("#loggeduser").innerHTML = 'You are not logged in'
|
document.querySelector("#loggeduser").innerHTML = 'You are not logged in'
|
||||||
} else {
|
} else {
|
||||||
document.querySelector("#loggeduser").innerHTML = `You are logged in as ${username}`
|
document.querySelector("#loggeduser").innerHTML = `You are logged in as "${username}"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,10 +48,10 @@ async function loginFetch() {
|
||||||
// FUNCTIONS FOR WHETHER THE LOGIN WAS A SUCCESS OR FAILURE
|
// FUNCTIONS FOR WHETHER THE LOGIN WAS A SUCCESS OR FAILURE
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
window.location.replace("/index.html")
|
|
||||||
document.querySelector("#errormessage").innerHTML = ''
|
document.querySelector("#errormessage").innerHTML = ''
|
||||||
localStorage.setItem('username', `${uname}`);
|
localStorage.setItem('username', `${uname}`);
|
||||||
document.querySelector("#username").innerHTML = `Logged in as ${uname}`
|
document.querySelector("#username").innerHTML = `Logged in as ${uname}`
|
||||||
|
window.location.replace("/index.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
function incorrectLogin() {
|
function incorrectLogin() {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//VARIBLES
|
// //VARIBLES
|
||||||
myStorage = window.localStorage;
|
// myStorage = window.localStorage;
|
||||||
|
// allCookies = document.cookie;
|
||||||
|
|
||||||
//LOGOUT FETCH FUNCTION
|
//LOGOUT FETCH FUNCTION
|
||||||
|
|
||||||
|
@ -19,28 +20,13 @@ async function logout() {
|
||||||
loggedIn()
|
loggedIn()
|
||||||
}
|
}
|
||||||
|
|
||||||
//CHECKS TO SEE IF USERNAME MATCHES TOKEN
|
// // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT
|
||||||
let tokenUpdate = window.setInterval(checkToken, 1000);
|
// if (allCookies !== '' && myStorage.length === 0) {
|
||||||
|
// logout()
|
||||||
|
// }
|
||||||
|
|
||||||
async function checkToken() {
|
// // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY.
|
||||||
const response = await fetch(`api/token/${username}/`);
|
// if (allCookies === '' && myStorage.length !== 0) {
|
||||||
const matches = await response.json();
|
// localStorage.removeItem('username')
|
||||||
|
// document.querySelector("#loggeduser").innerHTML = 'You are not logged in'
|
||||||
//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'
|
|
||||||
}
|
|
Loading…
Reference in New Issue