Commit 7532ff754603f2476df75263dd9f482c147698c3
1 parent
34dfadc0
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Improvements for recaptcha v1
Showing
1 changed file
with
6 additions
and
4 deletions
Show diff stats
lib/noosfero/api/helpers.rb
... | ... | @@ -379,12 +379,14 @@ require 'grape' |
379 | 379 | request = Net::HTTP::Post.new(uri.path) |
380 | 380 | request.set_form_data(verify_hash) |
381 | 381 | begin |
382 | - body = https.request(request).body | |
382 | + result = https.request(request).body.split("\n") | |
383 | 383 | rescue Exception => e |
384 | - return render_api_error!(_('Internal captcha validation error'), 500, nil, "recaptcha error: #{e.message}") | |
384 | + return render_api_error!(_('Internal captcha validation error'), 500, nil, "Error validating Googles' recaptcha version 1: #{e.message}") | |
385 | 385 | end |
386 | - body = JSON.parse(body) | |
387 | - body == "true\nsuccess" ? true : body | |
386 | + return true if result[0] == "true" | |
387 | + 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" | |
388 | + #Catches all errors at the end | |
389 | + return render_api_error!(_("Internal recaptcha validation error"), 500, nil, "Error validating Googles' recaptcha version 1: #{result[1]}") | |
388 | 390 | end |
389 | 391 | |
390 | 392 | def verify_recaptcha_v2(remote_ip, private_key, api_recaptcha_verify_uri, g_recaptcha_response) | ... | ... |