From 4c1f717be5d4f8963ad13c93c9fa741748bb8a79 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 6 Jan 2020 22:35:58 +0100 Subject: [PATCH] improved contact form --- rowers/forms.py | 1 - rowers/templates/email.html | 219 ++++++++++++++++++--------------- rowers/views/statements.py | 37 ++++-- rowsandall_app/settings_dev.py | 2 +- templates/newbase.html | 1 + 5 files changed, 145 insertions(+), 115 deletions(-) diff --git a/rowers/forms.py b/rowers/forms.py index 46de978c..bbd919b8 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -115,7 +115,6 @@ class EmailForm(forms.Form): lastname = forms.CharField(max_length=255) email = forms.EmailField() subject = forms.CharField(max_length=255) - botcheck = forms.CharField(max_length=5) message = forms.CharField() disqualificationreasons = ( diff --git a/rowers/templates/email.html b/rowers/templates/email.html index 474c3765..86fd7b2e 100644 --- a/rowers/templates/email.html +++ b/rowers/templates/email.html @@ -3,115 +3,134 @@ {% block main %}

Contact us through email

+
    -
  • - {% if form.errors %} -

    - Please correct the error{{ form.errors|pluralize }} below. -

    - {% endif %} - - -
    {% csrf_token %} - - - - - -
    - - - - - -
    - - - - - - -
    - - - -
    - - - -
    - - - - - -
    - Do you want to send me an email? - - -
    - - - -
    - -
    -
    +
  • + {% if form.errors %} +

    + Please correct the error{{ form.errors|pluralize }} below. +

    + {% endif %} + + +
    {% csrf_token %} +

    + + + + + +
    + + + + + +
    + + + + + + +
    + + + +
    + + + +
    + + + + + +
    + + + +
    + +
    +

    +
  • -

    Bug reporting, feature requests

    - -

    - Bug reports and feature requests can be done through our BitBucket page. Please check on the following link if your bug or issue is a known one. Feel free to file any feature request. -

      -
    • BitBucket Issue list (click here to go report an issue or request a feature)
    • -
    -

    +

    Bug reporting, feature requests

    + +

    + Bug reports and feature requests can be done through our BitBucket page. Please check on the following link if your bug or issue is a known one. Feel free to file any feature request. +

      +
    • BitBucket Issue list (click here to go report an issue or request a feature)
    • +
    +

  • -

    Facebook Group

    - -

    We run a facebook group where you can post questions and report problems, - especially if you think the wider user community benefits from the answers.

    -
      -
    • https://www.facebook.com/groups/rowsandall/
    • -
    -
  • +

    Facebook Group

    -
  • -

    Twitter

    - -

    You can also check me on Twitter: -

      -
    • https://twitter.com/rowsandall -
    - When the site is down, this is the appropriate channel to look for apologies, updates, and offer help. -

    -
  • +

    We run a facebook group where you can post questions and report problems, + especially if you think the wider user community benefits from the answers.

    +
      +
    • https://www.facebook.com/groups/rowsandall/
    • +
    + -
  • -

    Rowsandall s.r.o.

    - -

    Rowsandall s.r.o.
    - Nové sady 988/2
    - 602 00 Brno
    - Czech Republic
    - IČ: 070 48 572
    - DIČ: CZ 070 48 572 (Nejsme plátce DPH)
    - Datová schránka: 7897syr
    - Email: info@rowsandall.com
    - The company is registered in the business register at the - Regional Court in Brno (Společnost je zapsána v obchodním rejstříku vedeném u Krajského soudu v Brně, oddíl C, vložka 105845)
    -

    +
  • +

    Twitter

    -
  • -
-{% endblock %} +

You can also check me on Twitter: +

    +
  • https://twitter.com/rowsandall +
+ When the site is down, this is the appropriate channel to look for apologies, updates, and offer help. +

+ -{% block sidebar %} -{% include 'menu_help.html' %} -{% endblock %} +
  • +

    Rowsandall s.r.o.

    - +

    Rowsandall s.r.o.
    + Nové sady 988/2
    + 602 00 Brno
    + Czech Republic
    + IČ: 070 48 572
    + DIČ: CZ 070 48 572 (Nejsme plátce DPH)
    + Datová schránka: 7897syr
    + Email: info@rowsandall.com
    + The company is registered in the business register at the + Regional Court in Brno (Společnost je zapsána v obchodním rejstříku vedeném u Krajského soudu v Brně, oddíl C, vložka 105845)
    +

    + +
  • + + {% endblock %} + + {% block sidebar %} + {% include 'menu_help.html' %} + {% endblock %} + + {% block scripts %} + + + {% endblock %} diff --git a/rowers/views/statements.py b/rowers/views/statements.py index 1f1e700d..f2b3a263 100644 --- a/rowers/views/statements.py +++ b/rowers/views/statements.py @@ -1073,28 +1073,39 @@ def add_defaultfavorites(r): f.save() return 1 + # Shows email form and sends it if submitted def sendmail(request): if request.method == 'POST': + # test recaptcha + response_string = request.POST.get('g-recaptcha-response') + # replace below with settings + recaptcha_secret = '6LdRtMwUAAAAABc3piLDlI5VNDkOtEMIOckNi9tm' + url = 'https://www.google.com/recaptcha/api/siteverify' + data = { + 'secret':recaptcha_secret, + 'response': response_string, + } + response = requests.post(url,data=data,verify=True) + success = False + if response.status_code == 200: + success = response.json().get('success') + form = EmailForm(request.POST) - if form.is_valid(): + if form.is_valid() and success: firstname = form.cleaned_data['firstname'] lastname = form.cleaned_data['lastname'] email = form.cleaned_data['email'] - subject = form.cleaned_data['subject'] - botcheck = form.cleaned_data['botcheck'].lower() + subject = 'Rowsandall Contact Form:'+form.cleaned_data['subject'] message = form.cleaned_data['message'] - if botcheck == 'yes': - try: - fullemail = firstname + " " + lastname + " " + "<" + email + ">" - send_mail(subject, message, fullemail, ['info@rowsandall.com']) - return HttpResponseRedirect('/rowers/email/thankyou/') - except: - return HttpResponseRedirect('/rowers/email/') - else: - messages.error(request,'You have to answer YES to the question') - return HttpResponseRedirect('/rowers/email/') + fullemail = firstname + " " + lastname + " " + "<" + email + ">" + send_mail(subject, message, fullemail, ['info@rowsandall.com']) + return HttpResponseRedirect('/rowers/email/thankyou/') else: + if not success: + messages.error(request,'Bots are not welcome') + else: + messages.error(request,'Something went wrong. Please try again') return HttpResponseRedirect('/rowers/email/') else: return HttpResponseRedirect('/rowers/email/') diff --git a/rowsandall_app/settings_dev.py b/rowsandall_app/settings_dev.py index ad4c57c1..d40f8ca2 100644 --- a/rowsandall_app/settings_dev.py +++ b/rowsandall_app/settings_dev.py @@ -60,7 +60,7 @@ DEBUG = True TEMPLATES[0]['OPTIONS']['debug'] = DEBUG -ALLOWED_HOSTS = ['localhost'] +ALLOWED_HOSTS = ['localhost','127.0.0.1'] # INSTALLED_APPS += ['debug_toolbar',] diff --git a/templates/newbase.html b/templates/newbase.html index 3b6f4e2a..885e3f90 100644 --- a/templates/newbase.html +++ b/templates/newbase.html @@ -48,6 +48,7 @@ {% block meta %} {% endblock %}
    +