##// END OF EJS Templates
Added autoban by the hidden field (to ban spammers and prevent them from trying to post anything).
neko259 -
r271:ac659dae default
parent child Browse files
Show More
@@ -59,6 +59,7 b' class PostForm(NeboardForm):'
59 59 'class': 'form-email'}))
60 60
61 61 session = None
62 need_to_ban = False
62 63
63 64 def clean_title(self):
64 65 title = self.cleaned_data['title']
@@ -93,6 +94,7 b' class PostForm(NeboardForm):'
93 94 raise forms.ValidationError('Humans have sessions')
94 95
95 96 if cleaned_data['email']:
97 self.need_to_ban = True
96 98 raise forms.ValidationError('A human cannot enter a hidden field')
97 99
98 100 if not self.errors:
@@ -249,4 +251,4 b' class LoginForm(NeboardForm):'
249 251
250 252 cleaned_data = super(LoginForm, self).clean()
251 253
252 return cleaned_data No newline at end of file
254 return cleaned_data
@@ -37,6 +37,9 b' def index(request, page=0):'
37 37
38 38 if form.is_valid():
39 39 return _new_post(request, form)
40 if form.need_to_ban:
41 # Ban user because he is suspected to be a bot
42 _ban_current_user(request)
40 43 else:
41 44 form = threadFormClass(error_class=PlainErrorList, **kwargs)
42 45
@@ -102,7 +105,10 b' def _new_post(request, form, thread_id=b'
102 105
103 106
104 107 def tag(request, tag_name, page=0):
105 """Get all tag threads (posts without a parent)."""
108 """
109 Get all tag threads. Threads are split in pages, so some page is
110 requested. Default page is 0.
111 """
106 112
107 113 tag = get_object_or_404(Tag, name=tag_name)
108 114 threads = []
@@ -115,6 +121,9 b' def tag(request, tag_name, page=0):'
115 121 error_class=PlainErrorList)
116 122 if form.is_valid():
117 123 return _new_post(request, form)
124 if form.need_to_ban:
125 # Ban user because he is suspected to be a bot
126 _ban_current_user(request)
118 127 else:
119 128 form = forms.ThreadForm(initial={'tags': tag_name},
120 129 error_class=PlainErrorList)
@@ -147,6 +156,9 b' def thread(request, post_id):'
147 156
148 157 if form.is_valid():
149 158 return _new_post(request, form, post_id)
159 if form.need_to_ban:
160 # Ban user because he is suspected to be a bot
161 _ban_current_user(request)
150 162 else:
151 163 form = postFormClass(error_class=PlainErrorList, **kwargs)
152 164
@@ -345,7 +357,7 b' def api_get_post(request, post_id):'
345 357
346 358
347 359 def get_post(request, post_id):
348 """ Get the html of a post. Used for popups. """
360 """Get the html of a post. Used for popups."""
349 361
350 362 post = get_object_or_404(Post, id=post_id)
351 363
@@ -380,6 +392,7 b' def _init_default_context(request):'
380 392 context['theme'] = theme
381 393 context['theme_css'] = 'css/' + theme + '/base_page.css'
382 394
395 # This shows the moderator panel
383 396 moderate = user.get_setting(SETTING_MODERATE)
384 397 if moderate == 'True':
385 398 context['moderator'] = user.is_moderator()
@@ -390,7 +403,10 b' def _init_default_context(request):'
390 403
391 404
392 405 def _get_user(request):
393 """Get current user from the session"""
406 """
407 Get current user from the session. If the user does not exist, create
408 a new one.
409 """
394 410
395 411 session = request.session
396 412 if not 'user_id' in session:
@@ -412,8 +428,21 b' def _get_user(request):'
412 428
413 429
414 430 def _redirect_to_next(request):
431 """
432 If a 'next' parameter was specified, redirect to the next page. This is
433 used when the user is required to return to some page after the current
434 view has finished its work.
435 """
436
415 437 if 'next' in request.GET:
416 438 next_page = request.GET['next']
417 439 return HttpResponseRedirect(next_page)
418 440 else:
419 441 return redirect(index)
442
443
444 def _ban_current_user(request):
445 """Add current user to the IP ban list"""
446
447 ip = utils.get_client_ip(request)
448 Ban.objects.get_or_create(ip=ip)
General Comments 0
You need to be logged in to leave comments. Login now