Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Mon, 06 Jun 2022 09:57:48 UTC Commit: 1cb4a9f4b9e0b9f81ebda18bb4b9e504c2dcaf76 https://github.com/geany/www.geany.org/commit/1cb4a9f4b9e0b9f81ebda18bb4b9e5...
Log Message: ----------- Pastebin: Add simple math captcha
To reduce the huge amount of spam pastes we receive lately.
Modified Paths: -------------- geany/settings.py geany/urls.py pastebin/forms.py pastebin/static/css/pastebin.css pastebin/templates/pastebin/widgets/captcha_field.html requirements.txt
Modified: geany/settings.py 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -330,6 +330,7 @@
# 3rd party "compressor", + "captcha", # for pastebin "django_extensions", "honeypot", # for pastebin "mezzanine_pagedown", @@ -435,6 +436,9 @@
# django-honeypot HONEYPOT_FIELD_NAME = 'website' +CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge' +CAPTCHA_NOISE_FUNCTIONS = ('captcha.helpers.noise_dots',) +CAPTCHA_MATH_CHALLENGE_OPERATOR = '*'
NIGHTLYBUILDS_BASE_DIR = '/path/to/nightly/builds'
Modified: geany/urls.py 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -61,6 +61,7 @@
# Pastebin path('p/', include('pastebin.urls')), + path('captcha/', include('captcha.urls')),
# URL Shortener #path('s/', include('urlshortener.urls')), # disabled until it is fixed for Django 4.0
Modified: pastebin/forms.py 9 lines changed, 9 insertions(+), 0 deletions(-) =================================================================== @@ -13,6 +13,7 @@
from datetime import timedelta
+from captcha.fields import CaptchaField, CaptchaTextInput from django import forms from django.utils import timezone from django.utils.translation import gettext_lazy as _ @@ -40,6 +41,10 @@ class ExpiryOptionsWidget(forms.RadioSelect): option_inherits_attrs = False
+class CaptchaTextInputWidget(CaptchaTextInput): + template_name = 'pastebin/widgets/captcha_field.html' + + class SnippetForm(forms.ModelForm):
lexer = forms.ChoiceField( @@ -55,10 +60,14 @@ class SnippetForm(forms.ModelForm): widget=ExpiryOptionsWidget, )
+ captcha = CaptchaField(widget=CaptchaTextInputWidget(attrs={ + 'placeholder': 'Please solve the challenge'})) + # ---------------------------------------------------------------------- def __init__(self, request, *args, **kwargs): forms.ModelForm.__init__(self, *args, **kwargs) self.request = request + self.fields['captcha'].label = 'Verification' # set author self.fields['author'].initial = self.request.session.get('author', '')
Modified: pastebin/static/css/pastebin.css 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -39,6 +39,10 @@ form.new-snippet-form { .new-snippet-form .form-group select { max-width: 40em; } + +.new-snippet-form-no-padding-left { + padding-left: 0; +} /* * Snippet form */
Modified: pastebin/templates/pastebin/widgets/captcha_field.html 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,6 @@ +{% spaceless %} +<div class="radio-inline new-snippet-form-no-padding-left""><img src="{{ image }}" alt="captcha" class="captcha" /></div> +<div class="radio-inline new-snippet-form-no-padding-left"> +{% include "django/forms/widgets/multiwidget.html" %} +</div> +{% endspaceless %}
Modified: requirements.txt 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -7,6 +7,7 @@ django-extensions django-honeypot django-link-shortener django-log-request-id +django-simple-captcha mezzanine-pagedown mezzanine-sync-pages packaging
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).