This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
85 lines (74 loc) · 2.66 KB
/
controller.py
File metadata and controls
85 lines (74 loc) · 2.66 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
from requests_futures.sessions import *
from model import *
import onetimepass
import redis
from datetime import *
from threading import Timer
class Controller:
__lock = False
date = datetime.now()
list = []
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
def __init__(self):
db.connect(reuse_if_open=True)
Log.create_table()
Card.create_table()
def check_data(self, id, code):
#print(self.__lock)
if self.__lock:
return None, False
if id is 0 and code == "update":
self.__update_data()
return None, True
elif code == "reset":
self.clean()
return None, True
try:
card = Card.get(Card.user == id)
if onetimepass.valid_totp(code, card.code, token_length=8, interval_length=15):
Log.create(card=card.user).save()
return card, True
else:
if onetimepass.valid_totp(code, card.code, token_length=8, interval_length=180):
Log.create(card=card.user).save()
return card, True
else:
return card, False
except DoesNotExist:
#print("NO")
return None, False
def check_name(self, name):
try:
card = Card.get(Card.chineseName == name)
# print(self.r.get(card.get_id()))
if self.r.get(card.get_id()) == '2':
return card, False
self.write_redis(card)
# Log.create(card=card.user).save()
return card, True
except DoesNotExist:
return None, False
def write_redis(self, card):
self.r.set(card.get_id(), "2")
self.r.expire(card.get_id(), 3600)
def clean(self):
self.r.flushall()
def __update_data(self):
try:
session = FuturesSession()
session.post("https://nfls.io/user/card", data={
"action": "fetch",
"key": "2a8d656df6cacdb73aa9e0fd206c240d2a261f67"
}, background_callback=lambda session, response: self.__update_callback(response))
except Exception:
return
def __update_callback(self, response):
users = response.json()["data"]
self.__lock = True
Card.drop_table()
Card.create_table()
for user in users:
card = Card.create(user=user["id"], username=user["username"], englishName=user["englishName"], chineseName=user["chineseName"], className=user["class"], code=user["code"])
card.save()
self.date = datetime.now()
self.__lock = False