diff --git a/hub/services/templates/services/embedded_contact_form.html b/hub/services/templates/services/embedded_contact_form.html index 5d22f21..660be51 100644 --- a/hub/services/templates/services/embedded_contact_form.html +++ b/hub/services/templates/services/embedded_contact_form.html @@ -8,6 +8,13 @@ {% if details %} {% endif %} + + +
+ {% if service %} diff --git a/hub/services/templatetags/contact_tags.py b/hub/services/templatetags/contact_tags.py index 6d7791b..7d071bf 100644 --- a/hub/services/templatetags/contact_tags.py +++ b/hub/services/templatetags/contact_tags.py @@ -2,6 +2,7 @@ from django import template from hub.services.forms import LeadForm from hub.services.models import Service, ServiceOffering, Plan +import time register = template.Library() @@ -29,6 +30,9 @@ def embedded_contact_form( request = context["request"] form = LeadForm() + # Add timestamp for spam protection + timestamp = int(time.time()) + service_obj = None offering_obj = None plan_obj = None @@ -71,4 +75,5 @@ def embedded_contact_form( "request": request, "choices": processed_choices, "choice_label": choice_label, + "timestamp": timestamp, } diff --git a/hub/services/views/leads.py b/hub/services/views/leads.py index 00ce109..2e3ccda 100644 --- a/hub/services/views/leads.py +++ b/hub/services/views/leads.py @@ -1,4 +1,5 @@ import logging +import time from django.shortcuts import render, redirect from django.contrib import messages @@ -18,6 +19,27 @@ def thank_you(request): def contact_form(request): if request.method == "POST": + # Spam protection checks + honeypot_value = request.POST.get("website", "") + timestamp_value = request.POST.get("form_timestamp", "0") + current_time = int(time.time()) + + # Check 1: Honeypot field should be empty + if honeypot_value: + # Bot detected - silently redirect + return redirect("services:homepage") + + # Check 2: Form shouldn't be submitted too quickly (< 3 seconds) + try: + form_time = int(timestamp_value) + if current_time - form_time < 3: + # Too quick submission - likely a bot + return redirect("services:homepage") + except ValueError: + # Invalid timestamp - likely a bot + return redirect("services:homepage") + + # Continue with normal form processing form = LeadForm(request.POST) if form.is_valid(): from hub.services.models import Lead, Service, ServiceOffering, Plan