Lots of fixes and misc changes.
parent
4e57c11eaa
commit
d05db5c2de
|
@ -1,3 +1,4 @@
|
||||||
streamchat.code-workspace
|
streamchat.code-workspace
|
||||||
assets/
|
assets/
|
||||||
todo.txt
|
todo.txt
|
||||||
|
isonline.js
|
5
chat.css
5
chat.css
|
@ -25,6 +25,10 @@ label {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: 1%;
|
||||||
|
}
|
||||||
|
|
||||||
#loggeduser {
|
#loggeduser {
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +48,7 @@ label {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 90%;
|
height: 90%;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
|
overflow-x: hidden;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
15
chat.html
15
chat.html
|
@ -30,22 +30,13 @@
|
||||||
|
|
||||||
<div id="loggeduser"></div>
|
<div id="loggeduser"></div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script src="chat.js"></script>
|
||||||
window.onload = function() {
|
<script src="logout.js"></script>
|
||||||
let a = document.getElementById("logoutlink");
|
|
||||||
a.onclick = function() {
|
|
||||||
logout()
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<a id="logoutlink" href="stream.html">(logout)</a>
|
<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>
|
||||||
|
|
||||||
|
|
3
chat.js
3
chat.js
|
@ -1,5 +1,4 @@
|
||||||
// VARIABLES
|
// VARIABLES
|
||||||
let date = '2021-07-22'
|
|
||||||
let messageCount = 0;
|
let messageCount = 0;
|
||||||
let username = localStorage.getItem('username');
|
let username = localStorage.getItem('username');
|
||||||
const form = document.querySelector('form');
|
const form = document.querySelector('form');
|
||||||
|
@ -20,7 +19,7 @@ form.addEventListener("submit", async function (event) {
|
||||||
//SEND MESSAGE FETCH FUNCTION
|
//SEND MESSAGE FETCH FUNCTION
|
||||||
|
|
||||||
async function sendMessage() {
|
async function sendMessage() {
|
||||||
sendMessageInfo = { "name": username, "body": formMessage, "date": date }
|
sendMessageInfo = { "name": username, "body": formMessage }
|
||||||
fetch('/api/message/send', {
|
fetch('/api/message/send', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
@ -33,7 +33,7 @@ a {
|
||||||
|
|
||||||
#chatbox {
|
#chatbox {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
height: 50rem;
|
height: 53rem;
|
||||||
margin-left: 0.3em;
|
margin-left: 0.3em;
|
||||||
margin-right: -50%;
|
margin-right: -50%;
|
||||||
border: none;
|
border: none;
|
||||||
|
|
36
login.js
36
login.js
|
@ -4,6 +4,7 @@
|
||||||
let uname = document.querySelector('#uname').value;
|
let uname = document.querySelector('#uname').value;
|
||||||
let pin = document.querySelector('#pin').value;
|
let pin = document.querySelector('#pin').value;
|
||||||
const form = document.querySelector('form');
|
const form = document.querySelector('form');
|
||||||
|
let username = localStorage.getItem('username');
|
||||||
|
|
||||||
// SUBMIT FORM FUNCTION. AND FETCH USERNAME AND PIN FROM API.
|
// SUBMIT FORM FUNCTION. AND FETCH USERNAME AND PIN FROM API.
|
||||||
|
|
||||||
|
@ -14,24 +15,47 @@ form.addEventListener("submit", async function (event) {
|
||||||
uname = formData.get('uname');
|
uname = formData.get('uname');
|
||||||
pin = formData.get('pin');
|
pin = formData.get('pin');
|
||||||
|
|
||||||
const response = await fetch(`/api/users/${uname}/${pin}`);
|
try {
|
||||||
const loginInfo = await response.json();
|
const loginInfo = await loginFetch();
|
||||||
|
|
||||||
if (loginInfo.status === "ok") {
|
console.log(loginInfo)
|
||||||
|
|
||||||
|
if (loginInfo.status === 200) {
|
||||||
login()
|
login()
|
||||||
} else {
|
} else {
|
||||||
incorrectLogin()
|
incorrectLogin()
|
||||||
}
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.log(e);
|
||||||
|
document.querySelector("#errormessage").innerHTML = 'An Error has Occurred. Try again later. ' + e.toString();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// LOGIN FETCH
|
||||||
|
|
||||||
|
async function loginFetch() {
|
||||||
|
let sendLoginInfo = { "name": uname, "pin": pin }
|
||||||
|
return await fetch('/api/login/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(sendLoginInfo),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// FUNCTIONS FOR WHETHER THE LOGIN WAS A SUCCESS OR FAILURE
|
// FUNCTIONS FOR WHETHER THE LOGIN WAS A SUCCESS OR FAILURE
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
console.log('You have logged in!')
|
window.location.replace("/index.html")
|
||||||
document.querySelector("#username").innerHTML = `Logged in as ${uname}`
|
|
||||||
document.querySelector("#errormessage").innerHTML = ''
|
document.querySelector("#errormessage").innerHTML = ''
|
||||||
localStorage.setItem("username", `${uname}`);
|
localStorage.setItem('username', `${uname}`);
|
||||||
|
|
||||||
|
if (username != '') {
|
||||||
|
document.querySelector("#username").innerHTML = `Logged in as ${username}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function incorrectLogin() {
|
function incorrectLogin() {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
//VARIBLES
|
//VARIBLES
|
||||||
|
|
||||||
let username = localStorage.getItem('username');
|
// //IF NOT LOGGED IN DON'T SHOW LOG IN BUTTON
|
||||||
|
// if (username === '') {
|
||||||
|
// document.getElementById("logoutlink").style.display = "none";
|
||||||
|
// }
|
||||||
|
|
||||||
//LOGOUT FETCH FUNCTION
|
//LOGOUT FETCH FUNCTION
|
||||||
|
|
||||||
|
@ -11,10 +14,9 @@ async function logout() {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(sendRegisterInfo),
|
body: JSON.stringify(sendLogoutInfo),
|
||||||
});
|
});
|
||||||
document.querySelector("#errormessage").innerHTML = 'Logged out.'
|
document.querySelector("#errormessage").innerHTML = 'Logged out.'
|
||||||
localStorage.removeItem('username')
|
localStorage.removeItem('username')
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
31
register.js
31
register.js
|
@ -6,7 +6,7 @@ let pin = document.querySelector('#pin').value;
|
||||||
let selected = document.querySelector('#selected').value;
|
let selected = document.querySelector('#selected').value;
|
||||||
let custom = document.querySelector('#custom').value;
|
let custom = document.querySelector('#custom').value;
|
||||||
let pronouns = ''
|
let pronouns = ''
|
||||||
let responseText;
|
let responseJson;
|
||||||
const form = document.querySelector('form');
|
const form = document.querySelector('form');
|
||||||
|
|
||||||
//SUBMIT FUNCTION &CHECKING IF USERNAME IS TAKEN
|
//SUBMIT FUNCTION &CHECKING IF USERNAME IS TAKEN
|
||||||
|
@ -20,33 +20,27 @@ form.addEventListener("submit", async function (event) {
|
||||||
selected = formData.get('selected');
|
selected = formData.get('selected');
|
||||||
custom = formData.get('custom')
|
custom = formData.get('custom')
|
||||||
|
|
||||||
if (custom !== '') {
|
if (custom === '' && selected === 'none') {
|
||||||
pronouns = custom
|
newPronouns = ''
|
||||||
|
} else if (custom !== '') {
|
||||||
|
newPronouns = custom
|
||||||
} else {
|
} else {
|
||||||
pronouns = selected
|
newPronouns = selected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const response = await fetch(`api/users/${uname}/`);
|
||||||
const isNotTaken = await getUname();
|
const isTaken = await response.json();
|
||||||
|
|
||||||
if (isNotTaken.status === "fail") {
|
//YES THIS IS CONFUSING I KNOW.
|
||||||
|
if (isTaken.status === "fail") {
|
||||||
register()
|
register()
|
||||||
} else {
|
} else {
|
||||||
document.querySelector("#errormessage").innerHTML = `${uname} is already taken.`
|
document.querySelector('#errormessage').innerHTML = `${uname} is already taken.`
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
document.querySelector("#errormessage").innerHTML = 'An Error has Occurred. Try again later.'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
//FETCH FUNCTIONS. GETTING USERNAME FROM API & REGISTERING USER ASSIGNED NAME AND PIN.
|
//FETCH FUNCTIONS. GETTING USERNAME FROM API & REGISTERING USER ASSIGNED NAME AND PIN.
|
||||||
|
|
||||||
async function getUname() {
|
|
||||||
let response = await fetch(`/api/users/${uname}`);
|
|
||||||
responseJson = await response.json();
|
|
||||||
return responseJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function register() {
|
async function register() {
|
||||||
let sendRegisterInfo = { "name": uname, "pin": pin, "pronouns": pronouns }
|
let sendRegisterInfo = { "name": uname, "pin": pin, "pronouns": pronouns }
|
||||||
fetch('/api/register/', {
|
fetch('/api/register/', {
|
||||||
|
@ -60,3 +54,6 @@ async function register() {
|
||||||
window.location.replace("/login.html")
|
window.location.replace("/login.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function errorMessage() {
|
||||||
|
// document.querySelector("#errormessage").innerHTML = 'An error has occurrred. Please try again later.'
|
||||||
|
// }
|
||||||
|
|
Loading…
Reference in New Issue