Browse Source

Simple flood countermeasure. #143

Ralfp 12 years ago
parent
commit
2495949095

+ 12 - 1
misago/apps/threadtype/mixins.py

@@ -1,7 +1,18 @@
 from django import forms
-from django.utils.translation import ungettext
+from django.utils import timezone
+from django.utils.translation import ungettext, ugettext_lazy as _
 from misago.utils.strings import slugify
 
+class FloodProtectionMixin(object):
+    def clean(self):
+        cleaned_data = super(FloodProtectionMixin, self).clean()
+        diff = timezone.now() - self.request.user.last_post
+        diff = diff.seconds + (diff.days * 86400)
+        if diff < 35:
+            raise forms.ValidationError(_("You can't post one message so quickly after another. Please wait a moment and try again."))
+        return cleaned_data
+
+
 class ValidateThreadNameMixin(object):
     def clean_thread_name(self):
         data = self.cleaned_data['thread_name']

+ 0 - 1
misago/apps/threadtype/posting/base.py

@@ -1,5 +1,4 @@
 from django.template import RequestContext
-from django.utils import timezone
 from misago.acl.exceptions import ACLError403, ACLError404
 from misago.apps.errors import error403, error404
 from misago.forms import FormLayout

+ 5 - 2
misago/apps/threadtype/posting/forms.py

@@ -1,11 +1,14 @@
 from django import forms
 from django.conf import settings
+from django.utils import timezone
 from django.utils.translation import ugettext_lazy as _
-from misago.apps.threadtype.mixins import ValidateThreadNameMixin, ValidatePostLengthMixin
+from misago.apps.threadtype.mixins import (FloodProtectionMixin,
+                                           ValidateThreadNameMixin,
+                                           ValidatePostLengthMixin)
 from misago.forms import Form
 from misago.validators import validate_sluggable
 
-class PostingForm(Form, ValidatePostLengthMixin):
+class PostingForm(FloodProtectionMixin, Form, ValidatePostLengthMixin):
     include_thread_weight = True
     include_close_thread = True
     post = forms.CharField(widget=forms.Textarea)

+ 3 - 2
misago/apps/threadtype/thread/forms.py

@@ -1,6 +1,7 @@
 from django import forms
 from misago.forms import Form
-from misago.apps.threadtype.mixins import ValidatePostLengthMixin
+from misago.apps.threadtype.mixins import (FloodProtectionMixin,
+                                           ValidatePostLengthMixin)
 
-class QuickReplyForm(Form, ValidatePostLengthMixin):
+class QuickReplyForm(FloodProtectionMixin, Form, ValidatePostLengthMixin):
     post = forms.CharField(widget=forms.Textarea)