Jackie Chan
Jackie Chan

Reputation: 2662

How To: Require admin to activate account before sign_in Devise on Rails

I have just implemented a feature which for me seems like a bug, when adding a new column 'Approved' to users table in devise authentication, I got that even admin has to be approved. That mean my admin can't login to the system :)

Is it how things work with this feature? Any other solutions?

Thanks

Upvotes: 1

Views: 1643

Answers (1)

Dex
Dex

Reputation: 12759

Do something like this in your User model.

  # Devise overrides
  def disapprove 
    self.approved = false 
  end 
  def approve 
    self.approved = true 
  end 
  def active_for_authentication? 
    super && approved? 
  end 
  def inactive_message 
    approved? ? super : "Your account has not been approved" 
  end 
  # end Devise overrides

The inactive_message contents will be passed on to the Rails flash object. Make sure approved is false by default.

Upvotes: 4

Related Questions