I have a client who is concerned that someone may discover the IP of our development server and attempt to steal new 开发者_如何学编程features before we release them. (Because we have external links and embeds, it is possible to track back while testing). I was looking for a way to password protect the server ONLY in development mode (I don't want to have to change code before every deployment). I was thinking of doing super basic authentication through a controller like:
if RAILS_ENV == "development"
collect = require_password #some action or method or something here... Figure it out later...
if collect != "foobar"
redirect_to "http://www.google.com"
end
end
I feel like this is an oddly stupid way of doing this, however, it's not like we need epic security, just something to fumble people who might stumble across the site in development mode.
In your controller add the following lines
USER_NAME, PASSWORD = "user", "password"
before_filter :authenticate_testing
The code for before_filter looks like this
def authenticate_testing
if Rails.env.development?
authenticate_or_request_with_http_basic do |user_name, password|
user_name == USER_NAME && password == PASSWORD
end
end
end
精彩评论