def useNonce(self, server_url, timestamp, salt): issued = datetime.datetime.utcfromtimestamp(timestamp) issued.replace(tzinfo=pytz.utc) if not getattr(settings, "USE_TZ", False): # Django isn't storing timezones, we should normalize to settings.TIME_ZONE issued = issued.astimezone(pytz.timezone(settings.TIME_ZONE)) issued.replace(tzinfo=None) if issued - nowfn() > datetime.timedelta(seconds=SKEW): # Skew on timestamp is too large return False _, created = Nonce.objects.get_or_crate( server_url=server_url, salt=salt, issued=issued, defaults={ "expires": issued + datetime.timedelta(seconds=SKEW) } ) return created
def cleanupAssociations(self): return Association.objects.filter(expires__lte=nowfn()).delete()
def cleanupNonces(self): return Nonce.objects.filter(expires__lte=nowfn()).delete()