flaschengeist/geruecht/model/accessToken.py

56 lines
1.6 KiB
Python
Raw Normal View History

2019-04-11 21:56:55 +00:00
from datetime import datetime
from geruecht.logger import getDebugLogger
LOGGER = getDebugLogger()
2019-04-11 21:56:55 +00:00
class AccessToken():
2019-04-17 12:46:46 +00:00
""" Model for an AccessToken
2019-05-02 16:50:59 +00:00
2019-04-17 12:46:46 +00:00
Attributes:
timestamp: Is a Datetime from current Time.
user: Is an User.
token: String to verify access later.
"""
2019-04-11 21:56:55 +00:00
timestamp = None
user = None
token = None
2020-01-26 22:31:22 +00:00
ldap_conn = None
2019-04-11 21:56:55 +00:00
2020-03-07 13:56:44 +00:00
def __init__(self, user, token, ldap_conn, lifetime, timestamp=datetime.now()):
2019-04-17 12:46:46 +00:00
""" Initialize Class AccessToken
2019-05-02 16:50:59 +00:00
2019-04-17 12:46:46 +00:00
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")
2019-04-11 21:56:55 +00:00
self.user = user
self.timestamp = timestamp
2020-03-07 13:56:44 +00:00
self.lifetime = lifetime
2019-04-11 21:56:55 +00:00
self.token = token
2020-01-26 22:31:22 +00:00
self.ldap_conn = ldap_conn
2019-04-11 21:56:55 +00:00
def updateTimestamp(self):
2019-04-17 12:46:46 +00:00
""" Update the Timestamp
Update the Timestamp to the current Time.
"""
LOGGER.debug("Update Timestamp")
2019-04-11 21:56:55 +00:00
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):
2020-03-09 18:54:51 +00:00
return "AccessToken(user={}, token={}, timestamp={}, lifetime={}".format(self.user, self.token, self.timestamp, self.lifetime)
2019-04-11 21:56:55 +00:00
def __repr__(self):
2020-03-09 18:54:51 +00:00
return "AccessToken(user={}, token={}, timestamp={}, lifetime={}".format(self.user, self.token, self.timestamp, self.lifetime)