Skip to content
This repository has been archived by the owner. It is now read-only.

Support for checking if other actions are ssl required/enabled in the sa... #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/ssl_requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ def ssl_allowed(*actions)
write_inheritable_array(:ssl_allowed_actions, actions)
end
end

protected
# Returns true if the current action is supposed to run as SSL
def ssl_required?
(self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)
def ssl_required?(action = action_name)
(self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action.to_sym)
end
def ssl_allowed?
(self.class.read_inheritable_attribute(:ssl_allowed_actions) || []).include?(action_name.to_sym)

def ssl_allowed?(action = action_name)
(self.class.read_inheritable_attribute(:ssl_allowed_actions) || []).include?(action.to_sym)
end

private
def ensure_proper_protocol
return true if ssl_allowed?

if ssl_required? && !request.ssl?
redirect_to "https://" + request.host + request.request_uri
redirect_to "https://" + request.host + request.request_uri, :status => :moved_permanently
flash.keep
return false
elsif request.ssl? && !ssl_required?
Expand All @@ -59,4 +59,4 @@ def ensure_proper_protocol
return false
end
end
end
end