File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
from tkinter import *
2+
from tkinter import ttk, messagebox
3+
import pymysql
4+
import os
5+
from signup_page import SignUp
6+
import os
7+
8+
import credentials as cr
9+
10+
class login_page:
11+
def __init__(self, root):
12+
self.root = root
13+
self.root.title("Log In E-Health Application")
14+
# Set the window size
15+
# Here 0,0 represents the starting point of the window
16+
self.root.geometry("1280x800+0+0")
17+
self.root.config(bg = "white")
18+
19+
20+
#DESIGN PART
21+
22+
23+
self.frame1 = Frame(self.root, bg="yellow")
24+
self.frame1.place(x=0, y=0, width=450, relheight = 1)
25+
26+
label1 = Label(self.frame1, text= "E-Health Application", font=("times new roman", 27, "bold"), bg="yellow", fg="red").place(x=100,y=300)
27+
#label2 = Label(self.frame1, text= "E-Health Application", font=("times new roman", 25, "bold"), bg="yellow", fg="RoyalBlue1").place(x=162,y=300)
28+
label3 = Label(self.frame1, text= "It's all about hospital recommendation system", font=("times new roman", 13, "bold"), bg="yellow", fg="Blue1").place(x=100,y=360)
29+
30+
#Entry Field & Buttons
31+
32+
self.frame2 = Frame(self.root, bg = "gray95")
33+
self.frame2.place(x=450,y=0,relwidth=1, relheight=1)
34+
35+
self.frame3 = Frame(self.frame2, bg="white")
36+
self.frame3.place(x=140,y=150,width=500,height=450)
37+
38+
self.email_label = Label(self.frame3,text="Email Address", font=("helvetica",20,"bold"),bg="white", fg="gray").place(x=50,y=40)
39+
self.email_entry = Entry(self.frame3,font=("times new roman",15,"bold"),bg="white",fg="gray")
40+
self.email_entry.place(x=50, y=80, width=300)
41+
42+
self.password_label = Label(self.frame3,text="Password", font=("helvetica",20,"bold"),bg="white", fg="gray").place(x=50,y=120)
43+
self.password_entry = Entry(self.frame3,font=("times new roman",15,"bold"),bg="white",fg="gray",show="*")
44+
self.password_entry.place(x=50, y=160, width=300)
45+
46+
#Buttons
47+
self.login_button = Button(self.frame3,text="Log In",command=self.login_func,font=("times new roman",15, "bold"),bd=0,cursor="hand2",bg="blue",fg="white").place(x=50,y=200,width=300)
48+
49+
self.forgotten_pass = Button(self.frame3,text="Forgotten password?",command=self.forgot_func,font=("times new roman",10, "bold"),bd=0,cursor="hand2",bg="white",fg="blue").place(x=125,y=260,width=150)
50+
51+
self.create_button = Button(self.frame3,text="Create New Account",command=self.redirect_window,font=("times new roman",18, "bold"),bd=0,cursor="hand2",bg="green2",fg="white").place(x=80,y=320,width=250)
52+
53+
54+
def login_func(self):
55+
if self.email_entry.get()=="" or self.password_entry.get()=="":
56+
messagebox.showerror("Error!","All fields are required",parent=self.root)
57+
else:
58+
try:
59+
connection=pymysql.connect(host="localhost", user="root", password="chirag123", database="hospitals")
60+
cur = connection.cursor()
61+
cur.execute("select * from user_register where email=%s and password=%s",(self.email_entry.get(),self.password_entry.get()))
62+
row=cur.fetchone()
63+
if row == None:
64+
messagebox.showerror("Error!","Invalid USERNAME & PASSWORD",parent=self.root)
65+
else:
66+
messagebox.showinfo("Success","Wellcome to the PySeek family",parent=self.root)
67+
# Clear all the entries
68+
self.reset_fields()
69+
self.root.destroy()
70+
os.system("main.py")
71+
connection.close()
72+
73+
except Exception as e:
74+
messagebox.showerror("Error!",f"Error due to {str(e)}",parent=self.root)
75+
76+
def forgot_func(self):
77+
if self.email_entry.get()=="":
78+
messagebox.showerror("Error!", "Please enter your Email Id",parent=self.root)
79+
else:
80+
try:
81+
connection = pymysql.connect(host="localhost", user="root", password="chirag123", database="hospitals")
82+
cur = connection.cursor()
83+
cur.execute("select * from user_register where email=%s", self.email_entry.get())
84+
row=cur.fetchone()
85+
if row == None:
86+
messagebox.showerror("Error!", "Email Id doesn't exists")
87+
else:
88+
connection.close()
89+
90+
91+
92+
self.root=Toplevel()
93+
self.root.title("Forget Password?")
94+
self.root.geometry("400x440+450+200")
95+
self.root.config(bg="white")
96+
self.root.focus_force()
97+
self.root.grab_set()
98+
99+
title3 = Label(self.root,text="Change your password",font=("times new roman",20,"bold"),bg="white").place(x=10,y=10)
100+
101+
title4 = Label(self.root,text="It's quick and easy",font=("times new roman",12),bg="white").place(x=10,y=45)
102+
103+
title5 = Label(self.root, text="Select your question", font=("times new roman", 15, "bold"), bg="white").place(x=10,y=85)
104+
105+
self.sec_ques = ttk.Combobox(self.root,font=("times new roman",13),state='readonly',justify=CENTER)
106+
self.sec_ques['values'] = ("Select","What's your pet name?","Your first teacher name","Your birthplace", "Your favorite movie")
107+
self.sec_ques.place(x=10,y=120, width=270)
108+
self.sec_ques.current(0)
109+
110+
title6 = Label(self.root, text="Answer", font=("times new roman", 15, "bold"), bg="white").place(x=10,y=160)
111+
112+
self.ans = Entry(self.root,font=("arial"))
113+
self.ans.place(x=10,y=195,width=270)
114+
115+
title7 = Label(self.root, text="New Password", font=("times new roman", 15, "bold"), bg="white").place(x=10,y=235)
116+
117+
self.new_pass = Entry(self.root,font=("arial"))
118+
self.new_pass.place(x=10,y=270,width=270)
119+
120+
self.create_button = Button(self.root,text="Submit",command=self.change_pass,font=("times new roman",18, "bold"),bd=0,cursor="hand2",bg="green2",fg="white").place(x=95,y=340,width=200)
121+
#=========================================================================
122+
123+
except Exception as e:
124+
messagebox.showerror("Error", f"{e}")
125+
126+
127+
def change_pass(self):
128+
if self.email_entry.get() == "" or self.sec_ques.get() == "Select" or self.new_pass.get() == "":
129+
messagebox.showerror("Error!", "Please fill the all entry field correctly")
130+
else:
131+
try:
132+
connection = pymysql.connect(host="localhost", user="root", password="chirag123", database="hospitals")
133+
cur = connection.cursor()
134+
cur.execute("select * from user_register where email=%s and question=%s and answer=%s", (self.email_entry.get(),self.sec_ques.get(),self.ans.get()))
135+
row=cur.fetchone()
136+
137+
if row == None:
138+
messagebox.showerror("Error!", "Please fill the all entry field correctly")
139+
else:
140+
try:
141+
cur.execute("update user_register set password=%s where email=%s", (self.new_pass.get(),self.email_entry.get()))
142+
connection.commit()
143+
144+
messagebox.showinfo("Successful", "Password has changed successfully")
145+
connection.close()
146+
self.reset_fields()
147+
self.root.destroy()
148+
149+
except Exception as er:
150+
messagebox.showerror("Error!", f"{er}")
151+
152+
except Exception as er:
153+
messagebox.showerror("Error!", f"{er}")
154+
155+
156+
def redirect_window(self):
157+
self.root.destroy()
158+
# Importing the signup window.
159+
# The page must be in the same directory
160+
root = Tk()
161+
obj = SignUp(root)
162+
root.mainloop()
163+
164+
def reset_fields(self):
165+
self.email_entry.delete(0,END)
166+
self.password_entry.delete(0,END)
167+
168+
if __name__ == "__main__":
169+
root = Tk()
170+
obj = login_page(root)
171+
root.mainloop()

0 commit comments

Comments
 (0)