Added type argument
This commit is contained in:
parent
0ea7521054
commit
a53fada7e1
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
MANIFEST.in
Normal file → Executable file
0
MANIFEST.in
Normal file → Executable file
1
README.md
Normal file → Executable file
1
README.md
Normal file → Executable file
@ -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` |
|
||||
|
||||
---
|
||||
|
||||
|
0
django_hoptcha/__init__.py
Normal file → Executable file
0
django_hoptcha/__init__.py
Normal file → Executable file
8
django_hoptcha/decorators.py
Normal file → Executable file
8
django_hoptcha/decorators.py
Normal file → Executable file
@ -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
|
||||
|
0
django_hoptcha/settings.py
Normal file → Executable file
0
django_hoptcha/settings.py
Normal file → Executable file
0
django_hoptcha/static/django_hoptcha/hoptcha.js
Normal file → Executable file
0
django_hoptcha/static/django_hoptcha/hoptcha.js
Normal file → Executable file
0
django_hoptcha/templates/django_hoptcha/captcha_iframe.html
Normal file → Executable file
0
django_hoptcha/templates/django_hoptcha/captcha_iframe.html
Normal file → Executable file
0
django_hoptcha/templates/django_hoptcha/captcha_placeholder.html
Normal file → Executable file
0
django_hoptcha/templates/django_hoptcha/captcha_placeholder.html
Normal file → Executable file
0
django_hoptcha/templatetags/__init__.py
Normal file → Executable file
0
django_hoptcha/templatetags/__init__.py
Normal file → Executable file
0
django_hoptcha/templatetags/hoptcha_tags.py
Normal file → Executable file
0
django_hoptcha/templatetags/hoptcha_tags.py
Normal file → Executable file
0
django_hoptcha/validators.py
Normal file → Executable file
0
django_hoptcha/validators.py
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user