Sha256: ccdad6f61c8164c0bfd416f9f55b3f76f38dfe0ffc63f32a233165fb1f3c061b

Contents?: true

Size: 987 Bytes

Versions: 7

Compression:

Stored size: 987 Bytes

Contents

module SimpleCaptcha #:nodoc 
  module ControllerHelpers #:nodoc
    # This method is to validate the simple captcha in controller.
    # It means when the captcha is controller based i.e. :object has not been passed to the method show_simple_captcha.
    #
    # *Example*
    #
    # If you want to save an object say @user only if the captcha is validated then do like this in action...
    #
    #  if simple_captcha_valid?
    #   @user.save
    #  else
    #   flash[:notice] = "captcha did not match"
    #   redirect_to :action => "myaction"
    #  end
    def simple_captcha_valid?
      return true if Rails.env.test?
      
      if params[:captcha]
        data = SimpleCaptcha::Utils::simple_captcha_value(params[:captcha_key] || session[:captcha])
        result = data == params[:captcha].delete(" ").upcase
        SimpleCaptcha::Utils::simple_captcha_passed!(session[:captcha]) if result
        return result
      else
        return false
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 5 rubygems

Version Path
pludoni-simple_captcha-0.1.6 lib/simple_captcha/controller.rb
galetahub-simple_captcha-0.1.5 lib/simple_captcha/controller.rb
galetahub-simple_captcha-0.1.4 lib/simple_captcha/controller.rb
loyal_simple_captcha-0.0.1 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.2.1 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.2.0 lib/simple_captcha/controller.rb
foco-simple_captcha-0.1.3 lib/simple_captcha/controller.rb