Misc changes.

main
Luna 2021-07-24 11:27:21 -07:00
parent 446d74daf2
commit ed3aeffc5c
3 changed files with 15 additions and 8 deletions

View File

@ -56,7 +56,7 @@ button {
} }
#loggeduser { #loggeduser {
padding-top: 1.5% padding-top: 2%
} }
#errormessage { #errormessage {

View File

@ -30,13 +30,12 @@
<div id="loggeduser"></div> <div id="loggeduser"></div>
<script src="chat.js"></script> <button type="button" id="logoutbutton" onclick="logout()">Logout</button>
<script src="logout.js"></script>
<button type="button" onclick="logout()">Logout</button>
<div id="errormessage"></div> <div id="errormessage"></div>
<script src="chat.js"></script>
<script src="logout.js"></script>
</body> </body>

14
chat.js
View File

@ -12,8 +12,16 @@ form.addEventListener("submit", async function (event) {
formMessage = formData.get('message').toString(); 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 //SEND MESSAGE FETCH FUNCTION
@ -68,7 +76,7 @@ function printText(text) {
//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'); username = localStorage.getItem('username');
if (username === null || username === '') { 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}`