Devise: Require customers to be activated before login
Mittwoch, 18. Mai 2011, 21:07 Uhr | roberto@vasquez-angel.de |Assume you have you have a devise model customer. Customers should be able to sign up, but should be reviewed and activated (i.e. by an admin) before they can login.
First, add a column “active to the customer model:
$> rails g migration AddActiveToCustomers active:boolean
It’s a good idea to make the default false:
class AddActiveToCustomers < ActiveRecord::Migration
def self.up
add_column :customers, :active, :boolean, :default => false
end
def self.down
remove_column :customers, :active
end
end
Then you have to customize the inactive message. In your Rails.root/app/modelscustomer.rb:
class Customer < ActiveRecord::Base
attr_accessible :active # Make the active flag accessible, if you want to set it from anywhere (i.e. in an application backend
def active_for_authentication?
active
end
def inactive_message
"inactive"
end
.
.
.
end
That's it. If a customer signs up, he will not be able to login, before the active flag has been set to true in the database.