Sha256: 28b3b248b2d75fc9e01ecdf8b24bab50bf7ebc6d25850e8302a2de97c9cfa745

Contents?: true

Size: 963 Bytes

Versions: 26

Compression:

Stored size: 963 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 == 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

26 entries across 26 versions & 7 rubygems

Version Path
glebtv-simple_captcha-0.5.2 lib/simple_captcha/controller.rb
wxianfeng_simple_captcha-0.5.0 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.5.1 lib/simple_captcha/controller.rb
wxianfeng_simple_captcha-0.4.0 lib/simple_captcha/controller.rb
wxianfeng_simple_captcha-0.3.0 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.4.6 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.4.5 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.4.4 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.4.3 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.4.1 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.3.1 lib/simple_captcha/controller.rb
glebtv-simple_captcha-0.1.6 lib/simple_captcha/controller.rb
nahaylo-simple_captcha-0.2.0 lib/simple_captcha/controller.rb
the_captcha-0.1.3 lib/simple_captcha/controller.rb
the_captcha-0.1.1 lib/simple_captcha/controller.rb
the_captcha-0.1.0 lib/simple_captcha/controller.rb
wxianfeng_simple_captcha-0.2.0 lib/simple_captcha/controller.rb
wxianfeng_simple_captcha-0.1.0 lib/simple_captcha/controller.rb
wolcanus-simple_captcha-0.1.6 lib/simple_captcha/controller.rb
wolcanus-simple_captcha-0.1.5 lib/simple_captcha/controller.rb