2009-10-09 09:46:24 -04:00
|
|
|
module Devise
|
|
|
|
module ActiveRecord
|
2009-10-20 09:08:40 -04:00
|
|
|
# Shortcut method for including all devise modules inside your model.
|
|
|
|
# You can give some extra options while declaring devise in your model:
|
|
|
|
#
|
2009-10-20 11:31:34 -04:00
|
|
|
# * except: convenient option that allows you to add all devise modules,
|
|
|
|
# removing only the modules you setup here:
|
2009-10-20 09:08:40 -04:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2009-10-30 05:23:47 -04:00
|
|
|
# * confirm_within: the time you want your user to confirm it's account. During
|
2009-10-22 07:49:19 -04:00
|
|
|
# this time he will be able to access your application without confirming.
|
|
|
|
#
|
2009-10-30 05:23:47 -04:00
|
|
|
# devise :all, :confirm_within => 7.days
|
2009-10-22 07:49:19 -04:00
|
|
|
#
|
|
|
|
# * 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.
|
2009-10-12 07:37:28 -04:00
|
|
|
#
|
2009-10-09 09:46:24 -04:00
|
|
|
# Examples:
|
2009-10-12 07:37:28 -04:00
|
|
|
#
|
2009-10-30 06:29:10 -04:00
|
|
|
# # include only authenticatable module (default)
|
2009-10-09 09:46:24 -04:00
|
|
|
# devise
|
2009-10-12 07:37:28 -04:00
|
|
|
#
|
2009-10-30 06:29:10 -04:00
|
|
|
# # include authenticatable + confirmable modules
|
2009-10-09 09:46:24 -04:00
|
|
|
# devise :confirmable
|
2009-10-12 07:37:28 -04:00
|
|
|
#
|
2009-10-30 06:29:10 -04:00
|
|
|
# # include authenticatable + recoverable modules
|
2009-10-09 09:46:24 -04:00
|
|
|
# devise :recoverable
|
2009-10-12 07:37:28 -04:00
|
|
|
#
|
2009-10-30 06:29:10 -04:00
|
|
|
# # include authenticatable + rememberable modules
|
2009-10-19 22:52:31 -04:00
|
|
|
# devise :rememberable
|
|
|
|
#
|
2009-10-30 06:29:10 -04:00
|
|
|
# # include authenticatable + validatable modules
|
2009-10-09 09:46:24 -04:00
|
|
|
# devise :validatable
|
2009-10-12 07:37:28 -04:00
|
|
|
#
|
2009-10-30 06:29:10 -04:00
|
|
|
# # include authenticatable + confirmable + recoverable + rememberable + validatable
|
2009-10-19 22:52:31 -04:00
|
|
|
# devise :confirmable, :recoverable, :rememberable, :validatable
|
2009-10-12 07:37:28 -04:00
|
|
|
#
|
2009-10-09 09:46:24 -04:00
|
|
|
# # shortcut to include all modules (same as above)
|
|
|
|
# devise :all
|
2009-10-18 11:30:32 -04:00
|
|
|
#
|
2009-10-18 13:25:16 -04:00
|
|
|
# # include all except recoverable
|
2009-10-18 11:30:32 -04:00
|
|
|
# devise :all, :except => :recoverable
|
|
|
|
#
|
|
|
|
def devise(*modules)
|
|
|
|
options = modules.extract_options!
|
|
|
|
|
2009-10-30 06:29:10 -04:00
|
|
|
# TODO Remove me in a next release
|
|
|
|
if modules.include?(:authenticable)
|
|
|
|
modules.delete(:authenticable)
|
|
|
|
modules.unshift(:authenticatable)
|
|
|
|
ActiveSupport::Deprecation.warn "devise :authenticate is deprecated, use authenticatable instead"
|
|
|
|
end
|
|
|
|
|
2009-10-22 12:19:01 -04:00
|
|
|
modules = Devise::ALL if modules.include?(:all)
|
|
|
|
modules -= Array(options.delete(:except))
|
2009-10-30 06:29:10 -04:00
|
|
|
modules = [:authenticatable] | modules
|
2009-10-12 20:06:39 -04:00
|
|
|
|
2009-10-18 11:30:32 -04:00
|
|
|
modules.each do |m|
|
2009-10-12 20:06:39 -04:00
|
|
|
devise_modules << m.to_sym
|
|
|
|
include Devise::Models.const_get(m.to_s.classify)
|
|
|
|
end
|
2009-10-20 09:08:40 -04:00
|
|
|
|
2009-10-20 10:49:49 -04:00
|
|
|
# Convert new keys to methods which overwrites Devise defaults
|
2009-10-22 12:19:01 -04:00
|
|
|
options.each { |key, value| send(:"#{key}=", value) }
|
2009-10-12 20:06:39 -04:00
|
|
|
end
|
|
|
|
|
2009-10-17 11:10:15 -04:00
|
|
|
# Stores all modules included inside the model, so we are able to verify
|
|
|
|
# which routes are needed.
|
2009-10-12 20:06:39 -04:00
|
|
|
def devise_modules
|
|
|
|
@devise_modules ||= []
|
2009-10-09 09:46:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|