forked from young-k/easybank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
71 lines (62 loc) · 1.83 KB
/
database.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
import sqlite3
conn = sqlite3.connect('./data/example.db', check_same_thread=False)
c = conn.cursor()
"""
Initializes tables
Params:
None
"""
def create_table():
c.execute('''CREATE TABLE IF NOT EXISTS users (first_name text, last_name text, email text, phoneNumber text, password text, profileType text)''')
#c.execute('''CREATE TABLE IF NOT EXISTS survey (q1 text, q2 text, q3 text)''')
"""
Adds a user to the users database
Params:
first_name, last_name, email, password, profileType
"""
def create_user(first_name, last_name, email, phoneNumber, password,profileType):
if user_exists(email):
return False
else:
sql = "INSERT INTO users VALUES(?, ?, ?, ?,?,?)"
c.execute(sql, (first_name, last_name, email, phoneNumber, password, profileType))
conn.commit()
return True
"""
Checks if user's email is already registered within the database
"""
def user_exists(email):
c.execute("Select * from users u where u.email = "+ "'" + email + "'")
data=c.fetchall()
if len(data) == 0:
return False
else:
return True
"""
Updates user profileType
"""
def user_update(email, profileType):
c.execute("UPDATE users SET profileType='" + profileType + "' WHERE profileType = '0' AND email='" + email + "'")
conn.commit()
"""
Checks if login information is correct
"""
def user_authentication(email, password):
c.execute("Select * from users u where u.email = "+ "'" + email + "' AND u.password= "+"'" + password + "'")
data=c.fetchall()
if len(data)==0:
return False
else:
return True
"""
Params:
None
"""
def print_users():
for row in c.execute("Select * from users"):
print row
if __name__ == "__main__":
# Creating Tables
create_table()
# Testing create_user
print_users()