Actually make throttling work correctly

refactor
Sander Ferdinand 6 years ago
parent 3989dbdf8c
commit 523fa1c569
No known key found for this signature in database
GPG Key ID: 7BBC83D7A8810AAB

@ -46,16 +46,19 @@ def api_qr_generate(address):
"""
from funding.factory import cache
throttling_seconds = 3
ip = get_ip()
cache_key = 'qr_ip_%s' % ip
hit = cache.get(cache_key)
if hit and ip not in ['127.0.0.1', 'localhost']:
return Response('Wait a bit before generating a new QR', 403)
cache.set(cache_key, {}, throttling_seconds)
qr = QrCodeGenerator()
if not qr.exists(address):
# create a new QR code
ip = get_ip()
cache_key = 'qr_ip_%s' % ip
hit = cache.get(cache_key)
if hit and ip not in ['127.0.0.1', 'localhost']:
return Response('Wait a bit before generating a new QR', 403)
throttling_seconds = 3
cache.set(cache_key, {'wow': 'kek'}, throttling_seconds)
created = qr.create(address)
if not created:
raise Exception('Could not create QR code')

Loading…
Cancel
Save