Skip to content

Commit

Permalink
Created a generator that copies an initializer with configuration val…
Browse files Browse the repository at this point in the history
…ues.
  • Loading branch information
josevalim committed Nov 3, 2009
1 parent 371a9bb commit 8882727
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 60 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
Expand Up @@ -5,6 +5,8 @@

* enhancement
* [#16] Allow devise to be more agnostic. Do not require ActiveRecord to be loaded.
* Allow Warden::Manager to be configured through Devise
* Created a generator which creates an initializer

== 0.3.0

Expand Down
51 changes: 13 additions & 38 deletions README.rdoc
Expand Up @@ -91,29 +91,11 @@ You could also include the other devise modules as below:

Note that validations aren't added by default, so you're able to customize it. In order to have automatic validations working just include :validatable.

== Configuration values
== Model configuration

In addition to :except, you can provide some options to devise call:
In addition to :except, you can provide :pepper, :stretches, :confirm_within and :remember_for as options to devise method.

* pepper: setup a pepper to generate de encrypted password. By default no pepper is used:

devise :all, :pepper => 'my_pepper'

* stretches: configure how many times you want the password is reencrypted.

devise :all, :stretches => 20

* confirm_within: the time the user can access the site before being blocked because his account was not confirmed

devise :all, :confirm_within => 1.week

* remember_for: the time to store the remember me cookie in the user

devise :all, :remember_for => 2.weeks

All those values can also be set in a global way by setting them in Devise::Models:

Devise::Models.confirm_within = 1.week
All those options are described in "config/initializers/devise.rb", which is generated when you invoke `ruby script/generate devise_install` in your application root.

== Routes

Expand All @@ -140,23 +122,12 @@ This is going to look inside you User model and create the needed routes:
POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}

You can run the routes rake task to verify what routes are being created by devise.
There are also some options available for configuring your routes:

* :class_name => setup a different class to be looked up by devise, if it cannot be correctly find by the route name.

map.devise_for :users, :class_name => 'Account'

* :as => allows you to setup path name that will be used, as rails routes does. The following route configuration would setup your route as /accounts instead of /users:

map.devise_for :users, :as => 'accounts'
There are also some options available for configuring your routes, as :class_name (to set the class for that route), :as and :path_names, where the last two have the same meaning as in routes. The available :path_names are:

* :singular => setup the name used to create named routes. By default, for a :users key, it is going to be the singularized version, :user. To configure a named route like account_session_path instead of user_session_path just do:
map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }

map.devise_for :users, :singular => :account

* :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :password and :confirmation.

map.devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
Be sure to check devise_for documentation for detailed description.

== Controller filters

Expand Down Expand Up @@ -212,13 +183,17 @@ Devise let's you setup as many roles as you want, so let's say you already have

Devise comes with some generators to help you start:

script/generate devise Model
ruby script/generate devise_install

This will generate an initializer, with a description of all configuration values. You can also generate models through:

ruby script/generate devise Model

Will generate a model, configured with all devise modules, and add attr_accessible for default fields, so you can setup more accessible attributes later. The generator will also create the migration and configure your route for devise.
A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.

You can also copy devise views to your application, being able to modify them based on your needs. To do it so, run the following command:

script/generate devise_views
ruby script/generate devise_views

This is gonna copy all session, password, confirmation and mailer views to your app/views folder.

Expand Down
3 changes: 3 additions & 0 deletions generators/devise_install/USAGE
@@ -0,0 +1,3 @@
To copy a Devise initializer to your Rails App, with some configuration values, just do:

script/generate devise_install
9 changes: 9 additions & 0 deletions generators/devise_install/devise_install_generator.rb
@@ -0,0 +1,9 @@
class DeviseInstallGenerator < Rails::Generator::Base

def manifest
record do |m|
m.file "devise.rb", "config/initializers/devise.rb"
end
end

end
33 changes: 33 additions & 0 deletions generators/devise_install/templates/devise.rb
@@ -0,0 +1,33 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
Devise.setup do |config|
# Invoke `rake secret` and use the printed value to setup a pepper to generate
# the encrypted password. By default no pepper is used.
# config.pepper = "rake secret output"

# Configure how many times you want the password is reencrypted. Default is 10.
# config.stretches = 10

# The time you want give to your user to confirm his account. During this time
# he will be able to access your application without confirming. Default is nil.
# config.confirm_within = 2.days

# The time the user will be remembered without asking for credentials again.
# config.remember_for = 2.weeks

# Configure the e-mail address which will be shown in DeviseMailer.
# config.mail_sender = "foo.bar@yourapp.com"

# If you want to use other strategies, that are not (yet) supported by Devise,
# you can configure them inside the config.warden block. The example below
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
#
# config.manager do |manager|
# manager.oauth(:twitter) do |twitter|
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
# twitter.consumer_key = <YOUR CONSUMER KEY>
# twitter.options :site => 'http://twitter.com'
# end
# manager.default_strategies.unshift :twitter_oauth
# end
end
2 changes: 1 addition & 1 deletion generators/devise_views/USAGE
@@ -1,3 +1,3 @@
To copy all session, password and confirmation views from devise to your app just run the following command:
To copy all session, password, confirmation and mailer views from devise to your app just run the following command:

script/generate devise_views
24 changes: 3 additions & 21 deletions lib/devise/models.rb
Expand Up @@ -51,27 +51,9 @@ def #{accessor}=(value)
#
# devise :all, :except => :rememberable
#
# * pepper: setup a pepper to generate de encrypted password. By default no
# pepper is used:
#
# devise :all, :pepper => 'my_pepper'
#
# * stretches: configure how many times you want the password is reencrypted.
#
# devise :all, :stretches => 20
#
# * confirm_within: the time you want your user to confirm it's account. During
# this time he will be able to access your application without confirming.
#
# devise :all, :confirm_within => 7.days
#
# * remember_for: the time the user will be remembered without asking for
# credentials again.
#
# devise :all, :remember_for => 2.weeks
#
# You can refer to Authenticable, Confirmable and Rememberable for more
# information about writing your own method to setup each model apart.
# You can also give the following configuration values in a hash: :pepper,
# :stretches, :confirm_within and :remember_for. Please check your Devise
# initialiazer for a complete description on those values.
#
# Examples:
#
Expand Down

0 comments on commit 8882727

Please sign in to comment.