-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountSystem.py
More file actions
388 lines (310 loc) · 18 KB
/
Copy pathAccountSystem.py
File metadata and controls
388 lines (310 loc) · 18 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
from tkinter import *
from PIL import ImageTk, Image, ImageDraw
from tkinter import messagebox
import sqlite3
import Guest
import Employee
import admin
import Dashboard
import admin_start
class AccountPage:
def __init__(self, AccountSystem_window):
self.AccountSystem_window = AccountSystem_window
# Window Size and Placement
AccountSystem_window.rowconfigure(0, weight=1)
AccountSystem_window.columnconfigure(0, weight=1)
height = 650
width = 700
x = (AccountSystem_window.winfo_screenwidth()//2)-(width//2)
y = (AccountSystem_window.winfo_screenheight()//4)-(height//4)
AccountSystem_window.geometry('{}x{}+{}+{}'.format(width, height, x, y))
AccountSystem_window.resizable(0, 0)
# window Icon
icon = PhotoImage(file='images\\replace_this.png')
AccountSystem_window.iconphoto(True, icon)
AccountSystem_window.title('Login')
# Navigating through windows
sign_up = Frame(AccountSystem_window)
sign_in = Frame(AccountSystem_window)
landing_page = Frame(AccountSystem_window)
for frame in (landing_page, sign_in, sign_up):
frame.grid(row=0, column=0, sticky='nsew')
def show_frame(frame):
frame.tkraise()
show_frame(sign_in)
landing_page.config(background='#ffffff')
# Label
heading_label = Label(landing_page, text="To Continue,\n Please Login or Create New Account", font=("", 13, "bold"),
bg='#ffffff')
heading_label.place(x=370, y=200)
# Login Button
login_button = Button(landing_page, text='Login', bg='#fd6a36', font=("", 13, "bold"), bd=0, fg='white',
cursor='hand2', activebackground='#fd6a36', activeforeground='white',
command=lambda: show_frame(sign_in))
login_button.place(x=490, y=300)
# Sign Up Button
signUp_button = Button(landing_page, text='Create New Account', bg='#fd6a36', font=("", 13, "bold"), bd=0, fg='white',
cursor='hand2', activebackground='#fd6a36', activeforeground='white',
command=lambda: show_frame(sign_up))
signUp_button.place(x=440, y=350)
def open_guest():
win = Toplevel()
Guest.GuestPage(win)
AccountSystem_window.withdraw()
win.deiconify()
def open_employee():
win = Toplevel()
Dashboard.FirstPage(win)
AccountSystem_window.withdraw()
win.deiconify()
def open_admin():
win = Toplevel()
admin_start.FirstPage(win)
AccountSystem_window.withdraw()
win.deiconify()
# ==========================================================================================================
# ================================ SIGN IN PAGE ============================================================
# ==========================================================================================================
sign_in.config(background='#ffffff')
# ====== LOGO ==========
# logoIcon = Image.open('images\\CoffeeShop-brand-logo.png')
# photo = ImageTk.PhotoImage(logoIcon)
# logo = Label(sign_in, image=photo, bg='#ffffff')
# logo.image = photo
# logo.place(x=20, y=45)
# brand_name = Label(sign_in, text='CHILL DRINK SHOP', bg='#ffffff', fg='#ff6c38', font=("", 15, "bold"))
# brand_name.place(x=90, y=60)
# text = Label(sign_in, text="FDA APPROVED", bg='#ffffff', font=("", 12, "bold"))
# text.place(x=20, y=140)
# txt2 = "• We produce hygienic and healthy coffee \nby all standards\t\t\t \n\n• Very Affordable and best Coffee in " \
# "town \nfor the past two and half years\t"
# text2 = Label(sign_in, text=txt2,
# fg="#6b6a69", bg='#ffffff', font=("", 11, "bold"))
# text2.place(x=20, y=180)
# ====== LOGO ==========
# coffeeImage = Image.open('images\\coffee3.gif')
# photo = ImageTk.PhotoImage(coffeeImage)
# coffee_image = Label(sign_in, image=photo, bg='#ffffff')
# coffee_image.image = photo
# coffee_image.place(x=30, y=370)
# pageDivide_line = Canvas(sign_in, width=1.5, height=900, bg="#e6e6e6", highlightthickness=0)
# pageDivide_line.place(x=350, y=0)
heading = Label(sign_in, text="Login", font=("", 16, "bold"), bg='#ffffff')
heading.place(x=600/2, y=100)
Username = StringVar()
Password = StringVar()
def login_all():
# Admin
conn = sqlite3.connect("./Database/CoffeeShop.db")
cursor = conn.cursor()
find_user1 = 'SELECT * FROM Admin_Account WHERE admin_username = ? and admin_password = ?'
cursor.execute(find_user1, [(username_entry.get()), (password_entry.get())])
result = cursor.fetchall()
if result:
messagebox.showinfo("Success", 'Logged in Successfully,\n\nClick "OK" to continue.')
open_admin()
else:
messagebox.showerror("Failed", "Wrong Login details, please try again.")
username_label = Label(sign_in, text='Username', fg="#27221c", bg='#ffffff', font=("", 12, "bold"))
username_label.place(x=380/2, y=150)
username_entry = Entry(sign_in, highlightthickness=2, relief=FLAT, bg="#fafafa", fg="#6b6a69",
font=("", 12, 'bold'), textvariable=Username)
username_entry.place(x=380/2, y=182, width=290, height=34)
username_entry.config(highlightbackground="#6b6a69", highlightcolor="black")
password_label = Label(sign_in, text='Password', fg="#27221c", bg='#ffffff', font=("", 12, "bold"))
password_label.place(x=380/2, y=250)
password_entry = Entry(sign_in, highlightthickness=2, relief=FLAT, bg="#fafafa", fg="#6b6a69", font=("", 12), show="•",
textvariable=Password)
password_entry.place(x=380/2, y=282, width=290, height=34)
password_entry.config(highlightbackground="#6b6a69", highlightcolor="black")
loginButton = Button(sign_in, fg='#f8f8f8', text='Login', bg='#036553', font=("", 12, "bold"),
cursor='hand2', activebackground='#036553', command=login_all)
loginButton.place(x=380/2, y=370, width=290, height=40)
# line = Canvas(sign_in, width=286, height=1.5, bg="#e6e6e6", highlightthickness=0)
# line.place(x=380/2, y=440)
# label = Label(sign_in, text='No Account Yet', bg='#ffffff')
# label.place(x=580/2, y=430)
# createButton = Button(sign_in, fg='#f8f8f8', text='Create New Account', bg='#4286f5', font=("", 12, "bold"),
# cursor='hand2', activebackground='#4286f5', command=lambda: show_frame(sign_up))
# createButton.place(x=380/2, y=470, width=290, height=40)
# function for show and hide password
def password_command():
if password_entry.cget('show') == "•":
password_entry.config(show="")
else:
password_entry.config(show="•")
# Check Button
show_password = Checkbutton(sign_in, text="Show password", bg='#ffffff', fg='#27221c', command=password_command)
show_password.place(x=380/2, y=332)
def forgot_password():
win = Toplevel()
window_width = 350
window_height = 350
screen_width = win.winfo_screenwidth()
screen_height = win.winfo_screenheight()
position_top = int(screen_height / 4 - window_height / 4)
position_right = int(screen_width / 2 - window_width / 2)
win.geometry(f'{window_width}x{window_height}+{position_right}+{position_top}')
win.title('Forgot Password')
# win.iconbitmap('images\\aa.ico')
win.configure(background='#f8f8f8')
win.resizable(0, 0)
# Variables
username = StringVar()
password = StringVar()
confirmPassword = StringVar()
# ====== Email ====================
username_entry3 = Entry(win, fg="#a7a7a7", font=("yu gothic ui semibold", 12), highlightthickness=2,
textvariable=username)
username_entry3.place(x=40, y=30, width=256, height=34)
username_entry3.config(highlightbackground="black", highlightcolor="black")
username_label3 = Label(win, text='• Username', fg="#89898b", bg='#f8f8f8',
font=("yu gothic ui", 11, 'bold'))
username_label2.place(x=40, y=0)
# ==== New Password ==================
new_password_entry = Entry(win, fg="#a7a7a7", font=("yu gothic ui semibold", 12), show='•', highlightthickness=2,
textvariable=password)
new_password_entry.place(x=40, y=110, width=256, height=34)
new_password_entry.config(highlightbackground="black", highlightcolor="black")
new_password_label = Label(win, text='• New Password', fg="#89898b", bg='#f8f8f8',
font=("yu gothic ui", 11, 'bold'))
new_password_label.place(x=40, y=80)
# ==== Confirm Password ==================
confirm_password_entry = Entry(win, fg="#a7a7a7", font=("yu gothic ui semibold", 12), show='•', highlightthickness=2
, textvariable=confirmPassword)
confirm_password_entry.place(x=40, y=190, width=256, height=34)
confirm_password_entry.config(highlightbackground="black", highlightcolor="black")
confirm_password_label = Label(win, text='• Confirm Password', fg="#89898b", bg='#f8f8f8',
font=("yu gothic ui", 11, 'bold'))
confirm_password_label.place(x=40, y=160)
# ======= Update password Button ============
update_pass = Button(win, fg='#f8f8f8', text='Update Password', bg='#ff6c38', font=("", 12, "bold"),
cursor='hand2', activebackground='#ff6c38', command=lambda: change_password())
update_pass.place(x=40, y=240, width=256, height=50)
# ========= DATABASE CONNECTION FOR FORGOT PASSWORD=====================
def change_password():
db = sqlite3.connect("./Database/CoffeeShop.db")
cur = db.cursor()
#insert = '''update Guest_Account set guest_password=? where guest_username=? '''
#cur.execute(insert, [new_password_entry.get(), username_entry3.get(), ])
#db.commit()
#db.close()
#messagebox.showinfo('Congrats', 'Password changed successfully')
# forgotPassword = Button(sign_in, text='Forgot password', font=("", 10, "bold"), bg='#ffffff', fg='#4286f5',
# borderwidth=0, activebackground='#f8f8f8', command=lambda: forgot_password(), cursor="hand2")
# forgotPassword.place(x=600/2, y=332)
# =============================================================================================================
# ================================ SIGN UP PAGE ===============================================================
# =============================================================================================================
sign_up.config(background='#ffffff')
# ====== LOGO ==========
# logoIcon = Image.open('images\\CoffeeShop-brand-logo.png')
# photo = ImageTk.PhotoImage(logoIcon)
# logo = Label(sign_up, image=photo, bg='#ffffff')
# logo.image = photo
# logo.place(x=20, y=45)
# brand_name = Label(sign_up, text='CHILL DRINK SHOP', bg='#ffffff', fg='#ff6c38', font=("", 15, "bold"))
# brand_name.place(x=90, y=60)
# text = Label(sign_up, text="FDA APPROVED", bg='#ffffff', font=("", 12, "bold"))
# text.place(x=20, y=140)
# txt3 = "• We produce hygienic and healthy coffee \nby all standards\t\t\t \n\n• Very Affordable and best Coffee in " \
# "town \nfor the past two and half years\t"
# text2 = Label(sign_up, text=txt3,
# fg="#6b6a69", bg='#ffffff', font=("", 11, "bold"))
# text2.place(x=20, y=180)
# ====== LOGO ==========
# coffeeImage = Image.open('images\\coffee3.gif')
# photo = ImageTk.PhotoImage(coffeeImage)
# coffee_image = Label(sign_up, image=photo, bg='#ffffff')
# coffee_image.image = photo
# coffee_image.place(x=30, y=370)
# pageDivide_line = Canvas(sign_up, width=1.5, height=900, bg="#e6e6e6", highlightthickness=0)
# pageDivide_line.place(x=350, y=0)
heading = Label(sign_up, text="Create New Account", font=("", 16, "bold"), bg='#ffffff')
heading.place(x=220, y=50)
FullName = StringVar()
Username2 = StringVar()
Password2 = StringVar()
def signup_all():
check_counter = 0
warn = ""
if fullname_entry.get() == "":
warn = "Please enter your full name"
else:
check_counter += 1
if username_entry2.get() == "":
warn = "Please enter your username"
else:
check_counter += 1
if password_entry2.get() == "":
warn = "Please make sure your PASSWORD, USERNAME AND FULLNAME Fields are not empty"
else:
check_counter += 1
if check_counter == 3:
try:
connection = sqlite3.connect("./Database/CoffeeShop.db")
cur = connection.cursor()
cur.execute("INSERT INTO Guest_Account(guest_fullname, guest_username, guest_password) VALUES(?,?,?)",
(FullName.get(), Username2.get(), Password2.get()))
connection.commit()
connection.close()
messagebox.showinfo("Success", 'New account created successfully\n\nClick "OK" to continue')
open_guest()
except Exception as ep:
messagebox.showerror('', ep)
else:
messagebox.showerror('Error', warn)
# ========================================================================
# ============================Full name====================================
# ========================================================================
fullname_label = Label(sign_up, text='Fullname', fg="#27221c", bg='#ffffff', font=("", 12, "bold"))
fullname_label.place(x=380/2, y=80)
fullname_entry = Entry(sign_up, highlightthickness=2, relief=FLAT, bg="#fafafa", fg="#6b6a69",
font=("", 12, 'bold'), textvariable=FullName)
fullname_entry.place(x=380/2, y=112, width=290, height=34)
fullname_entry.config(highlightbackground="#6b6a69", highlightcolor="black")
# ========================================================================
# ============================Username====================================
# ========================================================================
username_label2 = Label(sign_up, text='Username', fg="#27221c", bg='#ffffff', font=("", 12, "bold"))
username_label2.place(x=380/2, y=165)
username_entry2 = Entry(sign_up, highlightthickness=2, relief=FLAT, bg="#fafafa", fg="#6b6a69",
font=("", 12, 'bold'), textvariable=Username2)
username_entry2.place(x=380/2, y=197, width=290, height=34)
username_entry2.config(highlightbackground="#6b6a69", highlightcolor="black")
# ========================================================================
# ============================Password====================================
# ========================================================================
password_label2 = Label(sign_up, text='Password', fg="#27221c", bg='#ffffff', font=("", 12, "bold"))
password_label2.place(x=380/2, y=250)
password_entry2 = Entry(sign_up, highlightthickness=2, relief=FLAT, bg="#fafafa", fg="#6b6a69", font=("", 12), show='•',
textvariable=Password2)
password_entry2.place(x=380/2, y=282, width=290, height=34)
password_entry2.config(highlightbackground="#6b6a69", highlightcolor="black")
signupButton = Button(sign_up, fg='#f8f8f8', text='Create Account', bg='#036553', font=("", 12, "bold"),
cursor='hand2', activebackground='#036553', command=signup_all)
signupButton.place(x=380/2, y=370, width=290, height=40)
line = Canvas(sign_up, width=286, height=1.5, bg="#e6e6e6", highlightthickness=0)
line.place(x=380/2, y=440)
label = Label(sign_up, text='Already have account', bg='#ffffff')
label.place(x=540/2, y=430)
sign_inButton = Button(sign_up, fg='#f8f8f8', text='Login', bg='#4286f5', font=("", 12, "bold"),
cursor='hand2', activebackground='#4286f5', command=lambda: show_frame(sign_in))
sign_inButton.place(x=380/2, y=470, width=290, height=40)
# function for show and hide password
def password_command2():
if password_entry2.cget('show') == '•':
password_entry2.config(show='')
else:
password_entry2.config(show='•')
# Check Button
show_password2 = Checkbutton(sign_up, text="Show password", bg='#ffffff', fg='#27221c',
command=password_command2)
show_password2.place(x=380/2, y=332)
#AccountSystem_window.mainloop()
def page():
window = Tk()
AccountPage(window)
window.mainloop()
if __name__ == '__main__':
page()