Sha256: 956be50592210fab3bbab712c1ecedc9fbd6951c561123dde45fb9a30c6c1be6

Contents?: true

Size: 986 Bytes

Versions: 10

Compression:

Stored size: 986 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(session[:captcha])
        result = (!data.nil? && data.upcase == 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

10 entries across 10 versions & 1 rubygems

Version Path
glebtv-simple_captcha-0.8.1 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.8.0 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.7.0 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.6.7 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.6.5 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.6.4 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.6.3 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.6.2 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.6.1 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.6.0 lib/simple_captcha/controller.rb