From: jordan Date: Tue, 4 Jan 2011 09:21:42 +0000 (+0000) Subject: Added reCaptcha image in case the Akismet module returns spam while checking X-Git-Tag: live~469 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/9ec76fc63597e2d033bf1f1da3d27b91b41f71e0 Added reCaptcha image in case the Akismet module returns spam while checking git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@665 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/forms/general.py b/forum/forms/general.py index 1becdf0..c754e85 100644 --- a/forum/forms/general.py +++ b/forum/forms/general.py @@ -5,6 +5,7 @@ from django.utils.safestring import mark_safe from forum import settings from django.http import str_to_unicode from forum.models import User +from forum_modules.recaptcha.formfield import ReCaptchaField import urllib DEFAULT_NEXT = '/' + getattr(settings, 'FORUM_SCRIPT_ALIAS') @@ -154,3 +155,5 @@ class SetPasswordForm(forms.Form): else: return self.cleaned_data['password2'] +class SimpleCaptchaForm(forms.Form): + captcha = ReCaptchaField() diff --git a/forum_modules/akismet/startup.py b/forum_modules/akismet/startup.py index 595447c..40b13d5 100644 --- a/forum_modules/akismet/startup.py +++ b/forum_modules/akismet/startup.py @@ -7,8 +7,9 @@ from forum.modules import decorate from forum import views from lib.akismet import Akismet from forum.settings import APP_URL, OSQA_VERSION -from settings import WORDPRESS_API_KEY, REP_FOR_NO_SPAM_CHECK +from settings import WORDPRESS_API_KEY, REP_FOR_NO_SPAM_CHECK, RECAPTCHA_PUB_KEY, RECAPTCHA_PRIV_KEY from forum.models.user import User +from forum.forms.general import SimpleCaptchaForm import settings @@ -18,8 +19,8 @@ def can_bypass_spam_check(user): def check_spam(param, comment_type): def wrapper(origin, request, *args, **kwargs): - if request.POST and request.POST.get(param, None) and WORDPRESS_API_KEY and (not can_bypass_spam_check( - request.user)): + if request.POST and request.POST.get(param, None) and WORDPRESS_API_KEY and (not can_bypass_spam_check(request.user)): + comment = smart_str(request.POST[param]) data = { @@ -38,6 +39,9 @@ def check_spam(param, comment_type): api = Akismet(settings.WORDPRESS_API_KEY, APP_URL, "OSQA/%s" % OSQA_VERSION) if api.comment_check(comment, data): + post_data = request.POST + captcha_form = SimpleCaptchaForm(request.POST) + if request.is_ajax(): response = { 'success': False, @@ -45,9 +49,18 @@ def check_spam(param, comment_type): } return HttpResponse(simplejson.dumps(response), mimetype="application/json") else: - return render_to_response('modules/akismet/foundspam.html', { - 'action_name': comment_type - }) + captcha_checked = False + + if RECAPTCHA_PUB_KEY and RECAPTCHA_PRIV_KEY: + if form.is_valid(): + captcha_checked = True + + if not captcha_checked: + return render_to_response('modules/akismet/foundspam.html', { + 'action_name': comment_type, + 'post_data' : post_data, + 'captcha_form' : captcha_form, + }) return origin(request, *args, **kwargs) @@ -57,5 +70,3 @@ def check_spam(param, comment_type): decorate(views.writers.ask)(check_spam('text', _('question'))) decorate(views.writers.answer)(check_spam('text', _('answer'))) decorate(views.commands.comment)(check_spam('comment', _('comment'))) - - diff --git a/forum_modules/akismet/templates/foundspam.html b/forum_modules/akismet/templates/foundspam.html index 8c39a89..03bc660 100644 --- a/forum_modules/akismet/templates/foundspam.html +++ b/forum_modules/akismet/templates/foundspam.html @@ -11,5 +11,21 @@ We're sorry, but Akismet believes your {{ action_name }} is spam.
If you believe this is an error, please contact the forum administrator. {% endblocktrans %} + +
+ + + + + + + +
+ {% for post_item in post_data.items %} + + {% endfor %} + {{ captcha_form.captcha }}
+
+ {% endblock %} \ No newline at end of file