From f4bae4af063a66ab42a1dd1194a7f5bca8b464a8 Mon Sep 17 00:00:00 2001 From: Ananya Date: Tue, 3 Mar 2026 21:19:39 +0530 Subject: [PATCH 1/3] feat: add captcha protection to user-facing forms --- web/forms.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/web/forms.py b/web/forms.py index 96489d524..b4799c7dd 100644 --- a/web/forms.py +++ b/web/forms.py @@ -578,6 +578,8 @@ def clean(self): class ReviewForm(forms.ModelForm): + captcha = CaptchaField(widget=TailwindCaptchaTextInput) + class Meta: model = Review fields = ("rating", "comment") @@ -910,6 +912,7 @@ class SuccessStoryForm(forms.ModelForm): content = MarkdownxFormField( label="Content", help_text="Use markdown for formatting. You can use **bold**, *italic*, lists, etc." ) + captcha = CaptchaField(widget=TailwindCaptchaTextInput) class Meta: model = SuccessStory @@ -929,6 +932,8 @@ class Meta: class LearnForm(forms.ModelForm): """Form for creating and editing waiting rooms.""" + captcha = CaptchaField(widget=TailwindCaptchaTextInput) + class Meta: model = WaitingRoom fields = ["title", "description", "subject", "topics"] @@ -1254,6 +1259,7 @@ class ForumTopicForm(forms.Form): widget=TailwindURLInput(attrs={"placeholder": "https://github.com/your-org/your-repo/milestone/1"}), help_text="Link to a related GitHub milestone (optional)", ) + captcha = CaptchaField(widget=TailwindCaptchaTextInput) def clean_github_issue_url(self): url = self.cleaned_data.get("github_issue_url") @@ -1308,6 +1314,8 @@ class Meta: class BlogPostForm(forms.ModelForm): """Form for creating and editing blog posts.""" + captcha = CaptchaField(widget=TailwindCaptchaTextInput) + class Meta: model = BlogPost fields = ["title", "content", "excerpt", "featured_image", "status", "tags"] @@ -1664,6 +1672,7 @@ class MemeForm(forms.ModelForm): ), help_text="If your subject isn't listed, enter a new one here", ) + captcha = CaptchaField(widget=TailwindCaptchaTextInput) class Meta: model = Meme @@ -1902,6 +1911,8 @@ class Meta: class StudyGroupForm(forms.ModelForm): + captcha = CaptchaField(widget=TailwindCaptchaTextInput) + class Meta: model = StudyGroup fields = ["name", "description", "course", "max_members", "is_private"] @@ -1915,6 +1926,7 @@ class VideoRequestForm(forms.ModelForm): # Only allow href, title and target attributes on anchor tags for security "a": ["href", "title", "target"], } + captcha = CaptchaField(widget=TailwindCaptchaTextInput) class Meta: model = VideoRequest @@ -1965,6 +1977,7 @@ class SurveyForm(forms.ModelForm): widget=TailwindInput(attrs={"placeholder": "Enter survey title"}), help_text="Give your survey a clear and descriptive title", ) + captcha = CaptchaField(widget=TailwindCaptchaTextInput) class Meta: model = Survey From cdcb7c5dfd805eb03e83d633750851217cfe4232 Mon Sep 17 00:00:00 2001 From: Ananya Date: Tue, 3 Mar 2026 21:40:49 +0530 Subject: [PATCH 2/3] fixes --- web/templates/add_meme.html | 7 +++++++ web/templates/success_stories/create.html | 9 +++++++++ web/templates/videos/submit_request.html | 14 ++++++++++++-- web/templates/web/forum/create_topic.html | 8 ++++++++ web/templates/web/forum/edit_topic.html | 8 ++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/web/templates/add_meme.html b/web/templates/add_meme.html index e7c12a71e..f564e409d 100644 --- a/web/templates/add_meme.html +++ b/web/templates/add_meme.html @@ -65,6 +65,8 @@

Add a New Educational Meme

Preview

@@ -72,6 +74,11 @@

Add a New Educational Meme

+
+ + {{ form.captcha }} + {% if form.captcha.errors %}

{{ form.captcha.errors.0 }}

{% endif %} +
{% if form.non_field_errors %}
{% for error in form.non_field_errors %}

{{ error }}

{% endfor %} diff --git a/web/templates/success_stories/create.html b/web/templates/success_stories/create.html index e2fb282d6..18cffe566 100644 --- a/web/templates/success_stories/create.html +++ b/web/templates/success_stories/create.html @@ -106,6 +106,15 @@

Draft: Save but don't publish yet. Published: Make visible to everyone.

+ +
+ + {{ form.captcha }} + {% if form.captcha.errors %} +

{{ form.captcha.errors }}

+ {% endif %} +
-{% endblock %} +{% endblock content %} diff --git a/web/templates/web/forum/create_topic.html b/web/templates/web/forum/create_topic.html index af6146f7f..c55ea488f 100644 --- a/web/templates/web/forum/create_topic.html +++ b/web/templates/web/forum/create_topic.html @@ -85,6 +85,14 @@

{{ form.github_milestone_url.errors }}
{% endif %} +
+ + {{ form.captcha }} + {% if form.captcha.errors %} +
{{ form.captcha.errors }}
+ {% endif %} +
+
+ + {{ form.captcha }} + {% if form.captcha.errors %} +
{{ form.captcha.errors }}
+ {% endif %} +
- + {{ form.captcha }} - {% if form.captcha.errors %}

{{ form.captcha.errors.0 }}

{% endif %} + {% if form.captcha.errors %} +

{{ form.captcha.errors.0 }}

+ {% endif %}
{% if form.non_field_errors %}
diff --git a/web/templates/web/forum/create_topic.html b/web/templates/web/forum/create_topic.html index c55ea488f..16b99777c 100644 --- a/web/templates/web/forum/create_topic.html +++ b/web/templates/web/forum/create_topic.html @@ -87,7 +87,7 @@

+ class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">CAPTCHA {{ form.captcha }} {% if form.captcha.errors %}
{{ form.captcha.errors }}
diff --git a/web/templates/web/forum/edit_topic.html b/web/templates/web/forum/edit_topic.html index 608304875..3eccfaa5f 100644 --- a/web/templates/web/forum/edit_topic.html +++ b/web/templates/web/forum/edit_topic.html @@ -68,7 +68,7 @@

Edit Topic

+ class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">CAPTCHA {{ form.captcha }} {% if form.captcha.errors %}
{{ form.captcha.errors }}