From a0465bb3429441bc9cb3742cc7213bd50f333df3 Mon Sep 17 00:00:00 2001 From: Rory McCann Date: Sat, 10 Jan 2009 23:32:17 +0000 Subject: [PATCH] Use recaptch library to check if the comment passes it --- __init__.py | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/__init__.py b/__init__.py index 4b295f1..625825e 100644 --- a/__init__.py +++ b/__init__.py @@ -47,34 +47,21 @@ def do_spamcheck(req, comment): if comment.blocked: return - key = get_recaptcha_key() - if key is None: - return + #import pdb ; pdb.set_trace() + + resp = captcha.submit( + recaptcha_challenge_field=req.values['recaptcha_challenge_field'], + recaptcha_response_field=req.values['recaptcha_response_field'], + private_key=req.app.cfg['recaptcha_spam_filter/privkey'], + remoteip=comment.submitter_ip + ) - data = { - 'key': apikey, - 'blog': req.app['blog_url'], - 'user_ip': comment.submitter_ip, - 'user_agent': USER_AGENT, - 'comment_type': 'comment', - 'comment_author': comment.author, - 'comment_author_email': comment.email, - 'comment_author_url': comment.www, - 'comment_content': comment.body - } - - # if we have a request object for testing we can provide some - # more information for akismet. - if req is not None: - data['referrer'] = req.environ.get('HTTP_REFERER', '') - for key in 'SERVER_ADDR', 'SERVER_NAME', 'SERVER_PORT', \ - 'SERVER_SOFTWARE', 'HTTP_ACCEPT', 'REMOTE_ADDR': - data[key] = req.environ.get(key, '') - - resp = send_request(apikey, True, data, 'comment-check') - if resp == 'true': + if resp.is_valid: + # Captcha passed + return + else: comment.status = COMMENT_BLOCKED_SPAM - comment.blocked_msg = BLOCKED_MSG + comment.blocked_msg = "Blocked for failing the captcha" def add_recaptcha_link(req, navigation_bar): -- 2.11.4.GIT