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