【发布时间】:2010-12-17 21:10:17
【问题描述】:
我需要一些非常基本的帮助。我遵循了关于让 Rails 3 和 Authlogic 一起工作的优秀教程。它与许多地方引用的相同非常基本的身份验证外壳程序相同。但我就是不能让注销功能起作用。我花了几天时间尝试各种事情。所以我需要帮助。也许这只是我没有正确理解的东西,但问题是:
底线:@user_session.destroy 不会终止会话。
详情: 我正在开发一个 Web 服务,所以我只与 .xml 格式的请求进行交互......并且我正在使用 cURL 进行测试。
除了我的主要问题外,一切正常。我用用户播种数据库。
当我在没有先登录的情况下执行以下操作并且 cookies.txt 为空白(或者是其他用户的 cookie)时 - >
curl -v -H "Accept: text/xml" -X GET --cookie cookies.txt http://localhost:3000/user.xml
我的请求按预期被拒绝(没有会话)
当我使用这个登录时 ->
curl -v -H "Accept: text/xml" -X POST -d 'user_session[email]=eric@xyz.com&user_session[password]=secret' --cookie-jar cookies.txt http://localhost:3000/user_session.xml
创建了一个新会话,然后我可以执行之前的 GET 操作。一切正常,因为使用其他用户的 cookie 不起作用,不使用 cookie 不起作用等等。
但是...当我注销时...这样做 ->
curl -v -H "Accept: text/xml" -X DELETE --cookie cookies.txt http://localhost:3000/user_session.xml
调用 UserSessionsController#destroy 操作
def destroy
@user_session = UserSession.find
@user_session.destroy
respond_to do |format|
format.html { redirect_to(:users, :notice => 'Goodbye!') }
format.xml { head :ok }
end
end
以及操作中的行 - @user_session = UserSession.find 和 @user_session.destroy 被执行。没有错误并在销毁后立即测试@user_session = UserSession.find 按预期产生 nil
但是...在下一个 GET 请求中,如果在请求中传递了现在应该过期的同一个 cookie,则会发生对该特定用户 ID 的相同数据库查找并传递信息 - 就好像会话继续存在一样! !
我知道这是基本的东西,但为了完整起见,这里是我的 ApplicationController:
class ApplicationController < ActionController::Base
#protect_from_forgery
helper_method :current_user_session, :current_user
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
def require_user
unless current_user
respond_to do |format|
format.xml { head :unauthorized }
end
return false
end
end
def require_no_user
if current_user
respond_to do |format|
format.xml { head :bad_request }
end
return false
end
end
无论我如何尝试,我都无法退出会话。当我看到缓存命中发生时,我什至钻研关闭 ActiveRecord 缓存。缓存已关闭,没有任何改变。我认为这要么是我理解的严重错误,要么是我不理解或无法正常工作的 Authlogic。
有什么想法吗??
【问题讨论】: