From ed3aeffc5c317a4aff5913406beb9e78044383f3 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 24 Jul 2021 11:27:21 -0700 Subject: [PATCH] Misc changes. --- chat.css | 2 +- chat.html | 7 +++---- chat.js | 14 +++++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/chat.css b/chat.css index 384156e..27167d8 100644 --- a/chat.css +++ b/chat.css @@ -56,7 +56,7 @@ button { } #loggeduser { - padding-top: 1.5% + padding-top: 2% } #errormessage { diff --git a/chat.html b/chat.html index 3b04835..364eb57 100644 --- a/chat.html +++ b/chat.html @@ -30,13 +30,12 @@
- - - - +
+ + diff --git a/chat.js b/chat.js index ca2ba7e..447f995 100644 --- a/chat.js +++ b/chat.js @@ -12,8 +12,16 @@ form.addEventListener("submit", async function (event) { formMessage = formData.get('message').toString(); - sendMessage() - + //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(); + + //YES THIS IS CONFUSING I KNOW. + if (matches.status === "ok") { + sendMessage() + } else { + document.querySelector("#errormessage").innerHTML = 'Username and token mismatch. Try logging in again.' + } }) //SEND MESSAGE FETCH FUNCTION @@ -68,7 +76,7 @@ function printText(text) { //TODO ADD CHECK TO SEE IF USERNAME AND TOKEN MATCHES function loggedIn() { username = localStorage.getItem('username'); - if (username === null || username === '') { + if (username === null) { document.querySelector("#loggeduser").innerHTML = 'You are not logged in' } else { document.querySelector("#loggeduser").innerHTML = `You are logged in as ${username}`