-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie.py
90 lines (71 loc) · 2.83 KB
/
cookie.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
from params import param_dict
from datetime import datetime
import datetime as dt
import sqlite3
def user_cookie(cookie):
if cookie == '':
return ''
conn = sqlite3.connect(param_dict['db_file'])
cursor = conn.cursor()
cursor.execute("SELECT login, expires FROM users WHERE cookie=?;", (cookie,))
data = cursor.fetchone()
if data is not None:
if datetime.strptime(str(data[1]).split('.')[0], "%Y-%m-%d %H:%M:%S") > dt.datetime.now():
return str(data[0])
return ''
def token_cookie(cookie):
if cookie == '':
return ''
conn = sqlite3.connect(param_dict['db_file'])
cursor = conn.cursor()
cursor.execute("SELECT token, expires FROM users WHERE cookie=?;", (cookie,))
data = cursor.fetchone()
if data is not None:
if datetime.strptime(str(data[1]).split('.')[0], "%Y-%m-%d %H:%M:%S") > dt.datetime.now():
return str(data[0])
return ''
def tk_pass(token, cookie):
if token == '' or cookie == '':
return ''
conn = sqlite3.connect(param_dict['db_file'])
cursor = conn.cursor()
cursor.execute("SELECT password, cookie, expires FROM users WHERE token=?;", (token,))
data = cursor.fetchone()
if data is not None:
if cookie == str(data[1]) and datetime.strptime(str(data[2].split('.')[0]), "%Y-%m-%d %H:%M:%S") > dt.datetime.now():
return str(data[0])
return ''
def tk_login(token, cookie):
if token == '' or cookie == '':
return ''
conn = sqlite3.connect(param_dict['db_file'])
cursor = conn.cursor()
cursor.execute("SELECT login, cookie, expires FROM users WHERE token=?;", (token,))
data = cursor.fetchone()
if data is not None:
if cookie == str(data[1]) and datetime.strptime(str(data[2]).split('.')[0], "%Y-%m-%d %H:%M:%S") > dt.datetime.now():
return str(data[0])
return ''
def tk_login(token, cookie):
if token == '' or cookie == '':
return ''
conn = sqlite3.connect(param_dict['db_file'])
cursor = conn.cursor()
cursor.execute("SELECT login, cookie, expires FROM users WHERE token=?;", (token,))
data = cursor.fetchone()
if data is not None:
if cookie == str(data[1]) and datetime.strptime(str(data[2]).split('.')[0], "%Y-%m-%d %H:%M:%S") > dt.datetime.now():
return str(data[0])
return ''
def update_cookie(cookie, expires, login):
conn = sqlite3.connect(param_dict['db_file'])
cursor = conn.cursor()
expires = str(expires)
cursor.execute("UPDATE users SET cookie=?, expires=? WHERE login=?;", (cookie, expires, login))
conn.commit()
def disable_cookie(cookie):
conn = sqlite3.connect(param_dict['db_file'])
cursor = conn.cursor()
expires = str(dt.datetime.utcnow())
cursor.execute("UPDATE users SET expires=? WHERE cookie=?;", (expires, cookie))
conn.commit()