flaschengeist/geruecht/model/accessToken.py

56 lines
1.6 KiB
Python

from datetime import datetime
from geruecht.logger import getDebugLogger
LOGGER = 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
ldap_conn = None
def __init__(self, user, token, ldap_conn, 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.
"""
LOGGER.debug("Initialize AccessToken")
self.user = user
self.timestamp = timestamp
self.lifetime = lifetime
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(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)