mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-30 04:27:01 -05:00
feat: Implement MFA authentication, add ride statistics model, and update various services, APIs, and tests across the application.
This commit is contained in:
@@ -3,7 +3,7 @@ Mixins for authentication views.
|
||||
"""
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from apps.core.utils.turnstile import validate_turnstile_token, get_client_ip
|
||||
from apps.core.utils.turnstile import get_client_ip, validate_turnstile_token
|
||||
|
||||
|
||||
class TurnstileMixin:
|
||||
@@ -15,30 +15,30 @@ class TurnstileMixin:
|
||||
def validate_turnstile(self, request):
|
||||
"""
|
||||
Validate the Turnstile response token.
|
||||
|
||||
|
||||
The token can be provided as:
|
||||
- 'cf-turnstile-response' in POST data (form submission)
|
||||
- 'turnstile_token' in JSON body (API request)
|
||||
"""
|
||||
# Try to get token from various sources
|
||||
token = None
|
||||
|
||||
|
||||
# Check POST data (form submissions)
|
||||
if hasattr(request, 'POST'):
|
||||
token = request.POST.get("cf-turnstile-response")
|
||||
|
||||
|
||||
# Check JSON body (API requests)
|
||||
if not token and hasattr(request, 'data'):
|
||||
data = getattr(request, 'data', {})
|
||||
if hasattr(data, 'get'):
|
||||
token = data.get('turnstile_token') or data.get('cf-turnstile-response')
|
||||
|
||||
|
||||
# Get client IP
|
||||
ip = get_client_ip(request)
|
||||
|
||||
|
||||
# Validate the token
|
||||
result = validate_turnstile_token(token, ip)
|
||||
|
||||
|
||||
if not result.get('success'):
|
||||
error_msg = result.get('error', 'Captcha verification failed. Please try again.')
|
||||
raise ValidationError(error_msg)
|
||||
|
||||
Reference in New Issue
Block a user