Sha256: 0849695dbfa0e525f33fc4a43e904b06824c681d3d018e7c1804f1ea9274f563

Contents?: true

Size: 1007 Bytes

Versions: 1

Compression:

Stored size: 1007 Bytes

Contents

module SoaringSimpleCaptcha #: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 = SoaringSimpleCaptcha::Utils::simple_captcha_value(params[:captcha_key] || session[:captcha])
        result = data == params[:captcha].delete(" ").upcase
        SoaringSimpleCaptcha::Utils::simple_captcha_passed!(session[:captcha]) if result
        return result
      else
        return false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soaring_simple_captcha-0.1.6 lib/soaring_simple_captcha/controller.rb