[英]How to allow sign in with devise if user is already authenticated?
There's an App which creates a new user when you first time open the site (if you don't have a cookie). 首次打开网站时(如果您没有Cookie的话),有一个应用程序可以创建一个新用户。 Also you can sign in as different user.
您也可以以其他用户身份登录。 The problem is Devise doesn't allow to sign in as already authenticated user.
问题是Devise不允许以已通过身份验证的用户身份登录。 Even if I override
require_no_authentication
in SessionsController
warden still remembers the user through session. 即使我在
SessionsController
覆盖了require_no_authentication
,监护人仍会通过会话记住用户。
I do aware about guest user pattern but there's no guest user. 我知道访客用户模式,但是没有访客用户。 The app is intended to create real user accounts and allow to sign in as another users.
该应用旨在创建真实的用户帐户,并允许以其他用户身份登录。
So the question is should I create new Warden strategy and if so, what checks shall I do there? 因此,问题是我应该制定新的“守望者”战略,如果是,我应该在那里做哪些检查? Or there's another way?
还是有另一种方式?
Just reset the session in the desired action. 只需将会话重置为所需的操作即可。 You can just make the first line be
reset_session
, or make it a before filter, like so: 您可以将第一行设置为
reset_session
,或将其设置为before过滤器,如下所示:
before_filter :deauthorize_user, only: [ :some_action ]
def deauthorize_user
reset_session
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.