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')
else:
return self.cleaned_data['password2']
+class SimpleCaptchaForm(forms.Form):
+ captcha = ReCaptchaField()
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
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 = {
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,
}
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)
decorate(views.writers.ask)(check_spam('text', _('question')))
decorate(views.writers.answer)(check_spam('text', _('answer')))
decorate(views.commands.comment)(check_spam('comment', _('comment')))
-
-
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