Devise - login from two model

一曲冷凌霜 提交于 2019-12-03 17:22:11

You should monkeypatch find_for_authentication method from devise/models/authenticatable.rb

module Devise
  module Models
    module Authenticatable
      def find_for_authentication(conditions)
          #put your authentication logic here
        end
    end
  end
end

About authentication logic: Using two models for authentication in your case it's realy bad idea. How do u want build relations with two users models? It's a lot of unnecessary code.

Correct way of resolving your problem is make some synchronization between yours tables.

  • Try to authenticate user with base User model.

  • If user credentials was wrong - try to authenticate him with CrmUser model.

  • If authentication with CrmUser was OK add him to users table if he doesn't exists there already.

  • Return User's model object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!