Skip to content

Commit 6776de6

Browse files
author
david allen
committed
Debugged Teo's impementation
1 parent a7caf20 commit 6776de6

File tree

3 files changed

+348
-17
lines changed

3 files changed

+348
-17
lines changed

capstone_kv_impl.py

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
from kivy.app import App
2+
from kivy.lang import Builder
3+
from kivy.uix.screenmanager import ScreenManager, Screen
4+
import db
5+
6+
global current_user
7+
current_user = object()
8+
global kivy_app
9+
kivy_app = object()
10+
11+
12+
class UserData:
13+
def __init__(self,un =""):
14+
self.UserName=un
15+
self.FirstName=""
16+
self.LastName=""
17+
self.Email=""
18+
self.Interests=""
19+
pass
20+
21+
def update(self,data):
22+
self.UserName = data[1]
23+
self.FirstName= data[3]
24+
self.LastName= data[4]
25+
self.Email= data[5]
26+
self.Interests= data[6]
27+
pass
28+
29+
30+
pass
31+
32+
class SplashWindow(Screen):
33+
34+
pass
35+
36+
class LoginWindow(Screen):#
37+
def login_released(self,usnm, passw):
38+
print(f"user name = {usnm.text}")
39+
print(f"password = {passw.text}")
40+
result = db.un_login(usnm.text,passw.text)
41+
if result == True:
42+
43+
44+
current_user = UserData(usnm.text)
45+
# clear text fields
46+
usnm.text =""
47+
passw.text =""
48+
#set window to profile
49+
kivy_app.root.current = "profile"
50+
self.manager.transition.direction = "left"
51+
pass
52+
else:
53+
# give users feedback that they are not able to log in due to invalid credentials
54+
pass
55+
56+
pass
57+
58+
pass
59+
60+
class ProfileWindow(Screen):
61+
def display_userdata(self,*args):
62+
user_profiles = db.profile_get(current_user.UserName)
63+
assert len(user_profiles)
64+
65+
user_data = user_profiles[0]
66+
current_user.update(user_data)
67+
for i in range (len(args)):
68+
args[i].text = user_data[i + 1]
69+
pass
70+
71+
72+
pass
73+
pass
74+
75+
class ProfileCreateWindow(Screen):
76+
def create_profile_released(self,usnm,passw,first_name,last_name,email,interests):
77+
db.profile_new(usnm.text,passw.text,first_name.text,last_name.text,email.text,interests.text)
78+
global current_user
79+
current_user.UserName = usnm.text
80+
current_user.FirstName = first_name.text
81+
current_user.LastName = last_name.text
82+
current_user.Email = email.text
83+
current_user.Interests = interests.text
84+
85+
86+
pass
87+
88+
89+
pass
90+
91+
class WindowManager(ScreenManager):
92+
93+
def get_username(self):
94+
global current_user
95+
96+
return current_user.UserName
97+
98+
def update_username(self,newusername ):
99+
100+
global current_user
101+
current_user.UserName = newusername
102+
103+
pass
104+
105+
def clear_released(self,* args):
106+
for element in args:
107+
element.text = ""
108+
pass
109+
pass
110+
111+
112+
pass
113+
114+
115+
current_user = UserData()
116+
117+
kv = Builder.load_file("my.kv")
118+
119+
120+
class MyMainApp(App):
121+
def build(self):
122+
return kv
123+
124+
def main():
125+
# # Teo: use these lines to manipulate database
126+
# Database initialization and tests
127+
db.init()
128+
# db.un_exists('userNameThatDoesNotExist')
129+
# db.profile_delete('userNameThatDoesNotExist')
130+
# db.profile_delete('davidDelSol')
131+
# db.profile_new(
132+
# 'davidDelSol',
133+
# 'encrypted?',
134+
# 'david',
135+
# 'aloka',
136+
# 'test@preform.io',
137+
# 'salsa,extended intelligence,marathon running in a full suit'
138+
# )
139+
# db.profile_new(
140+
# 'Python733t',
141+
# 'encrypted?',
142+
# 'Doroteo ',
143+
# 'Bonilla',
144+
# 'doabonilla@yahoo.com',
145+
# 'work,school,sleep,repeat'
146+
# )
147+
# db.un_login('davidDelSol', 'encrypted?')
148+
# db.profile_update('davidDelSol', pw = 'definitelyNotEncripted!')
149+
# db.un_login('davidDelSol', 'definitelyNotEncripted!')
150+
# db.un_exists('davidDelSol')
151+
# db.profile_print(all = True)
152+
# db.profile_print(['Python733t'])
153+
# db.profile_print('Python733t')
154+
pass
155+
156+
157+
if __name__ == "__main__":
158+
kivy_app = MyMainApp()
159+
160+
main()
161+
kivy_app.run()

db.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf-8 -*-
1+
import string
22
# ---------------------
33
# defaults
44
# ---------------------
@@ -9,7 +9,7 @@
99
# ---------------------
1010
import sqlite3
1111
# reference tutorial: https://www.youtube.com/watch?v=byHcYRpMgI4
12-
def init(db_name = DB_NAME, t_name = T_NAME):
12+
def init(db_name = DB_NAME, table_name = T_NAME):
1313
# connect to database
1414
# database file is created if it doesn't exist
1515
conn = sqlite3.connect(db_name)
@@ -19,7 +19,7 @@ def init(db_name = DB_NAME, t_name = T_NAME):
1919
# create a cursor
2020
c = conn.cursor()
2121
# create a table | DATYPES: null, integer, real, text, blob
22-
c.execute(f"""CREATE TABLE IF NOT EXISTS {t_name} (
22+
c.execute(f"""CREATE TABLE IF NOT EXISTS {table_name} (
2323
un text,
2424
pw text,
2525
first_name text,
@@ -33,7 +33,7 @@ def init(db_name = DB_NAME, t_name = T_NAME):
3333
# close connection (good practice)
3434
conn.close()
3535

36-
print(f'Initialized database "{db_name}" and table "{t_name}".')
36+
print(f'Initialized database "{db_name}" and table "{table_name}".')
3737

3838
return
3939

@@ -63,6 +63,7 @@ def profile_new(
6363
ints,
6464
db_name = DB_NAME
6565
):
66+
result = False
6667
conn = sqlite3.connect(db_name)
6768
c = conn.cursor()
6869

@@ -77,6 +78,7 @@ def profile_new(
7778
)
7879
""", (un, pw, fn, ln, em, ints,))
7980
conn.commit()
81+
result = True
8082
print(f'Created new profile for "{un}".')
8183
pass
8284
else:
@@ -85,10 +87,10 @@ def profile_new(
8587

8688
conn.close()
8789

90+
return result
8891

89-
return
9092

91-
def profile_print(*args, **kwargs):
93+
def profile_get(*args, **kwargs):
9294
uns = []
9395
print_all = False
9496
profiles = []
@@ -133,15 +135,14 @@ def profile_print(*args, **kwargs):
133135
profiles.append(c.fetchone())
134136

135137

136-
result = True if len(profiles) else False
137138

138139
print(f'db.profile_print("*{args}, **{kwargs}") profiles =')
139140
for profile in profiles:
140141
print(profile)
141142

142143
conn.close()
143144

144-
return result
145+
return profiles
145146

146147
def un_login(un, pw, db_name = DB_NAME):
147148
conn = sqlite3.connect(db_name)
@@ -239,9 +240,9 @@ def main():
239240
profile_update('davidDelSol', pw = 'definitelyNotEncripted!')
240241
un_login('davidDelSol', 'definitelyNotEncripted!')
241242
un_exists('davidDelSol')
242-
profile_print(all = True)
243-
profile_print(['Python733t'])
244-
profile_print('Python733t')
243+
profile_get(all = True)
244+
profile_get(['Python733t'])
245+
profile_get('Python733t')
245246

246247
pass
247248

0 commit comments

Comments
 (0)