-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttonFunction.py
151 lines (131 loc) · 5.76 KB
/
buttonFunction.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
# Given a particular button and page, this will give instruction on what to do once the button is pressed
from variableValues import login_tries
from Queries import signUpQueries
def mainPageButton(window):
window.destroy()
import userWrapper
def userWrapperSignInButton(window):
window.destroy()
import login
def userWrapperSignUpButton(window):
window.destroy()
import signUp
def loginButton(window):
"""
When the user inputs username and password, the username and password is stored and the tab is closed
"""
if login_tries == 0:
window.destroy()
messagebox.showinfo(
'Login In', 'Too many incorrect tries, Reset Password')
import forgotPassword
else:
if txtusername.get() in lstusernames:
indexofusername = lstusernames.index(txtusername.get())
passwordatindex = lstpasswords[indexofusername]
if txtpassword.get() == passwordatindex:
login_tries = -1
messagebox.showinfo('Login In', 'Login successful')
window.destroy()
import connectToDatabase
else:
login_tries -= 1
messagebox.showinfo(
'Login In', f'Incorrect password, tries left {login_tries}')
login
else:
messagebox.showinfo(
'Login In', 'Account does not exist with this username')
def signUpButton(window):
if txtfullname.get not in lstfullname:
if (
(not txtfullname.get() == "") and
(not txtusername.get() == "") and
(not txtsecuritykey.get() == "") and
(not txtphoneno.get() == "") and
(not txtpassword.get() == "") and
(not txtconfirmpassword.get() == "")
):
if (txtpassword.get() == txtconfirmpassword.get()):
if (txtusername.get() not in lstusernames):
signUpQueries()
window.destroy()
import login
elif txtusername.get() in lstusernames:
messagebox.showinfo('Sign Up', 'Username already in use')
else:
messagebox.showinfo('Sign Up', 'Passwords do not match')
else:
messagebox.showinfo('Sign Up', 'Fields cannot be left blank')
elif txtfullname.get() in lstfullname:
res = messagebox.askyesno(
'Sign Up', 'Account already exists, want to login?')
if res == 'True':
window.destroy()
import login
def locationFinderButton(window):
"""
When the user inputs location, the location is stored and the tab is closed
"""
user_location = location_user.get()
user_location = str(user_location).capitalize()
if user_location == "":
pass
else:
get_weather(user_location)
def sendOTPButton(window):
if (
(txtaskusernamereset.get() == "") or
(txtasksecuritykeyreset.get() == "")
):
messagebox.showinfo('Reset Password', 'Fields cannot be left blank')
elif (txtaskusernamereset.get() not in lstusernamesreset):
messagebox.showinfo('Reset Password', 'Incorrect username')
else:
# getting the security key of the username that was stored previously
indexofusername = lstusernamesreset.index(txtaskusernamereset.get())
global storedsecuritykey
storedsecuritykey = lstsecuritykeyreset[indexofusername]
# getting the stored password for use in resetpage
global oldpassword
oldpassword = lstpasswordsreset[indexofusername]
accountsid = 'AC6d502dd14d7cf89e864d81d15e55b2d1'
authtoken = 'c76df270ca3c94af92562587306b03fe'
client = Client(accountsid, authtoken)
global x
x = random.randint(1000, 9999)
# getting the phone number of the registered user
phonenoregistered = lstphonenoreset[indexofusername]
message = client.messages.create(
body=x, from_='+17174290730', to=f'+{phonenoregistered}')
messagebox.showinfo(
'Reset Password', 'OTP has been sent to the registered mobile number')
def resetPasswordButton(window):
if txtaskusernamereset.get() == '' or txtasksecuritykeyreset == '' or txtaskotp.get() == '' or txtresetpass1.get() == '' or txtresetpass1confirm.get() == '':
messagebox.showinfo('Reset Password', 'Fields cannot be left blank')
else:
if txtaskusernamereset.get() not in lstusernamesreset:
messagebox.showinfo('Reset Password', 'Incorrect username')
else:
if storedsecuritykey == txtasksecuritykeyreset.get():
if str(x) == txtaskotp.get():
if txtresetpass1.get() == txtresetpass1confirm.get():
if txtresetpass1.get() != oldpassword:
sql = f'UPDATE nameandpass SET Password = "{txtresetpass1.get()}" where Username = "{txtaskusernamereset.get()}";'
mycursor.execute(sql)
mydb.commit()
messagebox.showinfo(
'Reset Password', 'Password updated successfully')
import connectToDatabase
window.destroy()
else:
messagebox.showinfo(
'Reset Password', 'Cannot use old password')
else:
messagebox.showinfo(
'Reset Password', 'Passwords do not match')
else:
messagebox.showinfo(
'Reset Password', 'Incorrect otp entered')
else:
messagebox.showinfo('Reset Password', 'Incorrect security key')