Check if user is active before allowing user to sign in with devise (rails)

前端 未结 2 2153
挽巷
挽巷 2020-12-24 12:43

I am using devise and created a User field called :active which is either true or false. I have to manually make the user active (true) before the user is allowed to log in

2条回答
  •  独厮守ぢ
    2020-12-24 13:25

    Add these two methods to your user model, devise should pick them up automatically - you should NOT need to extend Devise::SessionsController

    def active_for_authentication?
      super && self.your_method_for_checking_active # i.e. super && self.is_active
    end
    
    def inactive_message
      "Sorry, this account has been deactivated."
    end
    

提交回复
热议问题