1+ from os import system , getcwd
2+ from time import sleep
3+ from string import ascii_uppercase , digits , punctuation
4+ from MainAdmin import adminMode
5+ from MainCustomer import customerMode
6+ from InputCustomer import readInventoryReport
7+ from ScreensStore import storeSign , storeSignAdmin , errorMessage
8+
9+
10+
11+ class Account :
12+ def __init__ (self , username , password , address , contact_no ):
13+ self .username = username
14+ self .password = password
15+ self .address = address
16+ self .contact_no = contact_no
17+
18+
19+
20+ account_list = []
21+ purchase_list = []
22+
23+
24+
25+ def readAccountStorage (acc_storage ):
26+ acc_list = []
27+
28+ get_file_path = getcwd ()
29+
30+ create_file_path = f"{ get_file_path } \\ Text Files"
31+
32+ read_acc_list = open (f"{ create_file_path } \\ account_list.txt" , "r" )
33+ read_account = read_acc_list .readline ()
34+
35+ while read_account != "" :
36+ account_details = read_account .split ()
37+
38+ acc_list .append ((account_details [0 ], account_details [1 ], account_details [2 ], account_details [3 ]))
39+
40+ read_account = read_acc_list .readline ()
41+
42+ read_acc_list .close ()
43+
44+ acc_storage = acc_list
45+
46+ return acc_storage
47+
48+
49+
50+ def writeAccountStorage (acc_storage ):
51+ get_file_path = getcwd ()
52+
53+ create_file_path = f"{ get_file_path } \\ Text Files"
54+
55+ write_acc_list = open (f"{ create_file_path } \\ account_list.txt" , "w" )
56+
57+ for account_details in acc_storage :
58+ write_to_file = f"{ account_details [0 ]} { account_details [1 ]} { account_details [2 ]} { account_details [3 ]} \n "
59+
60+ write_acc_list .write (write_to_file )
61+
62+ write_acc_list .close ()
63+
64+
65+
66+ def login ():
67+ global account_list
68+
69+ if len (account_list ) == 0 :
70+ account_list = readAccountStorage (account_list )
71+
72+ storeSign ()
73+ print (" LOG-IN TO ShopSmart\n " )
74+ print ("=" * 30 , "\n " )
75+ print (' *Type -1 at the prompt to\n cancel the process*\n ' )
76+ print ("=" * 30 , "\n \n " )
77+
78+ while True :
79+ username_input = input ("\033 [1A\033 [K Enter Username: " )
80+
81+ if username_input == "-1" :
82+ return None
83+ elif username_input == "admin" or [un for un in account_list if un [0 ] == username_input ]:
84+ break
85+ else :
86+ sleep (0.5 )
87+ print ("\033 [1A\033 [K USER DOES NOT EXIST" )
88+ sleep (1.25 )
89+
90+ print ()
91+
92+ while True :
93+ password_input = input ("\033 [1A\033 [K Enter Password: " )
94+
95+ if password_input == "-1" :
96+ return None
97+ elif username_input == "admin" and password_input == "admin" :
98+ adminMode ()
99+ break
100+ elif [un for un in account_list if un [0 ] == username_input and un [1 ] == password_input ]:
101+ customerMode (username_input )
102+ break
103+ else :
104+ sleep (0.5 )
105+ print ("\033 [1A\033 [K INCORRECT PASSWORD" )
106+ sleep (1.25 )
107+
108+
109+ def signup ():
110+ global account_list
111+
112+ account_list = []
113+ account_list = readAccountStorage (account_list )
114+
115+ storeSign ()
116+ print (" CREATE ShopSmart ACCOUNT\n " )
117+ print ("=" * 30 , "\n " )
118+ print (" Account Creation Guidelines\n " )
119+ print (" - Usernames are permanent and\n cannot be changed" )
120+ print (" - Usernames must not contain\n spaces or punctuation" )
121+ print (" - Usernames must be at least\n 3 characters in length" )
122+ print (" - Addresses must not contain\n spaces or punctuation" )
123+ print (" - Addresses must be at least\n 3 characters in length" )
124+ print (" - Replace spaces with a dash\n for addresses" )
125+ print (" - Contact numbers must be 11\n digits in length" )
126+ print (" - Passwords must be at least\n 8 characters in length" )
127+ print (" - Passwords must contain at\n least 1 uppercase letter" )
128+ print (" - Passwords must contain at\n least 1 number\n " )
129+ print ("=" * 30 , "\n " )
130+ print (' *Type -1 at the prompt to\n cancel the process*\n ' )
131+ print ("=" * 30 , "\n \n " )
132+
133+ while True :
134+ invalid_username = 0
135+
136+ new_username = input ("\033 [1A\033 [K Enter Username: " )
137+
138+ if new_username == "-1" :
139+ return None
140+
141+ for i in new_username :
142+ if i in punctuation or i == " " :
143+ invalid_username += 1
144+
145+ if invalid_username != 0 or len (new_username ) < 3 :
146+ sleep (0.5 )
147+ print ("\033 [1A\033 [K INVALID USERNAME" )
148+ sleep (1.25 )
149+ elif new_username == "admin" or [un for un in account_list if un [0 ] == new_username ]:
150+ sleep (0.5 )
151+ print ("\033 [1A\033 [K USER ALREADY EXISTS" )
152+ sleep (1.25 )
153+ else :
154+ break
155+
156+ print ("\n " )
157+
158+ while True :
159+ invalid_address = 0
160+
161+ new_address = input ("\033 [1A\033 [K Enter Address: " )
162+
163+ if new_address == "-1" :
164+ return None
165+
166+ for i in new_address :
167+ if i in [punc for punc in punctuation if punc != "-" ] or i == " " :
168+ invalid_address += 1
169+
170+ if invalid_address != 0 or len (new_address ) < 3 :
171+ sleep (0.5 )
172+ print ("\033 [1A\033 [K INVALID ADDRESS" )
173+ sleep (1.25 )
174+ else :
175+ break
176+
177+ print ()
178+
179+ while True :
180+ invalid_conact_no = 0
181+
182+ new_contact_no = input ("\033 [1A\033 [K Enter Contact #: " )
183+
184+ if new_contact_no == "-1" :
185+ return None
186+
187+ for i in new_contact_no :
188+ if i not in digits :
189+ invalid_conact_no += 1
190+
191+ if invalid_conact_no != 0 or len (new_contact_no ) != 11 :
192+ sleep (0.5 )
193+ print ("\033 [1A\033 [K INVALID CONTACT #" )
194+ sleep (1.25 )
195+ elif [un for un in account_list if un [3 ] == new_contact_no ]:
196+ sleep (0.5 )
197+ print ("\033 [1A\033 [K CONTACT # ALREADY USED" )
198+ sleep (1.25 )
199+ else :
200+ break
201+
202+ print ("\n " )
203+
204+ while True :
205+ uppercase_true = 0
206+ numbers_true = 0
207+
208+ new_password = input ("\033 [1A\033 [K Enter Password: " )
209+
210+ if new_password == "-1" :
211+ return None
212+
213+ for i in new_password :
214+ if i in ascii_uppercase :
215+ uppercase_true += 1
216+
217+ for i in new_password :
218+ if i in digits :
219+ numbers_true += 1
220+
221+ if uppercase_true != 0 and numbers_true != 0 and len (new_password ) >= 8 :
222+ break
223+ else :
224+ sleep (0.5 )
225+ print ("\033 [1A\033 [K INVALID PASSWORD" )
226+ sleep (1.25 )
227+
228+ print ()
229+
230+ while True :
231+ confirm_password = input ("\033 [1A\033 [K Confirm Password: " )
232+
233+ if confirm_password == "-1" :
234+ return None
235+
236+ if confirm_password == new_password :
237+ break
238+ else :
239+ sleep (0.5 )
240+ print ("\033 [1A\033 [K PASSWORDS DON'T MATCH" )
241+ sleep (1.25 )
242+
243+ storeSign ()
244+ print (" NEW ACCOUNT OVERVIEW\n " )
245+ print ("=" * 30 , "\n " )
246+ print (f" Username: { new_username } \n " )
247+ print (f" Address: { new_address .title ()} " )
248+ print (f" Contact #: { new_contact_no } \n " )
249+ print (f" Password: { new_password } \n " )
250+ print ("=" * 30 , "\n \n " )
251+
252+ while True :
253+ confirm_prompt = input ("\033 [1A\033 [K Create Account? [Y/N]: " )
254+
255+ if confirm_prompt .upper () in "YN" and len (confirm_prompt ) == 1 :
256+ break
257+ else :
258+ errorMessage ()
259+
260+ if confirm_prompt in "nN" :
261+ return None
262+
263+ storeSign ()
264+ print (" SUCCESSFULLY CREATED ACCOUNT\n " )
265+ print ("=" * 30 , "\n \n " )
266+
267+ new_account = Account (new_username , new_password , new_address .title (), new_contact_no )
268+
269+ account_list .append ((new_account .username , new_account .password , new_account .address , new_account .contact_no ))
270+
271+ writeAccountStorage (account_list )
272+
273+ while True :
274+ login_prompt = input ("\033 [1A\033 [K Proceed to Log-In? [Y/N]: " )
275+
276+ if login_prompt .upper () in "YN" and len (login_prompt ) == 1 :
277+ break
278+ else :
279+ errorMessage ()
280+
281+ if login_prompt in "yY" :
282+ login ()
283+
284+
285+
286+ def customerList ():
287+ global purchase_list
288+ global account_list
289+
290+ purchase_list = []
291+ purchase_list = readInventoryReport (purchase_list )
292+
293+ account_list = []
294+ account_list = readAccountStorage (account_list )
295+
296+ storeSignAdmin ()
297+ print (" CUSTOMER DATABASE\n " )
298+ print ("=" * 30 )
299+
300+ if len (account_list ) == 0 :
301+ print ("\n WOW SUCH EMPTY\n " )
302+ print ("=" * 30 , "\n " )
303+ else :
304+ for acc in account_list :
305+ products_purchased = 0
306+ total_paid = 0
307+
308+ for purchase in purchase_list :
309+ if purchase [0 ] == acc [0 ]:
310+ products_purchased += purchase [3 ]
311+ total_paid += purchase [4 ]
312+
313+ print (f"\n CUSTOMER # { account_list .index (acc ) + 1 } " )
314+
315+ print (f"Userame: { acc [0 ]} \n " )
316+ print (f"Address: { acc [2 ]} " )
317+ print (f"Contact #: { acc [3 ]} \n " )
318+ print (f"Total Products Purchased: { products_purchased } " )
319+ print (f"Total Amount Paid: PHP { total_paid :.2f} " )
320+
321+ if account_list .index (acc ) != len (account_list ) - 1 :
322+ print ("\n " + "-" * 30 )
323+
324+ print ("\n " + "=" * 30 , "\n " )
325+
326+ system ("pause" )
0 commit comments