2011-03-23 24 views
2

我有一个客户担心有人可能会发现我们的开发服务器的IP,并试图在我们发布之前窃取新功能。 (因为我们有外部链接和嵌入,所以可以在测试时跟踪回来)。我正在寻找一种仅在开发模式下密码保护服务器的方法(我不想在每次部署之前更改代码)。我是通过像控制器想这样做超级基本身份验证:在开发模式下密码保护杂种

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 

我喜欢这种感觉是这样的一个奇怪的笨方法,但是,它并不像我们所需要史诗般的安全性,只是要摸索的人谁可能在开发模式中偶然发现网站。

回答

1

在你的控制器中添加以下行

USER_NAME, PASSWORD = "user", "password" 
    before_filter :authenticate_testing 

为的before_filter的代码看起来像这样

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 
+0

史诗码位,在这里。完美适用于此应用程序。 – 2011-03-25 16:36:21