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