Sha256: 3f1c946038c00459dcb76962005453a695d21aa856a6e4a0400988efb37534fc

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

module CommonThread
  module Filters
    protected

    # Filter method to enforce a SSL requirement.
    #
    # To require SSL for all actions, use this in your controllers:
    #
    #   before_filter :ssl_required
    #
    # To require SSL for specific actions, use this in your controllers:
    #
    #   before_filter :ssl_required, :only => [ :edit, :update ]
    #
    # To skip this in a subclassed controller:
    #
    #   skip_before_filter :ssl_required
    #
    def ssl_required
      if !(RAILS_ENV == 'development' or RAILS_ENV == 'test') and !request.ssl?
        redirect_to "https://" + request.host + request.request_uri
        return false
      end
    end

    # Filter method to enforce that no one is logged in. Requires that you have logged_in? implemented.
    #
    # To require anonomous for all actions, use this in your controllers:
    #
    #   before_filter :anonomous_required
    #
    # To require anonomous for specific actions, use this in your controllers:
    #
    #   before_filter :anonomous_required, :only => [ :edit, :update ]
    #
    # To skip this in a subclassed controller:
    #
    #   skip_before_filter :anonomous_required
    #
    def anonomous_required
      !logged_in? || redirect_back_or_default('/')
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
commonthread-rails-0.4.2 lib/commonthread/filters.rb
commonthread-rails-0.4.1 lib/commonthread/filters.rb
commonthread-rails-0.4.0 lib/commonthread/filters.rb
commonthread-rails-0.3.4 lib/commonthread/filters.rb
commonthread-rails-0.3.3 lib/commonthread/filters.rb
commonthread-rails-0.3.2 lib/commonthread/filters.rb
commonthread-rails-0.3.1 lib/commonthread/filters.rb
commonthread-rails-0.3.0 lib/commonthread/filters.rb
commonthread-rails-0.2.5 lib/commonthread/filters.rb
commonthread-rails-0.2.4 lib/commonthread/filters.rb
commonthread-rails-0.2.3 lib/commonthread/filters.rb