Revert anti-spam removal

The anti-spam code is actually useful to us, so lets add it back
This commit is contained in:
Andrew Hutchings 2012-03-22 16:52:10 +00:00
parent eeb27e5e5b
commit 3e968eeb0d
6 changed files with 69 additions and 2 deletions

View File

@ -11,12 +11,14 @@
from werkzeug import redirect, Response
from werkzeug.exceptions import NotFound
from lodgeit import local
from lodgeit.i18n import list_languages as i18n_list_languages
from lodgeit.lib import antispam
from lodgeit.i18n import list_languages as i18n_list_languages, _
from lodgeit.utils import render_to_response, url_for
from lodgeit.models import Paste
from lodgeit.database import session
from lodgeit.lib.highlighting import list_languages, STYLES, get_style
from lodgeit.lib.pagination import generate_pagination
from lodgeit.lib.captcha import check_hashed_solution, Captcha
class PasteController(object):
@ -30,7 +32,7 @@ class PasteController(object):
language = local.request.session.get('language', 'text')
code = error = ''
private = False
show_captcha = private = False
parent = None
req = local.request
getform = req.form.get
@ -39,6 +41,19 @@ class PasteController(object):
code = getform('code', u'')
language = getform('language')
parent_id = getform('parent')
spam = getform('webpage') or antispam.is_spam(code)
if spam:
error = _('your paste contains spam')
captcha = getform('captcha')
if captcha:
if check_hashed_solution(captcha):
error = None
else:
error = _('your paste contains spam and the '
'CAPTCHA solution was incorrect')
show_captcha = True
if code and language and not error:
paste = Paste(code, language, parent_id, req.user_hash,
'private' in req.form)
@ -65,6 +80,7 @@ class PasteController(object):
code=code,
language=language,
error=error,
show_captcha=show_captcha,
private=private
)
@ -181,4 +197,8 @@ class PasteController(object):
return render_to_response('rss.html', items=items,
mimetype='application/rss+xml')
def show_captcha(self):
"""Show a captcha."""
return Captcha().get_response(set_cookie=True)
controller = PasteController

View File

@ -21,6 +21,10 @@ msgstr ""
msgid "your paste contains spam"
msgstr "Dein Paste beinhaltet Spam"
#: lodgeit/controllers/pastes.py:51
msgid "your paste contains spam and the CAPTCHA solution was incorrect"
msgstr "Dein Paste beinhaltet Spam und die CAPTCHA-Eingabe war falsch"
#: lodgeit/controllers/static.py:20
msgid "Pasting"
msgstr "Pasting"
@ -552,6 +556,14 @@ msgstr "Ein Fehler ist aufgetreten"
msgid "Could not submit your paste because %(error)s."
msgstr "Konnte den Paste nicht senden, da Fehler aufgetreten sind: %(error)s"
#: lodgeit/views/new_paste.html:12
msgid "Please fill out the CAPTCHA to proceed:"
msgstr "Bitte fülle das CAPTCHA Feld aus um fortzufahren"
#: lodgeit/views/new_paste.html:13
msgid "a captcha you can't see. Sorry :("
msgstr "ein Captcha das du nicht sehen kannst. Tut mir leid :("
#: lodgeit/views/new_paste.html:17
msgid "hide this message"
msgstr "verberge diese Nachricht"

View File

@ -21,6 +21,9 @@ msgstr ""
msgid "your paste contains spam"
msgstr ""
#: lodgeit/controllers/pastes.py:51
msgid "your paste contains spam and the CAPTCHA solution was incorrect"
msgstr ""
#: lodgeit/controllers/static.py:20
msgid "Pasting"
@ -496,6 +499,14 @@ msgstr ""
msgid "Could not submit your paste because %(error)s."
msgstr ""
#: lodgeit/views/new_paste.html:12
msgid "Please fill out the CAPTCHA to proceed:"
msgstr ""
#: lodgeit/views/new_paste.html:13
msgid "a captcha you can't see. Sorry :("
msgstr ""
#: lodgeit/views/new_paste.html:17
msgid "hide this message"
msgstr ""

View File

@ -179,6 +179,19 @@ div.related h3 a {
text-decoration: none;
}
div.notification div.captcha {
margin: 10px;
}
div.notification div.captcha p {
padding: 0;
}
div.notification div.captcha img {
display: block;
margin: 8px 0 8px 0;
}
div.related h3 a:hover,
div.paste_filter h3 a:hover {
background-color: #739BA5;

View File

@ -21,6 +21,9 @@ urlmap = Map([
Rule('/unidiff/<new_id>/<old_id>/', endpoint='pastes/unidiff_paste'),
Rule('/tree/<identifier>/', endpoint='pastes/show_tree'),
# captcha for new paste
Rule('/_captcha.png', endpoint='pastes/show_captcha'),
# paste list
Rule('/all/', endpoint='pastes/show_all'),
Rule('/all/<int:page>/', endpoint='pastes/show_all'),

View File

@ -7,7 +7,15 @@
<div class="notification">
<h3>{% trans %}Error While Pasting{% endtrans %}</h3>
<p>{% trans error=error|e %}Could not submit your paste because {{ error }}.{% endtrans %}</p>
{% if show_captcha %}
<div class="captcha">
<p>{% trans %}Please fill out the CAPTCHA to proceed:{% endtrans %}</p>
<img src="/_captcha.png" alt="{% trans %}a captcha you can't see. Sorry :({% endtrans %}">
<input type="text" name="captcha" size="20" />
</div>
{%- else %}
<p><a href="javascript:LodgeIt.hideNotification()">{% trans %}hide this message{% endtrans %}</a></p>
{%- endif %}
</div>
{% endif %}
{% if parent %}