diff --git a/frontend/js/chat.js b/frontend/js/chat.js index 7acf787..d7aca3c 100644 --- a/frontend/js/chat.js +++ b/frontend/js/chat.js @@ -7,7 +7,7 @@ const logoutButton = document.getElementById('logout'); let currentRecipient = null; -window.onload = function() { +window.onload = () => { document.getElementById('recipient').focus(); } @@ -32,6 +32,7 @@ async function getToken() { const response = await fetch('/auth/token'); if (!response.ok) { console.log('Network response was not ok'); + return null; } return await response.text(); } catch (error) { diff --git a/frontend/js/login.js b/frontend/js/login.js index d4d128e..2ec34bc 100644 --- a/frontend/js/login.js +++ b/frontend/js/login.js @@ -1,3 +1,7 @@ +window.onload = () => { + document.getElementById('username').focus(); +} + function showPasswd() { let x = document.getElementById("password"); if(x.type == "password"){ diff --git a/frontend/js/signup.js b/frontend/js/signup.js index 5c5993c..50f0b80 100644 --- a/frontend/js/signup.js +++ b/frontend/js/signup.js @@ -1,3 +1,7 @@ +window.onload = () => { + document.getElementById('username').focus(); +} + function showPasswd() { let x = document.getElementById("password"); let y = document.getElementById("sPassword"); diff --git a/frontend/routes/chat.html b/frontend/routes/chat.html index 71ad59b..526179b 100644 --- a/frontend/routes/chat.html +++ b/frontend/routes/chat.html @@ -3,20 +3,7 @@ Chat - +
diff --git a/frontend/stylesheet/chat.css b/frontend/stylesheet/chat.css new file mode 100644 index 0000000..d16b376 --- /dev/null +++ b/frontend/stylesheet/chat.css @@ -0,0 +1,73 @@ +body { + margin: 0; + padding-bottom: 3rem; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; + background-color: #f9f9f9; + color: #333; +} + +#form, #recipientForm { + background: rgba(255, 255, 255, 0.9); + padding: 0.5rem; + display: flex; + align-items: center; + box-sizing: border-box; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); + backdrop-filter: blur(10px); + z-index: 1000; +} + +#form { + position: fixed; + bottom: 0; + left: 0; + right: 0; +} + +#recipientForm { + position: fixed; + top: 0; + left: 0; + right: 0; +} + +#input, #recipient { + border: 1px solid #ddd; + padding: 0.5rem 1rem; + flex-grow: 1; + border-radius: 20px; + margin-right: 0.5rem; + font-size: 1rem; + transition: border-color 0.3s ease; +} + +#input:focus, #recipient:focus { + outline: none; + border-color: #007bff; +} + +#form > button, #recipientForm > button { + background: #007bff; + border: none; + padding: 0.5rem 1rem; + margin: 0.25rem; + border-radius: 20px; + color: #fff; + font-size: 1rem; + cursor: pointer; + transition: background-color 0.3s ease; +} + +#form > button:hover, #recipientForm > button:hover { + background-color: #0056b3; +} + +#logout { + background-color: #dc3545; +} + +#logout:hover { + background-color: #c82333; +} + +#messages diff --git a/index.js b/index.js index 54e3801..038c4dd 100644 --- a/index.js +++ b/index.js @@ -161,11 +161,16 @@ async function loginUser(req, res) { if (result.rows.length > 0) { // Compare password const match = await bcrypt.compare(password, result.rows[0].password); - if (match) { + if (!match) { + res.send('Incorrect Username or Password!'); + } const token = jwt.sign({ username }, jwtSecret, { expiresIn: '30d' // token expires in 30 days }); - res.cookie('token', token); + res.cookie('token', token, { + httpOnly: true, + maxAge: 30 * 24 * 60 * 60 * 1000 // 30 days + }); req.session.loggedin = true; req.session.username = username; res.send(` @@ -177,9 +182,6 @@ async function loginUser(req, res) { }, 1500); `); - } else { - res.send('Incorrect Username or Password!'); - } } else { res.send('Incorrect Username or Password!'); }