Compare commits
2 Commits
86ef9dc947
...
a53fada7e1
Author | SHA1 | Date | |
---|---|---|---|
a53fada7e1 | |||
0ea7521054 |
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 |
|
| `exempt_if` | Skip protection for trusted users | For staff |
|
||||||
| `methods` | HTTP methods to track (POST, GET, etc.) | POST |
|
| `methods` | HTTP methods to track (POST, GET, etc.) | POST |
|
||||||
| `shared` | Share same attempts counter among all endpoints | `False` |
|
| `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,
|
response=None,
|
||||||
exempt_if=lambda request: request.user.is_staff or request.user.is_superuser,
|
exempt_if=lambda request: request.user.is_staff or request.user.is_superuser,
|
||||||
backoff=False,
|
backoff=False,
|
||||||
shared=False
|
shared=False,
|
||||||
|
type=None,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Enforces CAPTCHA if request exceeds `threshold`.
|
Enforces CAPTCHA if request exceeds `threshold`.
|
||||||
@ -69,6 +70,7 @@ def hoptcha_protected(
|
|||||||
- exempt_if: skip protection for trusted users.
|
- exempt_if: skip protection for trusted users.
|
||||||
- methods: HTTP methods to track (default: POST).
|
- methods: HTTP methods to track (default: POST).
|
||||||
- shared: Share same attempts counter among all endpoints.
|
- shared: Share same attempts counter among all endpoints.
|
||||||
|
- type: Type of CAPTCHA do display (sliding, pointing, random)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(key, str):
|
if isinstance(key, str):
|
||||||
@ -80,6 +82,8 @@ def hoptcha_protected(
|
|||||||
else:
|
else:
|
||||||
raise TypeError("key must be a string or callable")
|
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):
|
def decorator(view_func):
|
||||||
@wraps(view_func)
|
@wraps(view_func)
|
||||||
def _wrapped_view(request, *args, **kwargs):
|
def _wrapped_view(request, *args, **kwargs):
|
||||||
@ -101,7 +105,7 @@ def hoptcha_protected(
|
|||||||
if not token or not verify_token(token):
|
if not token or not verify_token(token):
|
||||||
return response(request) if response else JsonResponse({
|
return response(request) if response else JsonResponse({
|
||||||
"error": "CAPTCHA",
|
"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)
|
}, status=400)
|
||||||
else:
|
else:
|
||||||
cache.delete(cache_key) # reset counter if passed
|
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
0
example/demoapp/demoapp/__init__.py
Normal file → Executable file
0
example/demoapp/demoapp/__init__.py
Normal file → Executable file
0
example/demoapp/demoapp/asgi.py
Normal file → Executable file
0
example/demoapp/demoapp/asgi.py
Normal file → Executable file
0
example/demoapp/demoapp/settings.py
Normal file → Executable file
0
example/demoapp/demoapp/settings.py
Normal file → Executable file
0
example/demoapp/demoapp/templates/form.html
Normal file → Executable file
0
example/demoapp/demoapp/templates/form.html
Normal file → Executable file
0
example/demoapp/demoapp/urls.py
Normal file → Executable file
0
example/demoapp/demoapp/urls.py
Normal file → Executable file
0
example/demoapp/demoapp/views.py
Normal file → Executable file
0
example/demoapp/demoapp/views.py
Normal file → Executable file
0
example/demoapp/demoapp/wsgi.py
Normal file → Executable file
0
example/demoapp/demoapp/wsgi.py
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user