-
Notifications
You must be signed in to change notification settings - Fork 5.5k
How To: Require admin to activate account before sign_in
drosboro edited this page Apr 25, 2011
·
29 revisions
Instead of using the confirmable module (to allow users to activate their own accounts), you may want to require an admin or moderator to activate new accounts.
Create a migration as follows (in this case, I'm assuming the model is called User):
class AddAdminActivationToUsers < ActiveRecord::Migration
def self.up
add_column :users, :approved, :boolean
end
def self.down
remove_column :users, :approved
end
end
Then, override the following methods in your model (User.rb):
def active_for_authentication?
super && approved?
end
def inactive_message
if !approved?
:not_approved
else
super # Use whatever other message
end
end
You will need to create an entry for :not_approved in the i18n file, located at config/locales/devise.##.yml
:
devise:
failure:
not_approved: 'Your account has not been approved by your administrator yet.'
You'll want to create a controller method that is admin-accessible only, that lists the unapproved users and provides a simple way to approve them.
(NOTE: still to come)
(NOTE: still to come)