简体   繁体   中英

Multiple model authentication in Rails using devise

I have a User model and an admin model and I am using devise for authentication. My Admin logins using an email and password. My User can login using both email and username. What should my

#config/initializers/devise.rb
config.authentication_keys = [ : ]

line should be and do I need to override devise to achieve this ?

Is email a required field for the User? If so, you can overwrite the Devise SessionController locate the user's email if username is used and process the authentication.

I would also STRONGLY advise against having a separate User and Admin model, unless Admin inherits User. You are only asking for problems in user management. I would recommend setting a role[s] attribute on the User model and using a framework like Pundit to manage access policy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM