52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
from geruecht.model.accessToken import AccessToken
|
|
from datetime import datetime
|
|
import time
|
|
from threading import Thread
|
|
import hashlib
|
|
|
|
class AccesTokenController(Thread):
|
|
tokenList = None
|
|
self.lifetime = 60
|
|
|
|
def __init__(self):
|
|
print("init AccesTokenControlle")
|
|
print("init threading")
|
|
Thread.__init__(self)
|
|
self.tokenList = []
|
|
|
|
def findAccesToken(self, token):
|
|
print("search for AccesToken", token)
|
|
for accToken in self.tokenList:
|
|
if accToken == token:
|
|
print("find AccesToken", accToken, "with token", token)
|
|
return accToken
|
|
print("no AccesToken with", token)
|
|
return None
|
|
|
|
def createAccesToken(self, user):
|
|
print("create AccesToken")
|
|
now = datetime.ctime(datetime.now())
|
|
token = hashlib.md5((now + user.password).encode('utf-8')).hexdigest()
|
|
self.tokenList.append(AccessToken(user, token))
|
|
print(self.tokenList)
|
|
print("finished create AccesToken", token)
|
|
return token
|
|
|
|
def isSameGroup(self, accToken, group):
|
|
print("controll if", accToken, "hase group", group)
|
|
return True if accToken.user.group == group else False
|
|
|
|
def run(self):
|
|
while True:
|
|
print("start allocate")
|
|
for accToken in self.tokenList:
|
|
print("controle", accToken)
|
|
if (datetime.now() - accToken.timestamp).seconds > self.lifetime:
|
|
print("delete", accToken)
|
|
self.tokenList.remove(accToken)
|
|
else:
|
|
print("time is only", (datetime.now() - accToken.timestamp).seconds)
|
|
print(self.tokenList)
|
|
print("wait")
|
|
time.sleep(10)
|