设计退出
上次我问这个问题,我被误解了。所以:
在我的 Rails3 应用程序中,我使用 Devise 进行身份验证。我的要求是,每个用户只能从一个浏览器登录。这意味着如果用户A已登录(例如在FF上),然后从其他计算机或其他浏览器(例如Chrome)发出登录用户A的请求,则第一个应该注销。
我发现我可以重写 SessionController 及其创建方法。但是,我没有看到任何方法来检查具有给定电子邮件(params[:email])的用户当前是否已登录,此外,我不知道应该调用哪个方法来销毁此用户会话。
last time, I asked this question I have been misunderstood. So:
In my Rails3 application I use Devise for authentication. I have requirement which says, that every user can be logged in only from one browser. It means if user A is logged in (e.g. on FF), and then from other computer, or from other browser (e.g. Chrome) comes request to log user A, the first one should be logged out.
I found out, that I can override SessionController and it's create method. However I don't see any way to check if user with given email (params[:email]) is currently logged in, furthermore I don't know which method should I invoke to destroy this user session.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是为会话中的每个页面加载存储一个时间戳。将 before_filter 中的值与用户的 last_seen 字段进行比较。如果用户最后一次见到是在会话时间戳之后,则销毁用户会话。
I'd just store a timestamp for each page load in the session. Compare this in a before_filter with a last_seen field of user. If the user last seen is after the session timestamp destroy the user session.
我采取的方法是修改可跟踪或lastseen插件,然后使用典狱长回调。
https://github.com/hassox/warden/wiki/Callbacks
不是一个很好的答案,但也许可以帮助您开始。
The approach I would take would be to modify the trackable or lastseen plugin and then use a warden callback.
https://github.com/hassox/warden/wiki/Callbacks
Not a great answer, but maybe can get you started.