任何人都知道如何通过RoR上的session_id找到会话? 我在我的项目中使用Authlogic我不知道这是否与之相关rubyonrails:如何通过session_id查找会话
0
A
回答
0
我自己没有必须这样做,我不确定为什么有人可能需要这样做。
翻阅源代码,我可以看到有可能是这样做的一种方式。
在Authlogic :: Session :: Persistence模块中有一个find方法。您可以拨打使用UserSession.find这种方法,它似乎具有搜索能力基础上的session_id
# This is how you persist a session. This finds the record for the current session using
# a variety of methods. It basically tries to "log in" the user without the user having
# to explicitly log in. Check out the other Authlogic::Session modules for more information.
#
# The best way to use this method is something like:
#
# helper_method :current_user_session, :current_user
#
# 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.user
# end
#
# Also, this method accepts a single parameter as the id, to find session that you marked with an id:
#
# UserSession.find(:secure)
#
# See the id method for more information on ids.
def find(id = nil, priority_record = nil)
session = new({:priority_record => priority_record}, id)
session.priority_record = priority_record
if session.persisting?
session
else
nil
end
end
end
该方法的文档是指Authlogic :: Session类。
在Authlogic :: Session :: Session :: Config中,它表示会话密钥可以是cookie密钥,字符串或符号。
module Config
# Works exactly like cookie_key, but for sessions. See cookie_key for more info.
#
# * <tt>Default:</tt> cookie_key
# * <tt>Accepts:</tt> Symbol or String
def session_key(value = nil)
rw_config(:session_key, value, cookie_key)
end
alias_method :session_key=, :session_key
end
因此,在随后它试图找到当前会话的方法,我们可以看到,如果RECORD_ID不为零然后查找使用该密钥对会话。
def persist_by_session
persistence_token, record_id = session_credentials
if !persistence_token.nil?
# Allow finding by persistence token, because when records are created the session is maintained in a before_save, when there is no id.
# This is done for performance reasons and to save on queries.
record = record_id.nil? ?
search_for_record("find_by_persistence_token", persistence_token) :
search_for_record("find_by_#{klass.primary_key}", record_id)
self.unauthorized_record = record if record && record.persistence_token == persistence_token
valid?
else
false
end
end
record_id是使用session_credentials方法创建的。这似乎是基于提供给控制器
def session_credentials
[controller.session[session_key], controller.session["#{session_key}_#{klass.primary_key}"]].compact
end
def session_key
build_key(self.class.session_key)
end
我收集这个最由Github通过源浏览键生成会话密钥。如果您需要更多帮助,那可能是开始寻找的最佳地点。
希望这会有所帮助
相关问题
- 1. session_id,cookie,会话管理
- 2. 在Ruby On Rails中使用session_id检索会话?
- 3. 未通过InitialContext查找找到Java会话门面
- 4. 如何检查用户何时通过会话过期退出
- 5. PHP session_id()不接受现有会话ID
- 6. 获取所有PHP会话列表session_id
- 7. php session_id算法没有会话?
- 8. 跨域使用session_id传输会话
- 9. 如果删除包含session_id的cookie,如何保留会话ID?
- 10. PHP - 如果我知道SESSION_ID,如何获取会话变量
- 11. Ruby/Rails通过ID查找对象
- 12. 通过Memcache的Django会话:手动找不到会话密钥
- 13. 如何通过会话ID找到设计用户?
- 14. JSF通过会话
- 15. ASP.net显示LoginStatus通过检查会话
- 16. 如何通知用户会话过期
- 17. 如何通过node.js获取codeigniter会话
- 18. 如何通过fancyupload传递会话
- 19. 如何通过会话变量的href
- 20. HTA - 如何通过点击按钮触发查找对话框?
- 21. 在zend中,如何通过ID检查会话是否存在?
- 22. 如何查看php会话是否已通过jquery设置
- 23. 通过协会查找模型
- 24. Rails的查找通过协会,地点
- 25. 通过查找
- 26. 通过会话通过ahref登录?
- 27. IRb:如何通过预先加载的类启动交互式ruby会话
- 28. 通过ID检索会话
- 29. 通过HTTP的APL会话?
- 30. 通过url传播会话