-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_engine.py
More file actions
179 lines (142 loc) · 4.84 KB
/
sql_engine.py
File metadata and controls
179 lines (142 loc) · 4.84 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
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
from flask import Flask
from data import db_session
from data.users import User
from data.administrators import Admin
from data.games import Game
from passhash import hash_password
app = Flask(__name__)
app.config['SECRET_KEY'] = 'yandexlyceum_secret_key'
def show_messsage(msg):
print(msg)
def check_login_correct(login):
lenth, spec, busy = False, True, True
for i in login:
if i not in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_":
spec = False
if len(login) >= 3:
lenth = True
db_sess = db_session.create_session()
if login not in [user.login for user in db_sess.query(User).all()]:
busy = False
if all([lenth, spec, not busy]):
return True
else:
show_messsage(f"Login={login} is inc besause: lenth={lenth}, spec={spec}, busy={busy}")
return False
else:
show_messsage("Login={login} is busy")
return False
def check_password_correct(password):
big, small, digits, lenth, spec = False, False, False, False, False
for i in password:
if i.isdigit():
digits = True
if i.upper() == i:
big = True
if i.lower() == i:
small = True
if i in """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""":
spec = True
if len(password) >= 8:
lenth = True
if all([big, small, digits, lenth, spec]):
return True
else:
return False
def check_cmd_amd_name_correct(cmd__adm_name):
lenth, spec = False, False
if len(cmd__adm_name) > 8:
lenth = True
for i in cmd__adm_name:
if i in "!?/.,[]{}():;":
spec = True
if all([lenth, not spec]):
return True
else:
show_messsage(f"Name={cmd__adm_name} is inc because: lenth={lenth}, not spec={not spec}")
return False
def check_cmd_staff_correct(id):
return True
def player_registration(login, password, cmd_name, cmd_info, cmd_staff, achievements=bytes("", "utf8")):
user = User()
if check_login_correct(login):
user.login = login
else:
show_messsage("Логин некорректен")
return False
if check_password_correct(password):
user.password = hash_password(password)
else:
show_messsage("Пароль некорректен")
return False
if check_cmd_amd_name_correct(cmd_name):
user.cmd_name = cmd_name
else:
show_messsage("Имя команды некорректен")
return False
user.cmd_info = cmd_info
if check_cmd_staff_correct(id):
user.cmd_staff = cmd_staff
else:
show_messsage("Cостав команды некорректен")
return False
user.achievements = achievements
db_sess = db_session.create_session()
db_sess.add(user)
db_sess.commit()
return True
def player_authorization(login, password):
db_sess = db_session.create_session()
sp = [user.login for user in db_sess.query(User).all()]
if login in sp:
ind = sp.index(login)
user = db_sess.query(User).filter(User.id == ind + 1).first()
if hash_password(password) == str(user.password):
return True
else:
show_messsage("Неверный пароль")
return False
else:
show_messsage("Неверный логин")
return False
def admin_registration(login, password, amd_name, amd_info):
admin = Admin()
if check_login_correct(login): admin.login = login
else:
show_messsage("Логин некорректен")
return False
if check_password_correct(password): admin.password = hash_password(password)
else:
show_messsage("Пароль некорректен")
return False
if check_cmd_amd_name_correct(amd_name): admin.amd_name = amd_name
else:
show_messsage("Имя админа некорректен")
return False
admin.amd_info = amd_info
db_sess = db_session.create_session()
db_sess.add(admin)
db_sess.commit()
return True
def admin_authorization(login, password):
db_sess = db_session.create_session()
sp = [admin.login for admin in db_sess.query(Admin).all()]
if login in sp:
ind = sp.index(login)
admin = db_sess.query(Admin).filter(Admin.id == ind + 1).first()
if hash_password(password) == str(admin.password):
return True
else:
show_messsage("Неверный пароль")
return False
else:
show_messsage("Неверный логин")
return False
def end_of_session():
db_sess = db_session.create_session()
db_sess.commit()
def main():
db_session.global_init("db/invexgame.db")
app.run()
if __name__ == '__main__':
main()