We have admin_users and we have regular users and they both have separate tables, models and devise logins.
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.
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_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 => e.g.
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.
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. 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"
In the end the main things was to just the devise generators again and then edit the devise views.