def reset_token(self): """ Resets a token by creating a new valid token, and saves the current token as previous. """ self.previous = self.valid self.valid = str(uuid4()) self.last_changed = isotime(subsecond=True)
def __init__(self, valid=None, previous=None, last_changed=None): if not valid: valid = str(uuid4()) if not last_changed: last_changed = isotime(subsecond=True) self.valid = valid self.previous = previous self.last_changed = last_changed
def _validate_token_min_time_limit_reached(self, token): #get the token create time and the current time as datetime objects token_created = parse_isotime(token.last_changed) current_time = parse_isotime(isotime(subsecond=True)) #get a datetime.timedelta object that represents the difference time_diff = current_time - token_created hours_diff = time_diff.total_seconds() / 3600 #if the time limit has not been reached, abort and alert the caller if hours_diff < MIN_TOKEN_TIME_LIMIT_HRS: _token_time_limit_not_reached()
def _validate_token_min_time_limit_reached(self, token): #get the token create time and the current time as datetime objects token_created = parse_isotime(token.last_changed) current_time = parse_isotime(isotime(subsecond=True)) #get a datetime.timedelta object that represents the difference time_diff = current_time - token_created hours_diff = time_diff.total_seconds() / 3600 #if the time limit has not been reached, abort and alert the caller if hours_diff < MIN_TOKEN_TIME_LIMIT_HRS: _token_time_limit_not_reached() return True
def reset_token(self): self.previous = self.valid self.valid = str(uuid4()) self.last_changed = isotime(subsecond=True)