-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods.py
255 lines (195 loc) · 8.18 KB
/
methods.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
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
import json
users = {}
with open('usersdata.json') as usersdata:
users = json.load(usersdata)
emailtypes = ["gmail.com", "email.com", "outlook.com", "mail.ru"]
def white():
print(f"\033[38;2;{255};{255};{255}m")
def red():
print(f"\033[38;2;{255};{0};{0}m")
def yellow():
print(f"\033[38;2;{255};{255};{0}m")
def green():
print(f"\033[38;2;{0};{255};{0}m")
def cancel(x):
x = x.lower()
if x == "cancel":
return exit(0)
def br():
print("\n")
class LogIn:
def email(cancel, users, white, red, yellow, green):
gm = input("Email: ").lower()
cancel(gm)
gmExist = True if gm in users.keys() else False
while not gmExist:
red()
print("\nWrong email")
white()
gm = input("Please enter correct email \n>>> ").lower()
cancel(gm)
if gm in users.keys():
gmExist = True
return gm
def password(cancel, users, gm, white, red, yellow, green):
psw = input("\nPassword: ")
cancel(psw)
isPsw = True if users[gm][3] == psw else False
while not isPsw:
red()
print("\nWrong password")
white()
psw = input("Please enter correct password \n>>> ")
cancel(psw)
if users[gm][3] == psw:
isPsw = True
green()
print(f"\nHi, {users[gm][0].title()}!")
print("\nThese are your infos")
white()
print(f"First Name: {users[gm][0].title()} \nLast Name: {users[gm][1].title()} \nPhone Number: {users[gm][2]} \nEmail: {gm.lower()} \nPassword: {users[gm][3]}")
class SignUp:
def fname(cancel, white, red, yellow, green):
fName = input("\nFirst Name: ")
isFname = True if 65 <= ord(fName[0]) <= 90 else False
while not isFname:
yellow()
print("\nFirst Letter of First Name should be upppercase letter")
white()
fName = input("First Name: ")
isFname = True if 65 <= ord(fName[0]) <= 90 else False
return fName
def lname(cancel, white, red, yellow, green):
lName = input("\nLast Name: ")
isLname = True if 65 <= ord(lName[0]) <= 90 else False
while not isLname:
yellow()
print("\nFirst Letter of Last Name should be upppercase letter")
white()
lName = input("Last Name: ")
isLname = True if 65 <= ord(lName[0]) <= 90 else False
return lName
def number(cancel, white, red, yellow, green):
telNumber = input("\nPhone Number (do not include + sign): ")
cancel(telNumber)
isTelNumber = True if telNumber.isdigit() else False
while not isTelNumber:
yellow()
telNumber = input("\nPlease enter correct Phone Number \n >>> ")
white()
cancel(telNumber)
isTelNumber = True if telNumber.isdigit() else False
return telNumber
def email(cancel, users, emailtypes, white, red, yellow, green):
email = input("\nEmail: ")
cancel(email)
isEmail = False
alreadyHas = True if email in users.keys() else False
signs = ["`", "-", "=", "[", "]", ";", "'", ",", "/", "~", "!", "#", "$", "%", "^", "&", "*", "(", ")", "+", "{", "}", "|", ":", '"', "<", ">", "?"]
while not isEmail:
for i in signs:
if i in email:
red()
print(f"\nEmail should not include signs like {i}")
white()
email = input("Please enter correct email \n >>> ")
cancel(email)
alreadyHas = True if email in users.keys() else False
continue
if alreadyHas:
red()
print("\nAccount with this email has already existed")
white()
elif not (email.isascii()):
red()
print("\nEmail should be in Latin letters")
white()
email = input("Please enter correct email \n >>> ")
cancel(email)
alreadyHas = True if email in users.keys() else False
elif "@" in email:
indSign = email.index("@")
emailtype = email[indSign+1::]
if emailtype in emailtypes:
isEmail = True
else:
red()
print("\nThere is an error after @")
white()
email = input("Please enter correct email \n >>> ")
cancel(email)
alreadyHas = True if email in users.keys() else False
else:
red()
print("\nEmail must have sign of @")
white()
email = input("Please enter correct email \n >>> ")
cancel(email)
alreadyHas = True if email in users.keys() else False
return email
def psw(cancel, white, red, yellow, green):
password = input("\nPassword: ")
cancel(password)
signs = ["`", "-", "=", "[", "]", ";", "'", ",", ".", "/", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "{", "}", "|", ":", '"', "<", ">", "?"]
isLong = True if len(password) >= 8 else False
hasUpper = False
hasLower = False
hasNumber = False
hasSign = False
hasEmpty = False if " " in password else True
for i in password:
if 48 <= ord(i) <= 57:
hasNumber = True
elif 65 <= ord(i) <= 90:
hasUpper = True
elif 97 <= ord(i) <= 122:
hasLower = True
elif i in signs:
hasSign = True
isPassword = True if isLong == True and hasUpper == True and hasLower == True and hasNumber == True and hasSign == True else False
a = [isLong, hasUpper, hasLower, hasNumber, hasSign, hasEmpty]
info = ["be 8 characters", "has one uppercase letter", "has one lowercase letter", "has number", "include one of these signs {~,!,`,@,#,$,%,^,&,*,(,),{,},_,-,=,+,\,|,[,],?,/,<,>,;,:,'}", "not be empty space"]
while not isPassword:
yellow()
print("\nPassword must: ")
for e in range(len(a)):
if not a[e]:
print(f"* {info[e]} at least")
red()
password = input("\nPlease enter valid password \n >>> ")
white()
cancel(password)
hasEmpty = False if " " in password else True
isLong = True if len(password) >= 8 else False
for i in password:
if 48 <= ord(i) <= 57:
hasNumber = True
elif 65 <= ord(i) <= 90:
hasUpper = True
elif 97 <= ord(i) <= 122:
hasLower = True
elif i in signs:
hasSign = True
a = [isLong, hasUpper, hasLower, hasNumber, hasSign, hasEmpty]
isPassword = True if isLong == True and hasUpper == True and hasLower == True and hasNumber == True and hasSign == True and hasEmpty == True else False
return password
def repws(cancel, users, password, telNumber, email, fName, lName, white, red, yellow, green):
repassword = input("\nRetype Password: ")
cancel(repassword)
isRetypePassword = True if repassword == password else False
while not isRetypePassword:
red()
print("\nRetype password must match password")
white()
repassword = input("Please enter correct Retype Password \n >>> ")
cancel(repassword)
isRetypePassword = True if repassword == password else False
email = email.lower()
fName = fName.lower()
lName = lName.lower()
users[email] = [fName, lName, telNumber, password]
with open('usersdata.json', 'w') as usersdata:
json.dump(users, usersdata)
green()
print("Signed up Successfully!!!")
white()