##// 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 'class': 'form-email'}))
59 'class': 'form-email'}))
60
60
61 session = None
61 session = None
62 need_to_ban = False
62
63
63 def clean_title(self):
64 def clean_title(self):
64 title = self.cleaned_data['title']
65 title = self.cleaned_data['title']
@@ -93,6 +94,7 b' class PostForm(NeboardForm):'
93 raise forms.ValidationError('Humans have sessions')
94 raise forms.ValidationError('Humans have sessions')
94
95
95 if cleaned_data['email']:
96 if cleaned_data['email']:
97 self.need_to_ban = True
96 raise forms.ValidationError('A human cannot enter a hidden field')
98 raise forms.ValidationError('A human cannot enter a hidden field')
97
99
98 if not self.errors:
100 if not self.errors:
@@ -249,4 +251,4 b' class LoginForm(NeboardForm):'
249
251
250 cleaned_data = super(LoginForm, self).clean()
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 if form.is_valid():
38 if form.is_valid():
39 return _new_post(request, form)
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 else:
43 else:
41 form = threadFormClass(error_class=PlainErrorList, **kwargs)
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 def tag(request, tag_name, page=0):
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 tag = get_object_or_404(Tag, name=tag_name)
113 tag = get_object_or_404(Tag, name=tag_name)
108 threads = []
114 threads = []
@@ -115,6 +121,9 b' def tag(request, tag_name, page=0):'
115 error_class=PlainErrorList)
121 error_class=PlainErrorList)
116 if form.is_valid():
122 if form.is_valid():
117 return _new_post(request, form)
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 else:
127 else:
119 form = forms.ThreadForm(initial={'tags': tag_name},
128 form = forms.ThreadForm(initial={'tags': tag_name},
120 error_class=PlainErrorList)
129 error_class=PlainErrorList)
@@ -147,6 +156,9 b' def thread(request, post_id):'
147
156
148 if form.is_valid():
157 if form.is_valid():
149 return _new_post(request, form, post_id)
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 else:
162 else:
151 form = postFormClass(error_class=PlainErrorList, **kwargs)
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 def get_post(request, post_id):
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 post = get_object_or_404(Post, id=post_id)
362 post = get_object_or_404(Post, id=post_id)
351
363
@@ -380,6 +392,7 b' def _init_default_context(request):'
380 context['theme'] = theme
392 context['theme'] = theme
381 context['theme_css'] = 'css/' + theme + '/base_page.css'
393 context['theme_css'] = 'css/' + theme + '/base_page.css'
382
394
395 # This shows the moderator panel
383 moderate = user.get_setting(SETTING_MODERATE)
396 moderate = user.get_setting(SETTING_MODERATE)
384 if moderate == 'True':
397 if moderate == 'True':
385 context['moderator'] = user.is_moderator()
398 context['moderator'] = user.is_moderator()
@@ -390,7 +403,10 b' def _init_default_context(request):'
390
403
391
404
392 def _get_user(request):
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 session = request.session
411 session = request.session
396 if not 'user_id' in session:
412 if not 'user_id' in session:
@@ -412,8 +428,21 b' def _get_user(request):'
412
428
413
429
414 def _redirect_to_next(request):
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 if 'next' in request.GET:
437 if 'next' in request.GET:
416 next_page = request.GET['next']
438 next_page = request.GET['next']
417 return HttpResponseRedirect(next_page)
439 return HttpResponseRedirect(next_page)
418 else:
440 else:
419 return redirect(index)
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