Sha256: 26e2f4242172e6e34c56df2e10fb189f09468afe38cf44bb44cc3662a4223291
Contents?: true
Size: 1.56 KB
Versions: 37
Compression:
Stored size: 1.56 KB
Contents
# Code adapted from http://github.com/rails/ssl_requirement module MuckEngine module SslRequirement extend ActiveSupport::Concern included do before_filter :ensure_proper_protocol end module ClassMethods # Specifies that the named actions requires an SSL connection to be performed (which is enforced by ensure_proper_protocol). def ssl_required(*actions) write_inheritable_array(:ssl_required_actions, actions) end def ssl_allowed(*actions) write_inheritable_array(:ssl_allowed_actions, actions) end end protected # Only require ssl if we are in production def ssl_required? return ENV['SSL'] == 'on' ? true : false if defined? ENV['SSL'] return false if local_request? return false if RAILS_ENV == 'test' ((self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)) && (::Rails.env == 'production' || ::Rails.env == 'staging') end def ssl_allowed? (self.class.read_inheritable_attribute(:ssl_allowed_actions) || []).include?(action_name.to_sym) end private def ensure_proper_protocol return true if ssl_allowed? if ssl_required? && !request.ssl? redirect_to "https://" + request.host + request.fullpath flash.keep return false elsif request.ssl? && !ssl_required? redirect_to "http://" + request.host + request.fullpath flash.keep return false end end end end
Version data entries
37 entries across 37 versions & 1 rubygems