设计会话限制 [英] Devise Session Limit

查看:157
本文介绍了设计会话限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails应用程序运行Rails 3.2.6和Devise 2.1.2,我想能够将并发登录限制为1.我已经尝试使用Devise安全扩展,但继续获得一个未定义的unique_session_id的方法。 / p>

相反,我想看看是否可以覆盖Devise的行为,如本文中所述:一次限制每个用户的一个会话



我明白它是如何工作的我已经生成了一个会话控制器,但我不知道如何强制应用程序将其用作Devise的覆盖。还应该在控制器中继承Application Controller或Devise Controller?



现在所有的一切都已经存在了,但应用程序没有写一个login_token来告诉我我没有正确使用控制器或其他可能是不好的。



任何帮助不胜感激。

解决方案

我强烈推荐你请查看 Devise Wiki 。有可能在做这样的事情时,可以在那里找到答案。您的新控制器将需要从Devise Sessions Controller继承:

  class MySessionsController< Devise :: SessionsController 

这样,你没有专门覆盖的任何方法仍然会被调用,因此不会打破其他功能。



为了确保Devise使用您的控制器而不是自己的控制器,请使您的 devise_for 调用 routes.rb 看起来如下:

  devise_for:users, :controllers => {:sessions => my_sessions} 

从那里Devise将拿起你的控制器。这可能是一个好主意,在那里重新启动服务器只是为了确保。


I have a Rails app running Rails 3.2.6 and Devise 2.1.2 and I want to be able to limit concurrent logins to 1. I've tried using the Devise Security Extension but keep getting an undefined method for unique_session_id.

Instead I want to see if I can override Devise's behavior as in this SO article: devise limit one session per user at a time

I understand how it works and I've generated a sessions controller, but I'm not sure how to force the app to use it as an override for Devise. Also in the controller should I be inheriting from the Application Controller or the Devise Controller?

Everything in place right now however the app doesn't write a login_token which tells me that I'm not using the controller properly or something else might be amiss.

Any help is appreciated.

解决方案

I would strongly recommend you check out the Devise Wiki. Chances are when doing something like this, the answer can be found there. Your new controller will need to inherit from the Devise Sessions Controller as such:

class MySessionsController < Devise::SessionsController

This way, any methods you did not specifically override will still be called, thus not breaking other functionality.

In order to make sure that Devise uses your controller instead of it's own, make your devise_for call in routes.rb look as follows:

devise_for :users, :controllers => { :sessions => "my_sessions" }

From there Devise will pick up your controller. It's probably a good idea to restart your server in there just to be sure.

这篇关于设计会话限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆