diff --git a/test/database.py b/database.py
similarity index 100%
rename from test/database.py
rename to database.py
diff --git a/server.py b/server.py
index 263dc45..f643014 100644
--- a/server.py
+++ b/server.py
@@ -657,6 +657,33 @@ def server():
return "File uploaded successfully!"
return "No file found"
+ @app.route("/send", methods=["POST"])
+ def send():
+ message = request.form["message"]
+ username = request.form["username"]
+
+ conn = sqlite3.connect("chat.db")
+ c = conn.cursor()
+ c.execute("INSERT INTO messages (username, message) VALUES (?, ?)", (username, message))
+ conn.commit()
+ conn.close()
+
+ return render_template("index.html")
+
+ @app.route("/get")
+ def get():
+ conn = sqlite3.connect("chat.db")
+ c = conn.cursor()
+ c.execute("SELECT username, message, timestamp FROM messages")
+ messages = c.fetchall()
+ conn.close()
+
+ return render_template("messages.html", messages=messages)
+
+ @app.route("/chat")
+ def chat():
+ return render_template("chat.html")
+
@app.errorhandler(404)
def page_not_found(e):
error_log("called non-existing page")
diff --git a/static/css/style.css b/static/css/style.css
index 7cffeae..150b4b3 100644
--- a/static/css/style.css
+++ b/static/css/style.css
@@ -186,4 +186,34 @@ a {
-
\ No newline at end of file
+
+ #messages {
+ width: 50%;
+ height: 50%;
+ overflow-y: scroll;
+ border: 1px solid gray;
+ padding: 10px;
+ margin-bottom: 10px;
+ background-color: white;
+ border-radius: 10px;
+ }
+
+ .message {
+ margin-bottom: 10px;
+ animation: fadein 0.5s;
+ }
+
+ @keyframes fadein {
+ from { opacity: 0; }
+ to { opacity: 1; }
+ }
+
+ .username {
+ font-weight: bold;
+ color: blue;
+ }
+
+ .timestamp {
+ font-size: 12px;
+ color: gray;
+ }
\ No newline at end of file
diff --git a/static/js/chat.js b/static/js/chat.js
index b5f3702..1a51b31 100644
--- a/static/js/chat.js
+++ b/static/js/chat.js
@@ -1,4 +1,4 @@
-window.onload = function() {
+/*window.onload = function() {
const username = document.getElementById('userNameEntry').innerHTML;
const ws = new WebSocket('ws://localhost:5000')
ws.addEventListener('open', (e) => {
@@ -13,4 +13,62 @@ window.onload = function() {
'username': username
}))
}
+}*/
+
+
diff --git a/test/templates/index.html b/templates/chat.html
similarity index 54%
rename from test/templates/index.html
rename to templates/chat.html
index c7cbbde..bf84de5 100644
--- a/test/templates/index.html
+++ b/templates/chat.html
@@ -6,7 +6,7 @@
flex-direction: column;
align-items: center;
font-family: Arial, sans-serif;
- background-color: lightblue;
+ background-image: linear-gradient(to right, rgb(38, 134, 62), rgb(89, 89, 175))
}
#messages {
@@ -22,6 +22,12 @@
.message {
margin-bottom: 10px;
+ animation: fadein 0.5s;
+ }
+
+ @keyframes fadein {
+ from { opacity: 0; }
+ to { opacity: 1; }
}
.username {
@@ -53,7 +59,44 @@
}
-