2009-11-03 06:35:11 -05:00
|
|
|
require 'devise/rails/routes'
|
2010-02-16 08:57:10 -05:00
|
|
|
require 'devise/rails/warden_compat'
|
|
|
|
|
|
|
|
module Devise
|
|
|
|
class Engine < ::Rails::Engine
|
2010-03-30 05:08:16 -04:00
|
|
|
config.devise = Devise
|
|
|
|
|
2010-07-17 03:43:35 -04:00
|
|
|
# Skip eager load of controllers because it is handled by Devise
|
|
|
|
# to avoid loading unused controllers.
|
|
|
|
config.paths.app.controllers.autoload!
|
|
|
|
config.paths.app.controllers.skip_eager_load!
|
|
|
|
|
|
|
|
# Initialize Warden and copy its configurations.
|
2010-05-15 18:38:40 -04:00
|
|
|
config.app_middleware.use Warden::Manager do |config|
|
|
|
|
Devise.warden_config = config
|
2010-04-22 13:59:52 -04:00
|
|
|
end
|
|
|
|
|
2010-05-15 18:38:40 -04:00
|
|
|
# Force routes to be loaded if we are doing any eager load.
|
|
|
|
config.before_eager_load { |app| app.reload_routes! }
|
2010-04-03 07:11:45 -04:00
|
|
|
|
2010-07-18 06:17:04 -04:00
|
|
|
initializer "devise.add_filters" do |app|
|
|
|
|
app.config.filter_parameters += [:password, :password_confirmation]
|
|
|
|
app.config.filter_parameters.uniq
|
|
|
|
end
|
|
|
|
|
2010-07-13 04:09:55 -04:00
|
|
|
initializer "devise.url_helpers" do
|
2010-07-13 07:35:53 -04:00
|
|
|
Devise.include_helpers(Devise::Controllers)
|
2010-07-13 07:11:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
initializer "devise.oauth_url_helpers" do
|
|
|
|
if Devise.oauth_providers.any?
|
2010-07-13 07:35:53 -04:00
|
|
|
Devise.include_helpers(Devise::Oauth)
|
2010-07-13 07:11:04 -04:00
|
|
|
end
|
2010-07-13 04:09:55 -04:00
|
|
|
end
|
2010-07-17 03:43:35 -04:00
|
|
|
|
2010-09-25 10:08:46 -04:00
|
|
|
initializer "devise.encryptor_check" do
|
|
|
|
case Devise.encryptor
|
|
|
|
when :bcrypt
|
|
|
|
puts "[DEVISE] From version 1.2, there is no need to set your encryptor to bcrypt " <<
|
|
|
|
"since encryptors are only enabled if you include :encryptable in your models. " <<
|
|
|
|
"With this change, we can integrate better with bcrypt and get rid of the " <<
|
|
|
|
"password_salt column (since bcrypt stores the salt with password). " <<
|
|
|
|
"Please comment config.encryptor in your initializer to get rid of this warning."
|
|
|
|
when nil
|
|
|
|
# Nothing to say
|
|
|
|
else
|
|
|
|
puts "[DEVISE] You are using #{Devise.encryptor} as encryptor. From version 1.2, " <<
|
|
|
|
"you need to explicitly add :encryptable to your models in order for this " <<
|
|
|
|
"configuration value to work."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-17 19:58:32 -04:00
|
|
|
# Check all available mappings and only load related controllers.
|
2010-07-17 03:43:35 -04:00
|
|
|
def eager_load!
|
|
|
|
mappings = Devise.mappings.values.map(&:modules).flatten.uniq
|
|
|
|
controllers = Devise::CONTROLLERS.values_at(*mappings)
|
|
|
|
path = paths.app.controllers.to_a.first
|
|
|
|
matcher = /\A#{Regexp.escape(path)}\/(.*)\.rb\Z/
|
|
|
|
|
|
|
|
Dir.glob("#{path}/devise/{#{controllers.join(',')}}_controller.rb").sort.each do |file|
|
|
|
|
require_dependency file.sub(matcher, '\1')
|
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
2010-02-16 08:57:10 -05:00
|
|
|
end
|
2010-09-17 19:58:32 -04:00
|
|
|
end
|