ruby-on-rails - Clear session store for a specific user in rails
问题描述
I am using the session_store cookie_store to save the sessions of my rails 4 application. Here my code
Rails.application.config.session_store :cookie_store, key: '_app_session'
My question is how can I invalidate the session of a specific user?
解决方案
您只能使当前用户的会话无效 - 通过调用reset_session
使他们的会话 ID 无效。
服务器不知道哪些会话 id 使用 cookie_store 链接到什么(数据库)用户 id。它只是跟踪有效会话标识符的列表。如果 cookie 中提供的会话标识符是有效的,那么 Rails 将解密并反序列化会话存储 cookie。这是存储用户 ID 的地方。由于用户 ID 由客户端存储,因此无法遍历会话存储并从用户 ID 中找到会话标识符。
如果您想密切关注用户会话,则需要使用不同的系统,例如使用 memcached 或数据库会话存储或访问令牌授予。
推荐阅读
- vba - 在 Word VBA 中更改图表源链接
- ant - ant 总是返回“BUILD SUCCESSFULL”也有错误
- java - 通过 T3 协议从 shell 调用 java 方法
- macros - 有没有办法在宏代码下传递一个列表?
- css - 多个 CSS 列 DL 不中断
- java - 更新查询期间的条件生成器错误:BinaryArithmeticOperation 与预期类型不匹配
- postgresql - 2 PostgreSQL 表中的主键?
- google-apps-script - 根据表单选择设置电子邮件收件人
- python-3.x - 如何计算不同的重复项
- excel - VBE7.dll的作用是什么?