简体   繁体   English

如果用户已经通过身份验证,如何允许设计登录?

[英]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.

相关问题 w Devise,如何允许登录用户以其他用户身份登录 - w Devise, how to allow a SignIn user to sign in as another user 设计如何允许登录用户注册另一个用户 - Devise how to allow logged user to sign up another user 设计-如何触发页面上的登录用户已经可以访问 - Devise - How to trigger a sign_in on page user already has access to 只允许该用户激活 sign_in - 设计 - Allow just that user actived sign_in - Devise 如何更改已使用Devise标记进行身份验证的用户的“登录后路径”? - How do I change the 'after sign in path' for a user that has been authenticated with a token with Devise? 允许经过身份验证的Devise用户访问Doorkeeper受保护的控制器操作 - Allow authenticated Devise user to access Doorkeeper protected controller actions 当用户已通过身份验证时,在设计中运行管理员策略 - Run warden strategy in devise when user is already authenticated Rails设计:如何允许访客用户添加记录然后仅在注册确认后确认记录 - Rails devise: how to allow guest user to add a record then confirm the record only after sign up confirmation Rails:在Devise注册页面上,如何允许(但不要求)用户输入个人资料名称? - Rails: On Devise sign up page, how to allow (but not require) a user to enter a profile name? 如何设置只有用户已登录时才设计RegistrationsController来显示sign_up页面? - How to make devise RegistrationsController to show sign_up page only if user is already signed in?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM