From 487f27c64b7ae96625767aa0b3ed2e1954b0dc7e Mon Sep 17 00:00:00 2001 From: Naman Sharma Date: Sun, 18 Jan 2026 16:12:12 +0000 Subject: [PATCH] Added reCAPTCHA to new question form --- forums/settings.py | 10 +- requirements.txt | 1 + static/website/templates/new-question.html | 8 ++ website/forms.py | 3 +- website/views.py | 129 ++++++++++++++++----- 5 files changed, 116 insertions(+), 35 deletions(-) diff --git a/forums/settings.py b/forums/settings.py index 6c549d2..2ed2771 100644 --- a/forums/settings.py +++ b/forums/settings.py @@ -18,6 +18,10 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# reCAPTCHA Settings +RECAPTCHA_SITE_KEY = os.getenv("RECAPTCHA_SITE_KEY") +RECAPTCHA_SECRET_KEY = os.getenv("RECAPTCHA_SECRET_KEY") + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ @@ -108,8 +112,8 @@ 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': os.getenv("SPOKEN_DB"), # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: - 'USER': os.getenv("DB_USER"), - 'PASSWORD': os.getenv("DB_PASSWORD"), + 'USER': os.getenv("SPOKEN_DB_USER"), + 'PASSWORD': os.getenv("SPOKEN_DB_PASSWORD"), # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 'HOST': '', 'PORT': '', # Set to empty string for default. @@ -150,7 +154,7 @@ LANGUAGE_CODE = 'en-us' -TIME_ZONE = 'Asia/Calcutta' +TIME_ZONE = 'Asia/Kolkata' USE_I18N = True diff --git a/requirements.txt b/requirements.txt index 08937ec..27abac0 100755 --- a/requirements.txt +++ b/requirements.txt @@ -15,3 +15,4 @@ django-debug-toolbar==1.4 python-dotenv==0.10.3 nltk==3.5 sklearn==0.0 +requests>=2.25.0 diff --git a/static/website/templates/new-question.html b/static/website/templates/new-question.html index c088447..78dea29 100755 --- a/static/website/templates/new-question.html +++ b/static/website/templates/new-question.html @@ -54,6 +54,13 @@

{% render_field form.body class+="form-control" %} + + + {% if require_recaptcha %} +
+
+
+ {% endif %} @@ -76,6 +83,7 @@

+