Commit 6699ae7d authored by lueyuw's avatar lueyuw
Browse files

save progress

parent 3595d87e
......@@ -5,6 +5,7 @@ from cryptography.fernet import Fernet
import sqlite3
import flask
import pathlib
import datetime
import json
import os
......@@ -157,54 +158,63 @@ def search_user():
with open('info.json') as json_file:
json_data = json.load(json_file)
userType = json_data['userType']
username = json_data['username']
return jsonify({'userType': userType})
return jsonify({'userType': userType, 'username': username})
@ app.route('/message', methods=["POST"])
def send_messages():
"""Send messages to different users."""
connection = get_db()
message = flask.request.json["form"]["message"]
data = request.get_json()
# add into database somehow
file_list = flask.request.json["form"]["fileList"]
sender = flask.session["username"]
receiver = flask.request.json["receiver"]
# file_list = flask.request.json["form"]["fileList"]
print(data)
sender = data['sender']
receiver = data['receiver']
message = data['message']
noneVal = None
now = datetime.datetime.now()
connection = get_db()
connection.execute(
"INSERT INTO messages (?, ?, ?)",
(sender, receiver, message)
"INSERT INTO messages ( sender, receiver, filename, message, sendTime) values(?, ?, ?, ?, ?)",
(sender, receiver, noneVal, message, now.strftime("%Y/%m/%d %H:%M:%S"))
)
connection.commit()
return
return jsonify(True)
@ app.route('/message', methods=["GET"])
def receive_messages():
"""Receive messages from different messages."""
username = ''
with open('info.json') as json_file:
json_data = json.load(json_file)
if json_data['username']:
username = json_data['username']
connection = get_db()
user = flask.session["username"]
messages = connection.execute(
"SELECT * "
"FROM messages "
"WHERE receiver=?",
(user, )
(username, )
).fetchall()
return_messages = []
for message in messages:
m = {
"message": message["text"],
"fileList": [message["filename"]]
"message": message["message"],
"from": message["sender"],
"date": message["sendTime"],
"dialogVisible": False,
"urls": [],
"pdf": ''
}
return_messages.append(m)
context = {
"form": return_messages,
"url": flask.request.url
}
return flask.jsonify(**context)
return jsonify(return_messages)
@ app.route('/vue-admin-template/table/list', methods=["GET"])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment