vendor/plugins/ambethia_recaptcha/lib/recaptcha.rb
# Your private API can be specified in the +options+ hash or preferably the environment
# variable +RECAPTCHA_PUBLIC_KEY+.
Your private API can be specified in the +options+ hash or preferably the environment
variable +RECAPTCHA_PUBLIC_KEY+.
Your private API can be specified in the + options + hash or preferably the environment variable + RECAPTCHA_PUBLIC_KEY + .
def verify_recaptcha(options = {})
        return true if SKIP_VERIFY_ENV.include? ENV['RAILS_ENV']
        model = options.is_a?(::ActiveRecord::Base)? options : options[:model]
        private_key = options[:private_key] ||= ENV['RECAPTCHA_PRIVATE_KEY']
        raise ReCaptchaError, "No private key specified." unless private_key
        begin
          recaptcha = Net::HTTP.post_form URI.parse("http://#{RECAPTCHA_VERIFY_SERVER}/verify"), {
            "privatekey" => private_key,
            "remoteip"   => request.remote_ip,
            "challenge"  => params[:recaptcha_challenge_field],
            "response"   => params[:recaptcha_response_field]
          }
          answer, error = recaptcha.body.split.map { |s| s.chomp }
          unless answer == 'true'
            session[:recaptcha_error] = error
            if model
              model.valid?
              if Rails::VERSION::MAJOR == 2 and Rails::VERSION::MINOR >= 2
                model.errors.add_to_base I18n.translate("#{model.class.name.underscore}.captcha", :scope => %w(activerecord errors models), :default => "Captcha response is incorrect, please try again.")
              else
                model.errors.add_to_base "Captcha response is incorrect, please try again."
              end
            end
            return false
          else
            session[:recaptcha_error] = nil
            return true
          end
        rescue Exception => e
          raise ReCaptchaError, e
        end
      end
def verify_recaptcha ( options = { } ) return true if SKIP_VERIFY_ENV . include? ENV [ 'RAILS_ENV' ] model = options . is_a? ( :: ActiveRecord :: Base ) ? options : options [ :model ] private_key = options [ :private_key ] ||= ENV [ 'RECAPTCHA_PRIVATE_KEY' ] raise ReCaptchaError , "No private key specified." unless private_key begin recaptcha = Net :: HTTP . post_form URI . parse ( "http://#{RECAPTCHA_VERIFY_SERVER}/verify" ) , { "privatekey" => private_key , "remoteip" => request . remote_ip , "challenge" => params [ :recaptcha_challenge_field ] , "response" => params [ :recaptcha_response_field ] } answer , error = recaptcha . body . split . map { | s | s . chomp } unless answer == 'true' session [ :recaptcha_error ] = error if model model . valid? if Rails :: VERSION :: MAJOR == 2 and Rails :: VERSION :: MINOR >= 2 model . errors . add_to_base I18n . translate ( "#{model.class.name.underscore}.captcha" , :scope => %w( activerecord errors models ) , :default => "Captcha response is incorrect, please try again." ) else model . errors . add_to_base "Captcha response is incorrect, please try again." end end return false else session [ :recaptcha_error ] = nil return true end rescue Exception => e raise ReCaptchaError , e end end
Your private API can be specified in the +options+ hash or preferably the environment
variable +RECAPTCHA_PUBLIC_KEY+.
Your private API can be specified in the + options + hash or preferably the environment variable + RECAPTCHA_PUBLIC_KEY + .
options
<not_specific>