开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜