mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Clean up the whole loading mess and closes #247. This commit depends on latest Rails.
This commit is contained in:
parent
d38421dde8
commit
e905762611
4 changed files with 26 additions and 23 deletions
|
@ -230,8 +230,7 @@ module Devise
|
||||||
# A method used internally to setup warden manager from the Rails initialize
|
# A method used internally to setup warden manager from the Rails initialize
|
||||||
# block.
|
# block.
|
||||||
def self.configure_warden! #:nodoc:
|
def self.configure_warden! #:nodoc:
|
||||||
return unless warden_config
|
@@warden_configured ||= begin
|
||||||
|
|
||||||
warden_config.failure_app = Devise::FailureApp
|
warden_config.failure_app = Devise::FailureApp
|
||||||
warden_config.default_scope = Devise.default_scope
|
warden_config.default_scope = Devise.default_scope
|
||||||
|
|
||||||
|
@ -240,6 +239,8 @@ module Devise
|
||||||
end
|
end
|
||||||
|
|
||||||
@@warden_config_block.try :call, Devise.warden_config
|
@@warden_config_block.try :call, Devise.warden_config
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate a friendly string randomically to be used as token.
|
# Generate a friendly string randomically to be used as token.
|
||||||
|
|
|
@ -9,6 +9,7 @@ module Devise
|
||||||
include ActionController::RackDelegation
|
include ActionController::RackDelegation
|
||||||
include ActionController::UrlFor
|
include ActionController::UrlFor
|
||||||
include ActionController::Redirecting
|
include ActionController::Redirecting
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
delegate :flash, :to => :request
|
delegate :flash, :to => :request
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
require 'devise/rails/routes'
|
require 'devise/rails/routes'
|
||||||
require 'devise/rails/warden_compat'
|
require 'devise/rails/warden_compat'
|
||||||
|
|
||||||
|
# Include UrlHelpers in ActionController and ActionView as soon as they are loaded.
|
||||||
|
ActiveSupport.on_load(:action_controller) { include Devise::Controllers::UrlHelpers }
|
||||||
|
ActiveSupport.on_load(:action_view) { include Devise::Controllers::UrlHelpers }
|
||||||
|
|
||||||
module Devise
|
module Devise
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
config.devise = Devise
|
config.devise = Devise
|
||||||
|
|
||||||
initializer "devise.ensure_routes_are_loaded", :before => :load_app_classes, :after => :load_config_initializers do |app|
|
config.app_middleware.use Warden::Manager do |config|
|
||||||
app.reload_routes!
|
|
||||||
end
|
|
||||||
|
|
||||||
initializer "devise.add_middleware" do |app|
|
|
||||||
app.config.middleware.use Warden::Manager do |config|
|
|
||||||
Devise.warden_config = config
|
Devise.warden_config = config
|
||||||
Devise.configure_warden!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
initializer "devise.add_url_helpers" do |app|
|
# Force routes to be loaded if we are doing any eager load.
|
||||||
Devise::FailureApp.send :include, app.routes.url_helpers
|
config.before_eager_load { |app| app.reload_routes! }
|
||||||
ActionController::Base.send :include, Devise::Controllers::UrlHelpers
|
|
||||||
ActionView::Base.send :include, Devise::Controllers::UrlHelpers
|
|
||||||
end
|
|
||||||
|
|
||||||
config.after_initialize do
|
config.after_initialize do
|
||||||
I18n.available_locales
|
|
||||||
flash = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
|
flash = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
|
||||||
|
|
||||||
I18n.backend.send(:translations).each do |locale, translations|
|
translations = begin
|
||||||
|
I18n.available_locales
|
||||||
|
I18n.backend.send(:translations)
|
||||||
|
rescue Exception => e # Do not care if something fails
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
translations.each do |locale, translations|
|
||||||
keys = flash & (translations[:devise][:sessions].keys) rescue []
|
keys = flash & (translations[:devise][:sessions].keys) rescue []
|
||||||
|
|
||||||
if keys.any?
|
if keys.any?
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'test_helper'
|
||||||
|
|
||||||
module Devise
|
module Devise
|
||||||
def self.yield_and_restore
|
def self.yield_and_restore
|
||||||
|
@@warden_configured = nil
|
||||||
c, b = @@warden_config, @@warden_config_block
|
c, b = @@warden_config, @@warden_config_block
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
|
|
Loading…
Reference in a new issue