From 72ea802d4d27a860d5e3b9eae327d1efb85461a2 Mon Sep 17 00:00:00 2001 From: Luna Date: Thu, 22 Jul 2021 23:51:26 -0700 Subject: [PATCH] Misc Changes and Fixes --- .gitignore | 3 +- chat.css | 4 +++ chat.html | 3 +- chat.js | 11 ++++++- login.html | 2 +- login.js | 2 +- loginchange.html | 41 -------------------------- loginchange.js | 77 ------------------------------------------------ register.html | 2 +- register.js | 12 ++++---- style.css | 6 ++-- 11 files changed, 31 insertions(+), 132 deletions(-) delete mode 100644 loginchange.html delete mode 100644 loginchange.js diff --git a/.gitignore b/.gitignore index 290e44d..e74dfca 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ streamchat.code-workspace index.html stream.css assets/ -todo.txt \ No newline at end of file +todo.txt +logout.js \ No newline at end of file diff --git a/chat.css b/chat.css index fc3829f..5ed8007 100644 --- a/chat.css +++ b/chat.css @@ -12,6 +12,10 @@ input { padding: 3%; } +label { + visibility: hidden; +} + #chatbox { background-color: white; padding: 1rem; diff --git a/chat.html b/chat.html index 4d2f232..62d56fc 100644 --- a/chat.html +++ b/chat.html @@ -21,7 +21,8 @@ -
+ +
diff --git a/chat.js b/chat.js index 0e43d9a..f216c0c 100644 --- a/chat.js +++ b/chat.js @@ -3,7 +3,6 @@ let date = '2021-07-22' let messageCount = 0; let username = localStorage.getItem('username'); const form = document.querySelector('form'); -document.querySelector("#loggeduser").innerHTML = `You are logged in as ${username}` // SEND A MESSAGE @@ -64,3 +63,13 @@ function printText(text) { div.appendChild(p) p.innerHTML = text } + + +//LOGGED IN STUFF +//TODO ADD CHECK TO SEE IF USERNAME AND TOKEN MATCHES +if (username === null) { + document.querySelector("#loggeduser").innerHTML = 'You are not logged in' + username = '' +} else { + document.querySelector("#loggeduser").innerHTML = `You are logged in as ${username}` +} \ No newline at end of file diff --git a/login.html b/login.html index 6915897..48ad76a 100644 --- a/login.html +++ b/login.html @@ -16,7 +16,7 @@

Login:

-
+

diff --git a/login.js b/login.js index e8af605..5494aca 100644 --- a/login.js +++ b/login.js @@ -29,7 +29,7 @@ form.addEventListener("submit", async function (event) { function login() { console.log('You have logged in!') - document.querySelector("#username").innerHTML = `${uname}` + document.querySelector("#username").innerHTML = `Logged in as ${uname}` document.querySelector("#errormessage").innerHTML = '' localStorage.setItem("username", `${uname}`); } diff --git a/loginchange.html b/loginchange.html deleted file mode 100644 index 3fbf4c1..0000000 --- a/loginchange.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - Login Change - - - - - - - - - - -

Change username and/or pin:

-

(leave field blank if not changing)

- -
- -
-
- -
-

- -
-
- -
-

- - - -
- - - -
- - diff --git a/loginchange.js b/loginchange.js deleted file mode 100644 index 1fc0941..0000000 --- a/loginchange.js +++ /dev/null @@ -1,77 +0,0 @@ - -//SETTING VARIABLES. GRABBING ELEMENT VALUES FROM FORM. - -let uname = document.querySelector('#uname').value; -let pin = document.querySelector('#pin').value; -let newUname = document.querySelector('#newuname').value; -let newPin = document.querySelector('#newpin').value; -const form = document.querySelector('form'); -let responseText; - - -//TODO -// let selected = document.querySelector('#selected').value; -// let custom = document.querySelector('#custom').value; -// let pronouns = '' - -//FORM SUMBIT FUNCTION & GET THE USERS USERNAME AND SEE IF IT IS CORRECT. - - -form.addEventListener("submit", async function (event) { - event.preventDefault(); - const formData = new FormData(form); - - uname = formData.get('uname'); - pin = formData.get('pin'); - newUname = formData.get('newuname'); - newPin = formData.get('newpin'); - - //TODO - // selected = formData.get('selected'); - // custom = formData.get('custom') - - // if (custom !== '') { - // pronouns = custom - // } else { - // pronouns = selected - // } - - if (newUname === '') { - newUname = uname - } - if (newPin === '') { - newPin = pin - } - - try { - const userNotFound = await getUname(); - - if (userNotFound.status === 'fail') { - document.querySelector("#errormessage").innerHTML = `user ${uname} was not found` - } else { - loginChange() - } - } catch { - document.querySelector("#errormessage").innerHTML = 'An Error has Occurred. Try again later.' - } -}) - - -//FETCH FUNTIONS. FETCHING USERNAME FROM API AND SUBMITTING NEW PIN AND USERNAME TO API. - -async function getUname() { - let response = await fetch(`/api/users/${uname}`); - responseJson = await response.json(); - return responseJson; -} - -async function loginChange() { - const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, { - method: 'POST', - headers: { - }, - body: "" - }); - document.querySelector("#errormessage").innerHTML = 'Login Changed!' - window.location.replace("/login.html") -} diff --git a/register.html b/register.html index 66b3201..fcd4654 100644 --- a/register.html +++ b/register.html @@ -15,7 +15,7 @@
-
+

diff --git a/register.js b/register.js index dea709f..c2604bb 100644 --- a/register.js +++ b/register.js @@ -27,9 +27,9 @@ form.addEventListener("submit", async function (event) { } try { - const isTaken = await getUname(); + const isNotTaken = await getUname(); - if (isTaken.status === "fail") { + if (isNotTaken.status === "fail") { register() } else { document.querySelector("#errormessage").innerHTML = `${uname} is already taken.` @@ -48,11 +48,13 @@ async function getUname() { } async function register() { - const rawResponse = await fetch(`/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase().replace("/", ".")}`, { + let sendRegisterInfo = { "name": uname, "pin": pin, "pronouns": pronouns } + fetch('/api/register/', { method: 'POST', headers: { - }, - body: "" + 'Content-Type': 'application/json', + }, + body: JSON.stringify(sendRegisterInfo), }); document.querySelector("#errormessage").innerHTML = 'Registered!' window.location.replace("/login.html") diff --git a/style.css b/style.css index 1ea339f..a7f671a 100644 --- a/style.css +++ b/style.css @@ -5,7 +5,7 @@ html { } body { - margin-top: 10%; + margin-top: 3%; } form { @@ -17,7 +17,7 @@ form { padding: 5%; box-shadow: 10px 10px 10px black; border-radius: 5px; - display:inline-flex; + display: inline-flex; width: 20%; } @@ -50,4 +50,4 @@ input[type=number]::-webkit-outer-spin-button { input[type=number] { -moz-appearance: textfield; -} +} \ No newline at end of file