Commit c987dfe2 authored by lueyuw's avatar lueyuw
Browse files

final version 1.0

parents 53a25ca1 8b409dfa
......@@ -5,6 +5,7 @@ from cryptography.fernet import Fernet
import sqlite3
import flask
import pathlib
import datetime
import json
import os
......@@ -94,6 +95,7 @@ def create_user():
data = request.get_json()
username = data['username']
print(data)
# make sure username does not exist in db
check_user = connection.execute(
"select * from users where username = ? ", (username,))
......@@ -116,7 +118,6 @@ def create_user():
json.dump(json_data, f)
connection.commit()
flask.redirect('/vue-admin-template/user/login')
return jsonify(True)
......@@ -141,16 +142,17 @@ def validate_login():
json_data = {'username': username,
'userType': query[0]['userType']}
json.dump(json_data, f)
return jsonify(True)
return jsonify(json_data)
else:
with open('info.json') as json_file:
json_data = json.load(json_file)
if json_data['username']:
return jsonify(True)
return jsonify(json_data)
return jsonify(False)
<<<<<<< HEAD
@ app.route('/vue-admin-template/user/form', methods=["POST"])
def send_messages():
"""Send messages to different users."""
......@@ -161,43 +163,78 @@ def send_messages():
# file_list = data["form"]["fileList"]
sender = data["username"]
receiver = data["receiver"]
=======
@app.route('/user/search', methods=["GET", "POST"])
def search_user():
json_data = {}
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, 'username': username})
@ app.route('/message', methods=["POST"])
def send_messages():
"""Send messages to different users."""
data = request.get_json()
# add into database somehow
# file_list = flask.request.json["form"]["fileList"]
print(data)
sender = data['sender']
receiver = data['receiver']
message = data['message']
noneVal = None
now = datetime.datetime.now()
>>>>>>> brian_omega
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('/vue-admin-template/user/form', 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 = {
<<<<<<< HEAD
"message": message["text"],
"fileList": [message["filename"]],
"sender": message["sender"],
"receiver": message["receiver"]
=======
"message": message["message"],
"from": message["sender"],
"date": message["sendTime"],
"dialogVisible": False,
"urls": [],
"pdf": ''
>>>>>>> brian_omega
}
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"])
......@@ -260,30 +297,29 @@ def get_info():
def get_login():
# an example of how to use encryption and decryption on the backend
encrypted_obj = encryptInfo("thisPassword")
decrypted_str = decryptInfo(encrypted_obj[0], encrypted_obj[1])
print(decrypted_str.decode("utf-8"))
# encrypted_obj = encryptInfo("thisPassword")
# decrypted_str = decryptInfo(encrypted_obj[0], encrypted_obj[1])
# print(decrypted_str.decode("utf-8"))
# test
connection = get_db()
username = 'dsbenton'
user_type = 'Patient'
fullname = 'Dejanae Benton'
dob = '07/08/2000'
email = 'dsbenton@umich.edu'
family_admin = 'Rebecca Benton'
filename = ''
password = '111111'
breakpoint()
connection.execute(
"INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(username, user_type, fullname, dob,
email, family_admin, filename, password)
)
test = connection.execute(
"SELECT * FROM users WHERE username=?",
('dsbenton',)
)
return 'Get_login triggered!' + test
# connection = get_db()
# username = 'dsbenton'
# user_type = 'Patient'
# fullname = 'Dejanae Benton'
# dob = '07/08/2000'
# email = 'dsbenton@umich.edu'
# family_admin = 'Rebecca Benton'
# filename = ''
# password = '111111'
# connection.execute(
# "INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
# (username, user_type, fullname, dob,
# email, family_admin, filename, password)
# )
# test = connection.execute(
# "SELECT * FROM users WHERE username=?",
# ('dsbenton',)
# )
return 'Get_login triggered!'
if __name__ == '__main__':
......
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