-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts.py
133 lines (106 loc) · 3.51 KB
/
scripts.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
from database import curs, conn
import os
def checkForExistence(username, password):
curs.execute("""
SELECT login FROM logins where login = '{}'
""".format(str(username)))
data = curs.fetchall()
print(data)
if len(data) > 0:
# pass_check проверка пароля
if checkPassword(password, username):
return True
else:
return False
else:
return False
def checkPassword(password, username):
curs.execute("""
SELECT password FROM logins WHERE login = '{}'
""".format(str(username)))
chk_password = curs.fetchall()
if len(chk_password) > 0:
if str(chk_password[0][0]) == str(password):
return True
else:
return False
def checkPermeation(username):
curs.execute("""
SELECT permeation FROM logins where login = '{}'
""".format(username))
perm = curs.fetchall()
# Проверка на админа
if len(perm) > 0:
# Распаршиваю кортеж чтоб выудить бул значение
if perm[0][0]:
return True
# Если админ - возвращаем тру
else:
return False
def getPerm(username):
curs.execute("""
SELECT permeation FROM logins where login = '{}'
""".format(username))
perm = curs.fetchall()
if len(perm) > 0:
return perm[0][0]
else:
return None
# ------------------------------------------------------------------------------------------------
# user side. Admin side upper
def uniqueLogin(username):
curs.execute("""
SELECT login FROM logins where login = '{}'
""".format(username))
copy = len(curs.fetchall())
print(str(copy) + " IS COPY")
if copy > 0:
return False
else:
return True
def checkPassAndCpPass(password, cppass):
if password == cppass:
return True
else:
return False
def createNewUser(username, password):
curs.execute("""
INSERT INTO logins VALUES ('{}', '{}', '{}')
""".format(username, password, False))
conn.commit()
# ------------------------------------------------------------------------------------------------
# bot sending secure md5 token (key)
def createQuery(username):
curs.execute("""
UPDATE logins SET requiretoken = True WHERE login = '{}' and permeation = '{}'
""".format(username, True))
conn.commit()
def checkForToken(token, username):
curs.execute("""
SELECT admintoken FROM privatetokens WHERE telegram_id = (SELECT logins.telegram_id FROM logins where requiretoken = True)
""")
token_ = curs.fetchall()
print(token_[0][0])
if len(token_) > 0:
if str(token) == str(token_[0][0]):
curs.execute("""
UPDATE logins SET requiretoken = False WHERE login = '{}' and permeation = '{}'
""".format(username, True))
return True
else:
return False
# ------------------------------------------------------------------------------------------------
# hardcoding time...
# server be like c:/../besthack2020finals/storage
def getTicketsAmount():
curs.execute("""
SELECT amount FROM tickets_amount
""")
amount = curs.fetchall()
return str(amount[0][0])
def allDataFromTickets():
curs.execute("""
SELECT * FROM tickets_info
""")
ticketInfo = curs.fetchall()
return ticketInfo