flaschengeist/geruecht/model/accessToken.py

50 lines
1.3 KiB
Python
Raw Normal View History

2019-04-11 21:56:55 +00:00
from datetime import datetime
class AccessToken():
2019-04-17 12:46:46 +00:00
""" Model for an AccessToken
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
def __init__(self, user, token, timestamp=datetime.now()):
2019-04-17 12:46:46 +00:00
""" 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.
"""
2019-04-11 21:56:55 +00:00
self.user = user
self.timestamp = timestamp
self.token = token
def updateTimestamp(self):
2019-04-17 12:46:46 +00:00
""" Update the Timestamp
Update the Timestamp to the current Time.
"""
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)