From 7532ff754603f2476df75263dd9f482c147698c3 Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Fri, 31 Jul 2015 10:37:48 -0300 Subject: [PATCH] Improvements for recaptcha v1 --- lib/noosfero/api/helpers.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/noosfero/api/helpers.rb b/lib/noosfero/api/helpers.rb index a12e6bb..b3f4df1 100644 --- a/lib/noosfero/api/helpers.rb +++ b/lib/noosfero/api/helpers.rb @@ -379,12 +379,14 @@ require 'grape' request = Net::HTTP::Post.new(uri.path) request.set_form_data(verify_hash) begin - body = https.request(request).body + result = https.request(request).body.split("\n") rescue Exception => e - return render_api_error!(_('Internal captcha validation error'), 500, nil, "recaptcha error: #{e.message}") + return render_api_error!(_('Internal captcha validation error'), 500, nil, "Error validating Googles' recaptcha version 1: #{e.message}") end - body = JSON.parse(body) - body == "true\nsuccess" ? true : body + return true if result[0] == "true" + return render_api_error!(_("Wrong captcha text, please try again"), 403, nil, "Error validating Googles' recaptcha version 1: #{result[1]}") if result[1] == "incorrect-captcha-sol" + #Catches all errors at the end + return render_api_error!(_("Internal recaptcha validation error"), 500, nil, "Error validating Googles' recaptcha version 1: #{result[1]}") end def verify_recaptcha_v2(remote_ip, private_key, api_recaptcha_verify_uri, g_recaptcha_response) -- libgit2 0.21.2