summaryrefslogtreecommitdiff
path: root/fundraising
diff options
context:
space:
mode:
authorÇağıl <cagilulusahin@gmail.com>2019-08-13 13:54:18 +0100
committerCarlton Gibson <carlton.gibson@noumenal.es>2019-08-13 14:54:18 +0200
commit43df311168476b66cdab07cf59aaf2476cff1546 (patch)
treef4eb406ceb590f0712d3970f870eb951114a884d /fundraising
parent45450b3c90dd19e3b99427d876ad40bd630e290c (diff)
Added `invisible` recapthca to donations form. (#928)
Diffstat (limited to 'fundraising')
-rw-r--r--fundraising/forms.py6
-rw-r--r--fundraising/templatetags/fundraising_extras.py4
-rw-r--r--fundraising/urls.py1
-rw-r--r--fundraising/views.py16
4 files changed, 25 insertions, 2 deletions
diff --git a/fundraising/forms.py b/fundraising/forms.py
index d215a95f..8a5b93d5 100644
--- a/fundraising/forms.py
+++ b/fundraising/forms.py
@@ -1,4 +1,6 @@
import stripe
+from captcha.fields import ReCaptchaField
+from captcha.widgets import ReCaptchaV3
from django import forms
from django.conf import settings
from django.core.mail import send_mail
@@ -275,3 +277,7 @@ class PaymentForm(forms.Form):
)
return donation
+
+
+class ReCaptchaForm(forms.Form):
+ captcha = ReCaptchaField(widget=ReCaptchaV3)
diff --git a/fundraising/templatetags/fundraising_extras.py b/fundraising/templatetags/fundraising_extras.py
index 150317b7..4d86573f 100644
--- a/fundraising/templatetags/fundraising_extras.py
+++ b/fundraising/templatetags/fundraising_extras.py
@@ -5,7 +5,7 @@ from django.conf import settings
from django.db import models
from django.template.defaultfilters import floatformat
-from fundraising.forms import DonateForm
+from fundraising.forms import DonateForm, ReCaptchaForm
from fundraising.models import (
DEFAULT_DONATION_AMOUNT, DISPLAY_DONOR_DAYS, GOAL_AMOUNT, GOAL_START_DATE,
LEADERSHIP_LEVEL_AMOUNT, DjangoHero, InKindDonor, Payment,
@@ -51,6 +51,7 @@ def donation_form_with_heart(context):
form = DonateForm(initial={
'amount': DEFAULT_DONATION_AMOUNT,
})
+ form_captcha = ReCaptchaForm()
return {
'goal_amount': GOAL_AMOUNT,
@@ -58,6 +59,7 @@ def donation_form_with_heart(context):
'donated_amount': donated_amount,
'total_donors': total_donors,
'form': form,
+ 'form_captcha': form_captcha,
'display_logo_amount': LEADERSHIP_LEVEL_AMOUNT,
'stripe_publishable_key': settings.STRIPE_PUBLISHABLE_KEY,
'user': user,
diff --git a/fundraising/urls.py b/fundraising/urls.py
index 4a3562ee..16f5fd9b 100644
--- a/fundraising/urls.py
+++ b/fundraising/urls.py
@@ -6,6 +6,7 @@ app_name = 'fundraising'
urlpatterns = [
path('', views.index, name='index'),
path('donate/', views.donate, name='donate'),
+ path('verify/', views.verify_captcha, name='verify-captcha'),
path('thank-you/<donation>/', views.thank_you, name='thank-you'),
path('manage-donations/<hero>/', views.manage_donations, name='manage-donations'),
path('manage-donations/<hero>/cancel/', views.cancel_donation, name='cancel-donation'),
diff --git a/fundraising/views.py b/fundraising/views.py
index 33124bc6..47b2cc6e 100644
--- a/fundraising/views.py
+++ b/fundraising/views.py
@@ -14,7 +14,7 @@ from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from .exceptions import DonationError
-from .forms import DjangoHeroForm, DonationForm, PaymentForm
+from .forms import DjangoHeroForm, DonationForm, PaymentForm, ReCaptchaForm
from .models import (
LEADERSHIP_LEVEL_AMOUNT, DjangoHero, Donation, Payment, Testimonial,
)
@@ -28,6 +28,20 @@ def index(request):
@require_POST
+def verify_captcha(request):
+ form = ReCaptchaForm(request.POST)
+
+ if form.is_valid():
+ data = {'success': True}
+ else:
+ data = {
+ 'success': False,
+ 'error': form.errors
+ }
+ return JsonResponse(data)
+
+
+@require_POST
def donate(request):
form = PaymentForm(request.POST)