Rails Recaptcha plugin always returns false

你离开我真会死。 提交于 2019-12-04 18:23:38

Just as a note, make sure you didn't accidentally switch around the public and private keys; they are different.

I can't tell if you're already handling the possibility that it is correct, in which case you would want to have something like this:

if verify_recaptcha
  @thing.save!
  redirect_to success_path
else
  flash[:error] = "There was an error with the recaptcha code below. Please re-enter the code and click submit." 
  render :action => 'new'
end

And remember to use:

<%= recaptcha_tags :ssl => true %>

If you are using SSL.

I went in and looked at the recaptcha plugin. The pertinent part reads something like this:

recaptcha = Net::HTTP.post_form URI.parse("http://#{server}/verify"), {
            "privatekey" => private_key,
            "remoteip"   => request.remote_ip,
            "challenge"  => challenge,
            "response"   => response
          }

This takes the challenge and response and returns a response. When I tried it with a challenge and response I generated, I got "true\nsuccess". The following lines of code return false if:

answer, error = recaptcha.body.split.map { |s| s.chomp }
unless answer == "true"

Since I got back "true\nsuccess", answer will be "true", and the code should therefore pass.

Can you try sending the response directly using Net::HTTP and seeing what response you get?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!