From 88a604edea37c642032058ed0e27ab972a156887 Mon Sep 17 00:00:00 2001 From: Evandro Junior Date: Sat, 25 Jul 2015 10:41:20 -0300 Subject: [PATCH] Captcha check for validation server timeout --- lib/noosfero/api/helpers.rb | 9 ++++++--- lib/noosfero/api/session.rb | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/noosfero/api/helpers.rb b/lib/noosfero/api/helpers.rb index a65b4f7..89bcd4c 100644 --- a/lib/noosfero/api/helpers.rb +++ b/lib/noosfero/api/helpers.rb @@ -392,7 +392,7 @@ require 'grape' end def verify_serpro_captcha(client_id, token, captcha_text, verify_uri) - return render_api_error!(_("Error processing token validation"), 500, nil, _("Missing Serpro's Captcha token")) unless token + return render_api_error!(_("Error processing token validation"), 500, nil, "Missing Serpro's Captcha token") unless token return render_api_error!(_('Captcha text has not been filled'), 403) unless captcha_text uri = URI(verify_uri) http = Net::HTTP.new(uri.host, uri.port) @@ -404,10 +404,13 @@ require 'grape' rescue Exception => e return render_api_error!(_('Internal captcha validation error'), 500, nil, "Serpro captcha error: #{e.message}") end + return true if body == '1' + return render_api_error!(_("Internal captcha validation error"), 500, body, "Unable to reach Serpro's Captcha validation service") if body == "Activity timed out" return render_api_error!(_("Wrong captcha text, please try again"), 403) if body == 0 - return render_api_error!(_("Token not found"), 500) if body == 2 + return render_api_error!(_("Serpro's captcha token not found"), 500) if body == 2 return render_api_error!(_("No data sent to validation server or other serious problem"), 500) if body == -1 - body == '1' ? true : body + #Catches all errors at the end + return render_api_error!(_("Internal captcha validation error"), 500, nil, "Error validating Serpro's captcha #{body}") end end diff --git a/lib/noosfero/api/session.rb b/lib/noosfero/api/session.rb index 4503910..58a6c18 100644 --- a/lib/noosfero/api/session.rb +++ b/lib/noosfero/api/session.rb @@ -40,7 +40,7 @@ module Noosfero attrs = attributes_for_keys [:email, :login, :password, :password_confirmation] + environment.signup_person_fields remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR']) # test_captcha will render_api_error! and exit in case of some problem - # this return is only improve the clarity of the execution path + # this return is only improve the clarity of the execution path return unless test_captcha(remote_ip, params, environment) user = User.new(attrs) if user.save -- libgit2 0.21.2