From dc6f5dcc5be6b06739fe634e0820366d46db14fc Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Thu, 16 Nov 2023 19:12:59 +0100 Subject: [PATCH 1/5] add recaptcha coe --- dynamicweb/settings/base.py | 3 +++ utils/forms.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 62fe2897..308c9029 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -56,6 +56,9 @@ dotenv.load_dotenv("{0}/.env".format(PROJECT_DIR)) from multisite import SiteID +RECAPTCHA_PUBLIC_KEY = env('RECAPTCHA_PUBLIC_KEY') +RECAPTCHA_PRIVATE_KEY = env('RECAPTCHA_PRIVATE_KEY') + UNGLEICH_BLOG_SITE_ID = int_env("UNGLEICH_BLOG_SITE_ID") SITE_ID = SiteID(default=(UNGLEICH_BLOG_SITE_ID if UNGLEICH_BLOG_SITE_ID > 0 else 1)) diff --git a/utils/forms.py b/utils/forms.py index f35c90f4..92b442af 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -4,6 +4,8 @@ from django.core.mail import EmailMultiAlternatives from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ +from captcha.fields import ReCaptchaField + from membership.models import CustomUser from .models import ContactMessage, BillingAddress, UserBillingAddress @@ -188,6 +190,7 @@ class UserBillingAddressForm(forms.ModelForm): class ContactUsForm(forms.ModelForm): error_css_class = 'autofocus' + captcha = ReCaptchaField() class Meta: model = ContactMessage From 9f74c0286e30d2ac68af477d81eb7183426d83f7 Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Thu, 16 Nov 2023 19:24:59 +0100 Subject: [PATCH 2/5] Add installed app --- dynamicweb/settings/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 308c9029..f03042dc 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -128,6 +128,7 @@ INSTALLED_APPS = ( 'djangocms_file', 'djangocms_picture', 'djangocms_video', + 'django_recaptcha', # 'djangocms_flash', # 'djangocms_googlemap', # 'djangocms_inherit', From c5f8660c5532481fa43b4f2ff23542752548abd0 Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Fri, 17 Nov 2023 03:29:10 +0100 Subject: [PATCH 3/5] Disable all saving of contact us form and send emails --- alplora/views.py | 6 +++--- digitalglarus/views.py | 6 +++--- ungleich_page/views.py | 6 +++--- utils/forms.py | 19 ++++++++++--------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/alplora/views.py b/alplora/views.py index 0a10b4e0..9fcbbc2f 100644 --- a/alplora/views.py +++ b/alplora/views.py @@ -31,9 +31,9 @@ class ContactView(FormView): return context def form_valid(self, form): - form.save() - form.send_email(email_to='info@alplora.ch') - messages.add_message(self.request, messages.SUCCESS, self.success_message) + #form.save() + #form.send_email(email_to='info@alplora.ch') + #messages.add_message(self.request, messages.SUCCESS, self.success_message) return render(self.request, 'alplora/contact_success.html', {}) diff --git a/digitalglarus/views.py b/digitalglarus/views.py index 299327e6..ba1a59f7 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -835,9 +835,9 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): - form.save() - form.send_email() - messages.add_message(self.request, messages.SUCCESS, self.success_message) + #form.save() + #form.send_email() + #messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(ContactView, self).form_valid(form) diff --git a/ungleich_page/views.py b/ungleich_page/views.py index e5a99d8d..372afb86 100644 --- a/ungleich_page/views.py +++ b/ungleich_page/views.py @@ -25,9 +25,9 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): - form.save() - form.send_email() - messages.add_message(self.request, messages.SUCCESS, self.success_message) + #form.save() + #form.send_email() + #messages.add_message(self.request, messages.SUCCESS, self.success_message) return super(ContactView, self).form_valid(form) def get_context_data(self, **kwargs): diff --git a/utils/forms.py b/utils/forms.py index 92b442af..3cc57578 100644 --- a/utils/forms.py +++ b/utils/forms.py @@ -4,7 +4,7 @@ from django.core.mail import EmailMultiAlternatives from django.template.loader import render_to_string from django.utils.translation import ugettext_lazy as _ -from captcha.fields import ReCaptchaField +from django_recaptcha.fields import ReCaptchaField from membership.models import CustomUser from .models import ContactMessage, BillingAddress, UserBillingAddress @@ -209,11 +209,12 @@ class ContactUsForm(forms.ModelForm): } def send_email(self, email_to='info@digitalglarus.ch'): - text_content = render_to_string( - 'emails/contact.txt', {'data': self.cleaned_data}) - html_content = render_to_string( - 'emails/contact.html', {'data': self.cleaned_data}) - email = EmailMultiAlternatives('Subject', text_content) - email.attach_alternative(html_content, "text/html") - email.to = [email_to] - email.send() + pass + #text_content = render_to_string( + # 'emails/contact.txt', {'data': self.cleaned_data}) + #html_content = render_to_string( + # 'emails/contact.html', {'data': self.cleaned_data}) + #email = EmailMultiAlternatives('Subject', text_content) + #email.attach_alternative(html_content, "text/html") + #email.to = [email_to] + #email.send() From 3c3c614b6b1d0c5993460dd1e21b6f05fb0e2d3c Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Fri, 17 Nov 2023 03:39:12 +0100 Subject: [PATCH 4/5] Debug --- alplora/views.py | 1 + digitalglarus/views.py | 1 + ungleich_page/views.py | 1 + 3 files changed, 3 insertions(+) diff --git a/alplora/views.py b/alplora/views.py index 9fcbbc2f..d628cffc 100644 --- a/alplora/views.py +++ b/alplora/views.py @@ -31,6 +31,7 @@ class ContactView(FormView): return context def form_valid(self, form): + print("alplora contactusform") #form.save() #form.send_email(email_to='info@alplora.ch') #messages.add_message(self.request, messages.SUCCESS, self.success_message) diff --git a/digitalglarus/views.py b/digitalglarus/views.py index ba1a59f7..bf3ed2c6 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -835,6 +835,7 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): + print("digital glarus contactusform") #form.save() #form.send_email() #messages.add_message(self.request, messages.SUCCESS, self.success_message) diff --git a/ungleich_page/views.py b/ungleich_page/views.py index 372afb86..01d1138d 100644 --- a/ungleich_page/views.py +++ b/ungleich_page/views.py @@ -25,6 +25,7 @@ class ContactView(FormView): success_message = _('Message Successfully Sent') def form_valid(self, form): + print("ungleich_page contactusform") #form.save() #form.send_email() #messages.add_message(self.request, messages.SUCCESS, self.success_message) From 325d1ffcb94add403cc7c9b60d354d9a16b6ef5e Mon Sep 17 00:00:00 2001 From: "app@dynamicweb-production" Date: Fri, 17 Nov 2023 03:43:49 +0100 Subject: [PATCH 5/5] Ignore more contact f --- datacenterlight/views.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 5bf68e0a..5c333a63 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -63,23 +63,23 @@ class ContactUsView(FormView): ) def form_valid(self, form): - form.save() - from_emails = { - 'glasfaser': 'glasfaser@ungleich.ch' - } - from_page = self.request.POST.get('from_page') - email_data = { - 'subject': "{dcl_text} Message from {sender}".format( - dcl_text=settings.DCL_TEXT, - sender=form.cleaned_data.get('email') - ), - 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, - 'to': [from_emails.get(from_page, 'support@ungleich.ch')], - 'body': "\n".join( - ["%s=%s" % (k, v) for (k, v) in form.cleaned_data.items()]), - 'reply_to': [form.cleaned_data.get('email')], - } - send_plain_email_task.delay(email_data) + #form.save() + #from_emails = { + # 'glasfaser': 'glasfaser@ungleich.ch' + #} + #from_page = self.request.POST.get('from_page') + #email_data = { + # 'subject': "{dcl_text} Message from {sender}".format( + # dcl_text=settings.DCL_TEXT, + # sender=form.cleaned_data.get('email') + # ), + # 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, + # 'to': [from_emails.get(from_page, 'support@ungleich.ch')], + # 'body': "\n".join( + # ["%s=%s" % (k, v) for (k, v) in form.cleaned_data.items()]), + # 'reply_to': [form.cleaned_data.get('email')], + #} + #send_plain_email_task.delay(email_data) if self.request.is_ajax(): return self.render_to_response( self.get_context_data(success=True, contact_form=form))