from datetime import datetime from geruecht import getLogger LOGGER = getLogger(__name__) 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 ldap_conn = None def __init__(self, user, token, ldap_conn, 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. """ LOGGER.debug("Initialize AccessToken") self.user = user self.timestamp = timestamp self.token = token self.ldap_conn = ldap_conn def updateTimestamp(self): """ Update the Timestamp Update the Timestamp to the current Time. """ LOGGER.debug("Update Timestamp") 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({}, {}, {}".format(self.user, self.token, self.timestamp) def __repr__(self): return "AccessToken({}, {}, {}".format(self.user, self.token, self.timestamp)