]> git.openstreetmap.org Git - osqa.git/commitdiff
Added reCaptcha image in case the Akismet module returns spam while checking
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 4 Jan 2011 09:21:42 +0000 (09:21 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 4 Jan 2011 09:21:42 +0000 (09:21 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@665 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms/general.py
forum_modules/akismet/startup.py
forum_modules/akismet/templates/foundspam.html

index 1becdf0edd52c648520c32394380bb3ff50dfd47..c754e859ea40154000d26ede38e3d81c8fa039a7 100644 (file)
@@ -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()
index 595447c30274ea2519651ead38955493859b138c..40b13d50f6f2b6250a7d774d4472934e01061d4e 100644 (file)
@@ -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')))
-
-
index 8c39a8927f19b32db355ff980f0f0cf194fa476b..03bc660bd19ade70cba1fb19e5e7ed1ac27883c5 100644 (file)
 We're sorry, but Akismet believes your {{ action_name }} is spam.<br />
 If you believe this is an error, please contact the forum administrator.
 {% endblocktrans %}
+
+<form action="." method="post">
+<table>
+       <tr>
+               <td>
+               {% for post_item in post_data.items %}
+               <input type="hidden" name="{{ post_item.0 }}" value="{{ post_item.1 }}" />
+               {% endfor %}
+               {{ captcha_form.captcha }}</td>
+       </tr>
+       <tr>
+               <td><input type="submit" value"{% trans "Submit" %} /></td>
+       </tr>
+</table>
+</form>
+
 </div>
 {% endblock %}
\ No newline at end of file