From a53fada7e186b6e9424347e671c744e42496d45c Mon Sep 17 00:00:00 2001 From: Ivan Nikolskiy Date: Mon, 9 Jun 2025 16:42:27 +0200 Subject: [PATCH] Added type argument --- .gitignore | 0 LICENSE | 0 MANIFEST.in | 0 README.md | 1 + django_hoptcha/__init__.py | 0 django_hoptcha/decorators.py | 8 ++++++-- django_hoptcha/settings.py | 0 django_hoptcha/static/django_hoptcha/hoptcha.js | 0 .../templates/django_hoptcha/captcha_iframe.html | 0 .../templates/django_hoptcha/captcha_placeholder.html | 0 django_hoptcha/templatetags/__init__.py | 0 django_hoptcha/templatetags/hoptcha_tags.py | 0 django_hoptcha/validators.py | 0 setup.py | 0 14 files changed, 7 insertions(+), 2 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 LICENSE mode change 100644 => 100755 MANIFEST.in mode change 100644 => 100755 README.md mode change 100644 => 100755 django_hoptcha/__init__.py mode change 100644 => 100755 django_hoptcha/decorators.py mode change 100644 => 100755 django_hoptcha/settings.py mode change 100644 => 100755 django_hoptcha/static/django_hoptcha/hoptcha.js mode change 100644 => 100755 django_hoptcha/templates/django_hoptcha/captcha_iframe.html mode change 100644 => 100755 django_hoptcha/templates/django_hoptcha/captcha_placeholder.html mode change 100644 => 100755 django_hoptcha/templatetags/__init__.py mode change 100644 => 100755 django_hoptcha/templatetags/hoptcha_tags.py mode change 100644 => 100755 django_hoptcha/validators.py mode change 100644 => 100755 setup.py diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/MANIFEST.in b/MANIFEST.in old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index b11faaa..5f818ee --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ hoptchaPost('/endpoint', payload, onSuccess, onError, function renderCustom(url) | `exempt_if` | Skip protection for trusted users | For staff | | `methods` | HTTP methods to track (POST, GET, etc.) | POST | | `shared` | Share same attempts counter among all endpoints | `False` | +| `type` | Type of CAPTCHA do display (sliding, pointing, random) | `random` | --- diff --git a/django_hoptcha/__init__.py b/django_hoptcha/__init__.py old mode 100644 new mode 100755 diff --git a/django_hoptcha/decorators.py b/django_hoptcha/decorators.py old mode 100644 new mode 100755 index a666a39..2c48928 --- a/django_hoptcha/decorators.py +++ b/django_hoptcha/decorators.py @@ -56,7 +56,8 @@ def hoptcha_protected( response=None, exempt_if=lambda request: request.user.is_staff or request.user.is_superuser, backoff=False, - shared=False + shared=False, + type=None, ): """ Enforces CAPTCHA if request exceeds `threshold`. @@ -69,6 +70,7 @@ def hoptcha_protected( - exempt_if: skip protection for trusted users. - methods: HTTP methods to track (default: POST). - shared: Share same attempts counter among all endpoints. + - type: Type of CAPTCHA do display (sliding, pointing, random) """ if isinstance(key, str): @@ -80,6 +82,8 @@ def hoptcha_protected( else: raise TypeError("key must be a string or callable") + type = type.lower() if type and type.lower() in ['sliding', 'pointing'] else 'random' + def decorator(view_func): @wraps(view_func) def _wrapped_view(request, *args, **kwargs): @@ -101,7 +105,7 @@ def hoptcha_protected( if not token or not verify_token(token): return response(request) if response else JsonResponse({ "error": "CAPTCHA", - "url": f"{GENERATE_URL}?{urlencode({'client_key': PUBLIC_KEY, 'timestamp': int(time.time() * 1000)})}" + "url": f"{GENERATE_URL}?{urlencode({'client_key': PUBLIC_KEY, 'timestamp': int(time.time() * 1000), 'type': type})}" }, status=400) else: cache.delete(cache_key) # reset counter if passed diff --git a/django_hoptcha/settings.py b/django_hoptcha/settings.py old mode 100644 new mode 100755 diff --git a/django_hoptcha/static/django_hoptcha/hoptcha.js b/django_hoptcha/static/django_hoptcha/hoptcha.js old mode 100644 new mode 100755 diff --git a/django_hoptcha/templates/django_hoptcha/captcha_iframe.html b/django_hoptcha/templates/django_hoptcha/captcha_iframe.html old mode 100644 new mode 100755 diff --git a/django_hoptcha/templates/django_hoptcha/captcha_placeholder.html b/django_hoptcha/templates/django_hoptcha/captcha_placeholder.html old mode 100644 new mode 100755 diff --git a/django_hoptcha/templatetags/__init__.py b/django_hoptcha/templatetags/__init__.py old mode 100644 new mode 100755 diff --git a/django_hoptcha/templatetags/hoptcha_tags.py b/django_hoptcha/templatetags/hoptcha_tags.py old mode 100644 new mode 100755 diff --git a/django_hoptcha/validators.py b/django_hoptcha/validators.py old mode 100644 new mode 100755 diff --git a/setup.py b/setup.py old mode 100644 new mode 100755