您不需要对UserSessionController
做任何事情,因为该控制器只会处理登录表单提交和注销。
Authlogic和authenticate_with_http_basic
是互不相关的。如果你想通过HTTP基本认证,你只需要创建一个方法来使用Rails提供的方法进行认证,并将该方法放在before_filter
上。通过HTTP身份验证登录,我认为每个请求都应该使用用户名和密码。
所以最后,你ProductsController
会像通过HTTP验证这
class ProductsController < ApplicationController
before_filter :authenticate_via_http_basic
# In case you have some method to redirect user to login page, skip it
skip_before_filter :require_authentication
...
protected
def authenticate_via_http_basic
unless current_user
authenticate_with_http_basic do |username, password|
if user = User.find_by_username(username)
user.valid_password?(password)
else
false
end
end
end
end
嗨,这是现在的工作。但是在控制器上集成http_basic_athentication之后,基于UserSession的身份验证现在不起作用。我总是得到http_basic_athentication登录提示符。 – randika 2009-11-11 13:21:09
对不起,延迟回复。我更新了答案:) – sikachu 2009-11-16 09:48:21