-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserApp.py
More file actions
145 lines (116 loc) · 4.25 KB
/
Copy pathUserApp.py
File metadata and controls
145 lines (116 loc) · 4.25 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
import json
import validators
def user_login(json_object):
while True:
username = input('Введите ваш логин: ')
flag = 0
for i in json_object['users']:
if username == i['name']:
flag = 1
if flag:
print('Такой Логин уже существует.')
continue
else:
break
return username
def user_email(json_object):
while True:
email = input('Введите ваш email: ')
flag = 0
if validators.email(email, whitelist = None):
for i in json_object['users']:
if email == i['email']:
flag = 1
if flag:
print('Такой EMAIL уже есть.')
continue
else:
break
else:
print('Неправильный формат EMAIL.')
continue
return email
def password_user():
letters = set('qwertyuiopasdfghjklzxcvbnmйцукенгшщзхъфывапролджэячсмитьбю')
numbers = set('1234567890')
while True:
password = input('Введите ПАРОЛЬ >= 12 символов,'
'не менее 1 цифры, 1 большой буквы, 1 малой буквы: ')
if len(password) < 12:
print("Пароль должен быть 12 или более символов.")
continue
if len(letters.intersection(set(password))) == 0:
print('Должно быть не менее одной малой буквы.')
continue
if len(numbers.intersection(set(password))) == 0:
print('Должно быть не менее одной цифры.')
continue
if len(set(password).intersection(set(str(letters).upper()))) == 0:
print('Должна быть хоть одна большая буква.')
continue
break
return password
def register_user(json_obj):
login = user_login(json_obj)
email = user_email(json_obj)
password = password_user()
user = {'name' : login,
'email' : email,
'password' : password}
json_obj['users'].append(user)
with open('data.json', 'w') as outfile:
json.dump(json_obj, outfile, indent=2)
def login(json_obj):
usname = input('Введите Ваш логин: ')
count = 0
for i in json_obj['users']:
if i['name'] == usname:
while True:
password = input('Введите пароль: ')
if i['password'] == password:
logout = True
sp_inf = [logout, count]
return sp_inf
else:
print('Неверный пароль.')
continue
else:
count += 1
else:
print('Данного пользователя нет.')
logout = False
sp_inf = [logout, None]
return sp_inf
def start():
with open('data.json', 'r') as infile:
json_obj = json.load(infile)
vv = input("Если вы хотите зарегистрироваться - 'Y', \n"
"Если зарегистрированы и хотите войти - 'N': " )
if vv.lower() == 'y':
register_user(json_obj)
elif vv.lower() == 'n':
us_inf = login(json_obj)
if us_inf[0] == True:
qwest = input("Вы хотите удалить свою учетную запись? - 'y', \n"
"Вы хотите выйти из учетной записи? - 'n': ")
if qwest.lower() == 'y':
us_inf[0] = False
json_obj['users'].pop(us_inf[1])
with open('data.json', 'w') as outfile:
json.dump(json_obj, outfile, indent= 2)
start()
else:
print('До новых встреч.')
start()
# anton = {'name' : 'Anton',
# 'email' : 'adizen52@uandex,ru',
# 'password' : 'qwerty123'}
#
# data = {}
#
# data['users'] = []
#
# data['users'].append(anton)
#
# with open('data.json', 'w') as outfile:
# json.dump(data, outfile, indent=2)