from datetime import datetime from geruecht.logger import getDebugLogger debug = getDebugLogger() class AccessToken(): """ Model for an AccessToken Attributes: timestamp: Is a Datetime from current Time. user: Is an User. token: String to verify access later. """ timestamp = None user = None token = None def __init__(self, id, user, token, lifetime, timestamp=datetime.now()): """ Initialize Class AccessToken No more to say. Args: User: Is an User to set. token: Is a String to verify later timestamp: Default current time, but can set to an other datetime-Object. """ debug.debug("init accesstoken") self.id = id self.user = user self.timestamp = timestamp self.lifetime = lifetime self.token = token self.lock_bar = False debug.debug("accesstoken is {{ {} }}".format(self)) def updateTimestamp(self): """ Update the Timestamp Update the Timestamp to the current Time. """ debug.debug("update timestamp from accesstoken {{ {} }}".format(self)) self.timestamp = datetime.now() def __eq__(self, token): return True if self.token == token else False def __sub__(self, other): return other - self.timestamp def __str__(self): return "AccessToken(user={}, token={}, timestamp={}, lifetime={}".format(self.user, self.token, self.timestamp, self.lifetime) def __repr__(self): return "AccessToken(user={}, token={}, timestamp={}, lifetime={}".format(self.user, self.token, self.timestamp, self.lifetime)