Commit 88a604edea37c642032058ed0e27ab972a156887

Authored by Evandro Junior
1 parent 838caf49

Captcha check for validation server timeout

lib/noosfero/api/helpers.rb
... ... @@ -392,7 +392,7 @@ require 'grape'
392 392 end
393 393  
394 394 def verify_serpro_captcha(client_id, token, captcha_text, verify_uri)
395   - return render_api_error!(_("Error processing token validation"), 500, nil, _("Missing Serpro's Captcha token")) unless token
  395 + return render_api_error!(_("Error processing token validation"), 500, nil, "Missing Serpro's Captcha token") unless token
396 396 return render_api_error!(_('Captcha text has not been filled'), 403) unless captcha_text
397 397 uri = URI(verify_uri)
398 398 http = Net::HTTP.new(uri.host, uri.port)
... ... @@ -404,10 +404,13 @@ require 'grape'
404 404 rescue Exception => e
405 405 return render_api_error!(_('Internal captcha validation error'), 500, nil, "Serpro captcha error: #{e.message}")
406 406 end
  407 + return true if body == '1'
  408 + return render_api_error!(_("Internal captcha validation error"), 500, body, "Unable to reach Serpro's Captcha validation service") if body == "Activity timed out"
407 409 return render_api_error!(_("Wrong captcha text, please try again"), 403) if body == 0
408   - return render_api_error!(_("Token not found"), 500) if body == 2
  410 + return render_api_error!(_("Serpro's captcha token not found"), 500) if body == 2
409 411 return render_api_error!(_("No data sent to validation server or other serious problem"), 500) if body == -1
410   - body == '1' ? true : body
  412 + #Catches all errors at the end
  413 + return render_api_error!(_("Internal captcha validation error"), 500, nil, "Error validating Serpro's captcha #{body}")
411 414 end
412 415  
413 416 end
... ...
lib/noosfero/api/session.rb
... ... @@ -40,7 +40,7 @@ module Noosfero
40 40 attrs = attributes_for_keys [:email, :login, :password, :password_confirmation] + environment.signup_person_fields
41 41 remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR'])
42 42 # test_captcha will render_api_error! and exit in case of some problem
43   - # this return is only improve the clarity of the execution path
  43 + # this return is only improve the clarity of the execution path
44 44 return unless test_captcha(remote_ip, params, environment)
45 45 user = User.new(attrs)
46 46 if user.save
... ...