简体   繁体   English

rails devise-如何为两个不同的用户模型进行2个devise认证?

[英]rails devise - how to have 2 devise authentications for two different user models?

We have admin_users and we have regular users and they both have separate tables, models and devise logins. 我们有admin_users和普通用户,他们都有单独的表,模型和设计登录名。

It might make more sense to use devise against just one user table and use cancan for the roles but the application has already been created with two separate user tables and it's not an option to change them at this point. 仅针对一个用户表使用devise并使用cancan作为角色可能更有意义,但是应用程序已经使用两个单独的用户表创建,因此此时不能更改它们。

The admin users functionality, including login, is working ok. 管理员用户的功能(包括登录名)工作正常。 Initially standard users access was only through a link and token based authentication but that needs to change. 最初,标准用户访问仅通过基于链接和令牌的身份验证进行,但这需要进行更改。

In routes we had 在路线上,我们有

devise_for :admin_users, ActiveAdmin::Devise.config  
devise_for :users
resources :users, :only => [:update, :edit]

So I added the root path for the users resource as indcated by the Devise documentation as the place where a successful login goes to: 因此,我添加了由Devise文档说明的用户资源的根路径,作为成功登录的位置:

devise_for :admin_users, ActiveAdmin::Devise.config  
devise_for :users
resources :users, :only => [:update, :edit] do
  root to: "practitioner_activities#welcome"
end  

and I then also tried removing the only => eg 然后我也尝试删除only => eg

devise_for :admin_users, ActiveAdmin::Devise.config  
devise_for :users
resources :users do
  root to: "practitioner_activities#welcome"
end  

For the (regular) User model I changed: 对于(常规)用户模型,我进行了更改:

devise :token_authenticatable,

to also have: 还具有:

devise :token_authenticatable, # token login still permitted.  
       :database_authenticatable, :recoverable, :rememberable, 
       :trackable, :validatable
       # Not sure if these will make a difference but they are like this in other apps.

but instead of redirecting to practitioner_activities#welcome the users gets sent back to the login screen. 但是不会将用户重定向到登录屏幕,而无需重定向到开业者_活动#welcome。

I notice that the first line in the console that is logged for the login POST is using the AdminUser model, not the User model. 我注意到控制台中为登录POST记录的第一行使用的是AdminUser模型,而不是User模型。 Any idea how to fix? 任何想法如何解决?

Started POST "/" for 127.0.0.1 at 2012-08-23 13:54:50 -0400
Processing by HelpController#show as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"28iGxAB+URoIKoBQtPizGAosJoZ/V7Vko1w/bYMvesE=", "new_user_session_path"=>{"email"=>"Borger.Cathy@meridianschools.o
rg", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign In"}
  AdminUser Load (0.4ms)  SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1

The login form itself is: 登录表单本身是:

= semantic_form_for(:new_user_session_path, 
  :html => {:id => "session_new"}) do|f| 

      = f.inputs do
        = f.input :email, :label => "Username"
        = f.input :password
        = f.input :remember_me, :as => :boolean, :if =>  false  
        = f.commit_button "Sign In"

最终,主要的事情是再次只是设计生成器,然后编辑设计视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Devise,如何拥有两个 authenticated_root(针对两个不同的用户模型) - With Devise, how have two authenticated_root (for two different user models) Rails:如何让设计中的两个用户模型通过注册 - Rails: how to let two user models in devise go through registration Devise中的两种截然不同的用户模型 - Two very different user models in Devise 如何在rails中使用两个不同的注册页面(使用设计) - How to have two different signup pages in rails (using devise) 导轨,将3种不同的模型与Devise相关联 - rails, associating 3 different models with Devise Rails通过Devise验证不同的模型 - Rails authenticate different models with Devise Rails Devise,两个模型在同一页面上具有自己的登录表单 - Rails Devise, Two Models have their own login form on the same page 如何使用带有devise和rails的两个不同模型的两个不同的自定义注册表单? - How to use two different custom signup forms with two different models with devise and rails? 为Ruby on Rails上的Devise设置不同的用户模型和注册路径 - Setting up different User models and registration paths for Devise on Ruby on Rails 为 Rails 设计:将用户数据分成两个模型会提高安全性吗? - Devise for Rails: Does Seperating User Data into Two Models Improve Security?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM