-
Notifications
You must be signed in to change notification settings - Fork 5
/
user_management.py
60 lines (52 loc) · 1.75 KB
/
user_management.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
import sqlite3 as sql
import time
import random
def insertUser(username, password, DoB):
con = sql.connect("database_files/database.db")
cur = con.cursor()
cur.execute(
"INSERT INTO users (username,password,dateOfBirth) VALUES (?,?,?)",
(username, password, DoB),
)
con.commit()
con.close()
def retrieveUsers(username, password):
con = sql.connect("database_files/database.db")
cur = con.cursor()
cur.execute(f"SELECT * FROM users WHERE username = '{username}'")
if cur.fetchone() == None:
con.close()
return False
else:
cur.execute(f"SELECT * FROM users WHERE password = '{password}'")
# Plain text log of visitor count as requested by Unsecure PWA management
with open("visitor_log.txt", "r") as file:
number = int(file.read().strip())
number += 1
with open("visitor_log.txt", "w") as file:
file.write(str(number))
# Simulate response time of heavy app for testing purposes
time.sleep(random.randint(80, 90) / 1000)
if cur.fetchone() == None:
con.close()
return False
else:
con.close()
return True
def insertFeedback(feedback):
con = sql.connect("database_files/database.db")
cur = con.cursor()
cur.execute(f"INSERT INTO feedback (feedback) VALUES ('{feedback}')")
con.commit()
con.close()
def listFeedback():
con = sql.connect("database_files/database.db")
cur = con.cursor()
data = cur.execute("SELECT * FROM feedback").fetchall()
con.close()
f = open("templates/partials/success_feedback.html", "w")
for row in data:
f.write("<p>\n")
f.write(f"{row[1]}\n")
f.write("</p>\n")
f.close()