2019-04-11 21:56:55 +00:00
|
|
|
from datetime import datetime
|
2019-05-02 23:40:13 +00:00
|
|
|
from geruecht import getLogger
|
|
|
|
|
|
|
|
LOGGER = getLogger(__name__)
|
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-01-26 22:31:22 +00:00
|
|
|
def __init__(self, user, token, ldap_conn, 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.
|
|
|
|
"""
|
2019-05-02 23:40:13 +00:00
|
|
|
LOGGER.debug("Initialize AccessToken")
|
2019-04-11 21:56:55 +00:00
|
|
|
self.user = user
|
|
|
|
self.timestamp = timestamp
|
|
|
|
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.
|
|
|
|
"""
|
2019-05-02 23:40:13 +00:00
|
|
|
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):
|
2019-04-17 12:46:46 +00:00
|
|
|
return "AccessToken({}, {}, {}".format(self.user, self.token, self.timestamp)
|
2019-04-11 21:56:55 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2019-04-17 12:46:46 +00:00
|
|
|
return "AccessToken({}, {}, {}".format(self.user, self.token, self.timestamp)
|