-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
84 lines (74 loc) · 2.44 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import sqlite3
from flask import Flask, url_for, render_template, request, redirect, session
import json
import cecom_doorlock
import User_Authentication
import socket
app = Flask(__name__)
app.secret_key = 'We are Fried Chicken Dinner!!!!'
@app.route("/", methods=['GET', 'POST'])
def doorLock():
if request.method == 'POST':
returnjson = request.get_json(silent=True, cache=False, force=True)
if returnjson['code'] == '1':
print(returnjson['ID'])
return User_Authentication.Authentication(returnjson['ID'])
return str(returnjson)
if request.method == 'GET':
return 'test'
@app.route("/communication", methods=['GET', 'POST'])
def main():
return "hello world"
@app.route("/signIn", methods=['GET', 'POST'])
def registerPage():
if request.method == 'GET':
return render_template('sign_in.html')
else:
id = request.form['id']
name = request.form['name']
conn = sqlite3.connect("test.db")
curs = conn.cursor()
curs.execute("select*from User")
curs.execute("INSERT INTO user(Student_ID,Name) VALUES(" + "'"+ str(id)+"'" + "," + "'" + str(name)+ "'" + ")")
conn.commit()
curs.close()
conn.close()
return "test"
@app.route("/log", methods=['GET', 'POST'])
def logPage():
conn = sqlite3.connect('fileLogDB.db')
curs = conn.cursor()
curs.execute("SELECT * FROM fileLogDB")
sqlData = curs.fetchall()
returnString = ""
for i in sqlData:
returnString +=( "<h1>"+str(i)+"</h1>")
conn.commit()
curs.close()
conn.close()
return returnString
def DBinit():
conn = sqlite3.connect("test.db")
curs = conn.cursor()
curs.execute("DROP TABLE IF EXISTS User")
curs.execute("CREATE TABLE if not exists User(Student_ID, Name);")
conn.commit()
curs.close()
conn.close()
conn = sqlite3.connect("fileLogDB.db")
curs = conn.cursor()
curs.execute("CREATE TABLE if not exists fileLogDB(username, time, file)")
conn.commit()
curs.close()
conn.close()
conn = sqlite3.connect("test.db")
curs = conn.cursor()
curs.execute("select*from User")
curs.execute("INSERT INTO user(Student_ID,Name) VALUES(" + '20178999' + "," + "'testdata'" + ")")
conn.commit()
curs.close()
conn.close()
if __name__ == '__main__':
DBinit()
IP = str(socket.gethostbyname(socket.gethostname()))
app.run(host="192.168.0.20", port=9090, debug=True)