-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
162 lines (128 loc) · 4.72 KB
/
main.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
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
import sys
from PyQt5.uic import loadUi
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
######## Data Base Connection ########
import mysql.connector
########### welcome.ui #########
class WelcomeScreen(QDialog):
def __init__(self):
super(WelcomeScreen, self).__init__()
loadUi("welcome_screen.ui",self)
self.addimage()
self.Signup.clicked.connect(self.signup)
self.Login.clicked.connect(self.login)
def addimage(self):
qp=QPixmap("blur.jpg")
self.label.setPixmap(qp)
def login(self):
user=self.username.text()
pwd=self.password.text()
if len(user)==0 or len(pwd)==0:
self.error.setText("Incorrect credentials")
else:
try:
# connecting to DB and validating the Uname and pwd
mydb = mysql.connector.connect(
host='localhost',
user='Mysql user',
passwd='Enter Your password',
port='Your default port',
database='test')
cur=mydb.cursor()
cur.execute('SELECT * from account_details where Username=%s and Password=%s'
,(user,pwd))
if cur.fetchone():
self.error.setText("successfull")
obj = DashBoard()
widget.addWidget(obj)
widget.setCurrentIndex(widget.currentIndex() + 1)
else:
self.error.setText("Incorrect credentials or Pwd")
except Exception as es:
print("Error")
def signup(self):
obj = SignUp()
widget.addWidget(obj)
widget.setCurrentIndex(widget.currentIndex() + 1)
########### Dashboard.ui #########
class DashBoard(QDialog):
def __init__(self):
super(DashBoard, self).__init__()
loadUi("DashBoard.ui",self)
self.addimage()
self.Exit.clicked.connect(self.exit)
def addimage(self):
qp = QPixmap("blur.jpg")
self.label.setPixmap(qp)
def exit(self):
obj=WelcomeScreen()
widget.addWidget(obj)
widget.setCurrentIndex(widget.currentIndex()+1)
########### signup.ui #########
class SignUp(QDialog):
def __init__(self):
super(SignUp, self).__init__()
loadUi("Sign_Up.ui", self)
self.addimage()
self.Signup_2.clicked.connect(self.goback)
self.Signup.clicked.connect(self.signup)
def addimage(self):
qp = QPixmap("blur.jpg")
self.label.setPixmap(qp)
def goback(self):
obj=WelcomeScreen()
widget.addWidget(obj)
widget.setCurrentIndex(widget.currentIndex()+1)
def signup(self):
name = self.name.text()
Phnum = self.phnum.text()
pwd = self.password.text()
user = self.username.text()
confirmpwd = self.confirmPassword.text()
if (len(name) and len(Phnum) and len(pwd) and len(user)
and len(confirmpwd)) == 0:
self.error.setText("Please fill all Credentials")
else:
if pwd == confirmpwd:
try:
mydb = mysql.connector.connect(
host='localhost',
user='root',
passwd='kumar',
port='3306',
database='test')
cur = mydb.cursor()
id_query="SELECT max(id) from test.account_details"
cur.execute(id_query)
R=cur.fetchone()
if R!=None and R[0]!=None:
id=int(R[0])+1
cur = mydb.cursor()
sql="insert into test.account_details(id,Name,PhNum,Username,Password) values(%s, %s, %s, %s, %s)"
cur.execute(sql,(id,name,Phnum,user,pwd))
mydb.commit()
if cur.fetchone():
self.error.setText("ERROR")
else:
self.error.setText("Sign Up Successfull ")
self.error.setStyleSheet("color:green")
self.error.setFont(QFont('MS Shell Dlg 2', 14))
except Exception as es:
print("error")
self.error.setText("ERROR ")
else:
self.error.setText("Passwords don't match")
########### MAIN CODE #########
#The code below are mandatory to launch the PyQt APP
app = QApplication(sys.argv)
welcome= WelcomeScreen()
widget = QStackedWidget()
widget.addWidget(welcome)
widget.setFixedHeight(875)
widget.setFixedWidth(1125)
widget.show()
try:
sys.exit((app.exec()))
except:
print("exiting")