rails http basic authentication
in the view file, how can i ,check whether the user is authenticated? is there any helper methods like signe开发者_JAVA技巧d_in?
, logged_in?
etc. ?
No, when using basic http auth you have to manage the session by yourself:
authenticate_or_request_with_http_basic do |id, password|
if id == USER_ID && password == PASSWORD
session[:logged_in] = true
return true
else
return false
end
end
But there are many plugins which provide authentication in rails. Look here for example:
http://www.themomorohoax.com/2009/02/21/rails-2-3-authentication-comparison
(update)
okay, based on your other question, you can just put a before_filter at every controller/method you want to secure. the user will then be prompted for a password the first time he calls a secured method and the browser caches it after that.
Here's a list of the most common Rails authentication solutions.
精彩评论