开发者

Ruby on Rails: how do I make an http password protected sub domain?

I want a subdomain like... admin.example.com

but I want it to require a user and password.开发者_StackOverflow中文版 Like... the kind that uses teh browser's interface, rather than a database backed authentication system.

what are some good methods of doing this?


It's fairly simple:

# products_controller.rb
before_filter :authenticate

protected

def authenticate
  authenticate_or_request_with_http_basic do |username, password|
    username == "foo" && password == "bar"
  end
end

See: http://railscasts.com/episodes/82-http-basic-authentication


Write a small rack application. Both checking if its the correct subdomain and enforcing basic auth can be done easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜