Created
January 15, 2013 04:15
-
-
Save agoodman/4535983 to your computer and use it in GitHub Desktop.
bad ssl practice in controller logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BadSslController < ApplicationController | |
before_filter :enforce_https | |
def enforce_https | |
if use_ssl? | |
if request.protocol != 'https://' | |
redirect_to url_for(controller: controller_name, action: action_name, protocol: 'https') and return | |
end | |
else | |
if request.protocol != 'http://' | |
redirect_to url_for(controller: controller_name, action: action_name, protocol: 'http') and return | |
end | |
end | |
end | |
def use_ssl? | |
if controller_name=='orders' | |
if action_name=='index' || action_name=='show' | |
true | |
else | |
false | |
end | |
elsif controller_name=='troops' | |
if action_name=='index' || action_name=='show' | |
true | |
else | |
false | |
end | |
elsif controller_name=='generals' | |
true | |
end | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment