devise 1.0.11 → 1.1.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (121) hide show
  1. data/CHANGELOG.rdoc +6 -72
  2. data/Gemfile +18 -0
  3. data/README.rdoc +51 -46
  4. data/Rakefile +5 -4
  5. data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +2 -2
  6. data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +4 -3
  7. data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +11 -7
  8. data/app/controllers/{sessions_controller.rb → devise/sessions_controller.rb} +11 -8
  9. data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +2 -10
  10. data/app/models/devise/mailer.rb +55 -0
  11. data/app/views/{confirmations → devise/confirmations}/new.html.erb +1 -1
  12. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  13. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  14. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  15. data/app/views/{passwords → devise/passwords}/edit.html.erb +1 -1
  16. data/app/views/{passwords → devise/passwords}/new.html.erb +1 -1
  17. data/app/views/{registrations → devise/registrations}/edit.html.erb +1 -1
  18. data/app/views/{registrations → devise/registrations}/new.html.erb +1 -1
  19. data/app/views/{sessions → devise/sessions}/new.html.erb +1 -1
  20. data/app/views/{shared/_devise_links.erb → devise/shared/_links.erb} +0 -0
  21. data/app/views/{unlocks → devise/unlocks}/new.html.erb +1 -1
  22. data/{lib/devise → config}/locales/en.yml +7 -1
  23. data/lib/devise.rb +6 -29
  24. data/lib/devise/controllers/helpers.rb +16 -43
  25. data/lib/devise/controllers/internal_helpers.rb +10 -36
  26. data/lib/devise/controllers/scoped_views.rb +35 -0
  27. data/lib/devise/failure_app.rb +7 -14
  28. data/lib/devise/hooks/rememberable.rb +3 -6
  29. data/lib/devise/hooks/trackable.rb +1 -1
  30. data/lib/devise/mapping.rb +17 -18
  31. data/lib/devise/models.rb +4 -20
  32. data/lib/devise/models/{database_authenticatable.rb → authenticatable.rb} +16 -28
  33. data/lib/devise/models/confirmable.rb +25 -23
  34. data/lib/devise/models/http_authenticatable.rb +3 -7
  35. data/lib/devise/models/lockable.rb +40 -35
  36. data/lib/devise/models/recoverable.rb +4 -8
  37. data/lib/devise/models/rememberable.rb +6 -9
  38. data/lib/devise/models/timeoutable.rb +1 -3
  39. data/lib/devise/models/token_authenticatable.rb +4 -5
  40. data/lib/devise/models/validatable.rb +10 -1
  41. data/lib/devise/orm/mongo_mapper.rb +10 -23
  42. data/lib/devise/rails.rb +11 -9
  43. data/lib/devise/rails/routes.rb +113 -107
  44. data/lib/devise/rails/warden_compat.rb +3 -41
  45. data/lib/devise/schema.rb +13 -21
  46. data/lib/devise/strategies/{database_authenticatable.rb → authenticatable.rb} +3 -3
  47. data/lib/devise/strategies/http_authenticatable.rb +4 -22
  48. data/lib/devise/test_helpers.rb +1 -8
  49. data/lib/devise/version.rb +1 -1
  50. data/lib/generators/devise/devise_generator.rb +57 -0
  51. data/{generators → lib/generators}/devise/templates/migration.rb +1 -1
  52. data/lib/generators/devise_install/devise_install_generator.rb +25 -0
  53. data/{generators → lib/generators}/devise_install/templates/README +4 -8
  54. data/{generators → lib/generators}/devise_install/templates/devise.rb +0 -3
  55. data/lib/generators/devise_views/devise_views_generator.rb +11 -0
  56. data/test/controllers/helpers_test.rb +15 -9
  57. data/test/devise_test.rb +1 -6
  58. data/test/encryptors_test.rb +0 -3
  59. data/test/failure_app_test.rb +6 -1
  60. data/test/integration/authenticatable_test.rb +25 -85
  61. data/test/integration/http_authenticatable_test.rb +2 -10
  62. data/test/integration/lockable_test.rb +3 -22
  63. data/test/integration/recoverable_test.rb +1 -1
  64. data/test/integration/registerable_test.rb +31 -36
  65. data/test/integration/rememberable_test.rb +6 -24
  66. data/test/integration/token_authenticatable_test.rb +2 -4
  67. data/test/integration/trackable_test.rb +1 -1
  68. data/test/mailers/confirmation_instructions_test.rb +4 -10
  69. data/test/mailers/unlock_instructions_test.rb +1 -1
  70. data/test/mapping_test.rb +12 -24
  71. data/test/models/authenticatable_test.rb +3 -3
  72. data/test/models/confirmable_test.rb +29 -29
  73. data/test/models/http_authenticatable_test.rb +19 -0
  74. data/test/models/lockable_test.rb +45 -44
  75. data/test/models/recoverable_test.rb +7 -7
  76. data/test/models/rememberable_test.rb +7 -10
  77. data/test/models/validatable_test.rb +19 -24
  78. data/test/models_test.rb +2 -16
  79. data/test/orm/active_record.rb +3 -4
  80. data/test/orm/mongo_mapper.rb +2 -10
  81. data/test/rails_app/app/active_record/admin.rb +1 -1
  82. data/test/rails_app/app/active_record/user.rb +3 -3
  83. data/test/rails_app/app/controllers/application_controller.rb +1 -7
  84. data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
  85. data/test/rails_app/app/controllers/users_controller.rb +0 -4
  86. data/test/rails_app/app/mongo_mapper/admin.rb +4 -7
  87. data/test/rails_app/app/mongo_mapper/user.rb +5 -8
  88. data/test/rails_app/config/application.rb +32 -0
  89. data/test/rails_app/config/boot.rb +7 -108
  90. data/test/rails_app/config/environment.rb +4 -41
  91. data/test/rails_app/config/environments/development.rb +15 -13
  92. data/test/rails_app/config/environments/production.rb +25 -20
  93. data/test/rails_app/config/environments/test.rb +23 -22
  94. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  95. data/test/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
  96. data/test/rails_app/config/initializers/devise.rb +0 -3
  97. data/test/rails_app/config/initializers/session_store.rb +2 -2
  98. data/test/rails_app/config/routes.rb +17 -21
  99. data/test/routes_test.rb +30 -47
  100. data/test/support/{assertions_helper.rb → assertions.rb} +0 -15
  101. data/test/support/{tests_helper.rb → helpers.rb} +16 -3
  102. data/test/support/{integration_tests_helper.rb → integration.rb} +8 -4
  103. data/test/support/webrat/integrations/rails.rb +31 -0
  104. data/test/test_helper.rb +8 -7
  105. data/test/test_helpers_test.rb +9 -9
  106. metadata +53 -128
  107. data/app/models/devise_mailer.rb +0 -68
  108. data/app/views/devise_mailer/confirmation_instructions.html.erb +0 -5
  109. data/app/views/devise_mailer/reset_password_instructions.html.erb +0 -8
  110. data/app/views/devise_mailer/unlock_instructions.html.erb +0 -7
  111. data/generators/devise/USAGE +0 -5
  112. data/generators/devise/devise_generator.rb +0 -15
  113. data/generators/devise/lib/route_devise.rb +0 -32
  114. data/generators/devise/templates/model.rb +0 -9
  115. data/generators/devise_install/USAGE +0 -3
  116. data/generators/devise_install/devise_install_generator.rb +0 -15
  117. data/generators/devise_views/USAGE +0 -3
  118. data/generators/devise_views/devise_views_generator.rb +0 -21
  119. data/rails/init.rb +0 -2
  120. data/test/integration/rack_middleware_test.rb +0 -47
  121. data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
@@ -14,11 +14,7 @@ module Devise
14
14
  # # creates a new token and send it with instructions about how to reset the password
15
15
  # User.find(1).send_reset_password_instructions
16
16
  module Recoverable
17
- def self.included(base)
18
- base.class_eval do
19
- extend ClassMethods
20
- end
21
- end
17
+ extend ActiveSupport::Concern
22
18
 
23
19
  # Update password saving the record and clearing token. Returns true if
24
20
  # the passwords are valid and the record was saved, false otherwise.
@@ -32,7 +28,7 @@ module Devise
32
28
  # Resets reset password token and send reset password instructions by email
33
29
  def send_reset_password_instructions
34
30
  generate_reset_password_token!
35
- ::DeviseMailer.deliver_reset_password_instructions(self)
31
+ ::Devise::Mailer.reset_password_instructions(self).deliver
36
32
  end
37
33
 
38
34
  protected
@@ -45,7 +41,7 @@ module Devise
45
41
  # Resets the reset password token with and save the record without
46
42
  # validating
47
43
  def generate_reset_password_token!
48
- generate_reset_password_token && save(false)
44
+ generate_reset_password_token && save(:validate => false)
49
45
  end
50
46
 
51
47
  # Removes reset_password token
@@ -69,7 +65,7 @@ module Devise
69
65
  # try saving the record. If not user is found, returns a new user
70
66
  # containing an error in reset_password_token attribute.
71
67
  # Attributes must contain reset_password_token, password and confirmation
72
- def reset_password_by_token(attributes={})
68
+ def reset_password!(attributes={})
73
69
  recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token])
74
70
  recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) unless recoverable.new_record?
75
71
  recoverable
@@ -30,21 +30,18 @@ module Devise
30
30
  # # lookup the user based on the incoming cookie information
31
31
  # User.serialize_from_cookie(cookie_string)
32
32
  module Rememberable
33
+ extend ActiveSupport::Concern
33
34
 
34
- def self.included(base)
35
- base.class_eval do
36
- extend ClassMethods
37
-
38
- # Remember me option available in after_authentication hook.
39
- attr_accessor :remember_me
40
- end
35
+ included do
36
+ # Remember me option available in after_authentication hook.
37
+ attr_accessor :remember_me
41
38
  end
42
39
 
43
40
  # Generate a new remember token and save the record without validations.
44
41
  def remember_me!
45
42
  self.remember_token = Devise.friendly_token
46
43
  self.remember_created_at = Time.now.utc
47
- save(false)
44
+ save(:validate => false)
48
45
  end
49
46
 
50
47
  # Removes the remember token only if it exists, and save the record
@@ -53,7 +50,7 @@ module Devise
53
50
  if remember_token
54
51
  self.remember_token = nil
55
52
  self.remember_created_at = nil
56
- save(false)
53
+ save(:validate => false)
57
54
  end
58
55
  end
59
56
 
@@ -11,9 +11,7 @@ module Devise
11
11
  #
12
12
  # timeout_in: the time you want to timeout the user session without activity.
13
13
  module Timeoutable
14
- def self.included(base)
15
- base.extend ClassMethods
16
- end
14
+ extend ActiveSupport::Concern
17
15
 
18
16
  # Checks whether the user session has expired based on configured time.
19
17
  def timedout?(last_access)
@@ -18,11 +18,10 @@ module Devise
18
18
  # User.find(1).valid_authentication_token?('rI1t6PKQ8yP7VetgwdybB') # returns true/false
19
19
  #
20
20
  module TokenAuthenticatable
21
- def self.included(base)
22
- base.class_eval do
23
- extend ClassMethods
24
- before_save :ensure_authentication_token
25
- end
21
+ extend ActiveSupport::Concern
22
+
23
+ included do
24
+ before_save :ensure_authentication_token
26
25
  end
27
26
 
28
27
  # Generate new authentication token (a.k.a. "single access token").
@@ -15,7 +15,7 @@ module Devise
15
15
 
16
16
  base.class_eval do
17
17
  validates_presence_of :email
18
- validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :case_sensitive => false, :allow_blank => true
18
+ validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :allow_blank => true
19
19
  validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true
20
20
 
21
21
  with_options :if => :password_required? do |v|
@@ -34,6 +34,15 @@ module Devise
34
34
  "to the following methods: #{unavailable_validations.to_sentence}."
35
35
  end
36
36
  end
37
+
38
+ protected
39
+
40
+ # Checks whether a password is needed or not. For validations only.
41
+ # Passwords are always required if it's a new record, or if the password
42
+ # or confirmation are being set somewhere.
43
+ def password_required?
44
+ new_record? || !password.nil? || !password_confirmation.nil?
45
+ end
37
46
  end
38
47
  end
39
48
  end
@@ -1,19 +1,8 @@
1
1
  module Devise
2
2
  module Orm
3
3
  module MongoMapper
4
- module InstanceMethods
5
- def save(options={})
6
- if options == false
7
- super(:validate => false)
8
- else
9
- super
10
- end
11
- end
12
- end
13
-
14
4
  def self.included_modules_hook(klass)
15
- klass.send :extend, self
16
- klass.send :include, InstanceMethods
5
+ klass.send :extend, self
17
6
  yield
18
7
 
19
8
  klass.devise_modules.each do |mod|
@@ -22,11 +11,14 @@ module Devise
22
11
  end
23
12
 
24
13
  def find(*args)
14
+ options = args.extract_options!
25
15
  case args.first
26
- when :first, :all
27
- send(args.shift, *args)
28
- else
29
- super
16
+ when :first
17
+ first(options)
18
+ when :all
19
+ all(options)
20
+ else
21
+ super
30
22
  end
31
23
  end
32
24
 
@@ -43,10 +35,5 @@ module Devise
43
35
  end
44
36
  end
45
37
 
46
- if MongoMapper::Version >= "0.8.0"
47
- MongoMapper::Plugins::Document::ClassMethods.send(:include, Devise::Models)
48
- MongoMapper::Plugins::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)
49
- else
50
- MongoMapper::Document::ClassMethods.send(:include, Devise::Models)
51
- MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)
52
- end
38
+ MongoMapper::Document::ClassMethods.send(:include, Devise::Models)
39
+ MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)
@@ -1,14 +1,16 @@
1
1
  require 'devise/rails/routes'
2
2
  require 'devise/rails/warden_compat'
3
3
 
4
- Rails.configuration.after_initialize do
5
- require "devise/orm/#{Devise.orm}"
4
+ module Devise
5
+ class Engine < ::Rails::Engine
6
+ engine_name :devise
6
7
 
7
- # Adds Warden Manager to Rails middleware stack, configuring default devise
8
- # strategy and also the failure app.
9
- Rails.configuration.middleware.use Warden::Manager do |config|
10
- Devise.configure_warden(config)
11
- end
8
+ config.middleware.use Warden::Manager do |config|
9
+ Devise.configure_warden(config)
10
+ end
12
11
 
13
- I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), 'locales', 'en.yml'))
14
- end
12
+ config.after_initialize do
13
+ require "devise/orm/#{Devise.orm}"
14
+ end
15
+ end
16
+ end
@@ -1,11 +1,10 @@
1
- module ActionController::Routing
1
+ module ActionDispatch::Routing
2
2
  class RouteSet #:nodoc:
3
-
4
3
  # Ensure Devise modules are included only after loading routes, because we
5
4
  # need devise_for mappings already declared to create magic filters and
6
5
  # helpers.
7
- def load_routes_with_devise!
8
- load_routes_without_devise!
6
+ def finalize_with_devise!
7
+ finalize_without_devise!
9
8
  return if Devise.mappings.empty?
10
9
 
11
10
  ActionController::Base.send :include, Devise::Controllers::Helpers
@@ -13,121 +12,128 @@ module ActionController::Routing
13
12
 
14
13
  ActionView::Base.send :include, Devise::Controllers::UrlHelpers
15
14
  end
16
- alias_method_chain :load_routes!, :devise
15
+ alias_method_chain :finalize!, :devise
16
+ end
17
17
 
18
- class Mapper #:doc:
19
- # Includes devise_for method for routes. This method is responsible to
20
- # generate all needed routes for devise, based on what modules you have
21
- # defined in your model.
22
- # Examples: Let's say you have an User model configured to use
23
- # authenticatable, confirmable and recoverable modules. After creating this
24
- # inside your routes:
25
- #
26
- # map.devise_for :users
27
- #
28
- # this method is going to look inside your User model and create the
29
- # needed routes:
30
- #
31
- # # Session routes for Authenticatable (default)
32
- # new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
33
- # user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
34
- # destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
35
- #
36
- # # Password routes for Recoverable, if User model has :recoverable configured
37
- # new_user_password GET /users/password/new(.:format) {:controller=>"passwords", :action=>"new"}
38
- # edit_user_password GET /users/password/edit(.:format) {:controller=>"passwords", :action=>"edit"}
39
- # user_password PUT /users/password(.:format) {:controller=>"passwords", :action=>"update"}
40
- # POST /users/password(.:format) {:controller=>"passwords", :action=>"create"}
41
- #
42
- # # Confirmation routes for Confirmable, if User model has :confirmable configured
43
- # new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"confirmations", :action=>"new"}
44
- # user_confirmation GET /users/confirmation(.:format) {:controller=>"confirmations", :action=>"show"}
45
- # POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
46
- #
47
- # You can configure your routes with some options:
48
- #
49
- # * :class_name => setup a different class to be looked up by devise, if it cannot be correctly find by the route name.
50
- #
51
- # map.devise_for :users, :class_name => 'Account'
52
- #
53
- # * :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:
54
- #
55
- # map.devise_for :users, :as => 'accounts'
56
- #
57
- # * :scope => setup the scope name. This is used as the instance variable name in controller, as the name in routes and the scope given to warden. Defaults to the singular of the given name:
58
- #
59
- # map.devise_for :users, :scope => :account
60
- #
61
- # * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :password and :confirmation.
62
- #
63
- # map.devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
64
- #
65
- # * :path_prefix => the path prefix to be used in all routes.
66
- #
67
- # map.devise_for :users, :path_prefix => "/:locale"
68
- #
69
- # * :sign_out_via => restirct the HTTP method(s) accepted for the :sign_out action (default: :get), possible values are :post, :get, :put, :delete and :any, e.g. if you wish to restrict this to accept only :delete requests you should do:
70
- #
71
- # map.devise_for :users, :sign_out_via => :delete
72
- #
73
- # You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
74
- #
75
- # Any other options will be passed to route definition. If you need conditions for your routes, just map:
76
- #
77
- # map.devise_for :users, :conditions => { :subdomain => /.+/ }
78
- #
79
- # If you are using a dynamic prefix, like :locale above, you need to configure default_url_options through Devise. You can do that in config/initializers/devise.rb or setting a Devise.default_url_options:
80
- #
81
- # Devise.default_url_options do
82
- # { :locale => I18n.locale }
83
- # end
84
- #
85
- def devise_for(*resources)
86
- options = resources.extract_options!
18
+ class Mapper
19
+ # Includes devise_for method for routes. This method is responsible to
20
+ # generate all needed routes for devise, based on what modules you have
21
+ # defined in your model.
22
+ # Examples: Let's say you have an User model configured to use
23
+ # authenticatable, confirmable and recoverable modules. After creating this
24
+ # inside your routes:
25
+ #
26
+ # devise_for :users
27
+ #
28
+ # this method is going to look inside your User model and create the
29
+ # needed routes:
30
+ #
31
+ # # Session routes for Authenticatable (default)
32
+ # new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
33
+ # user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
34
+ # destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
35
+ #
36
+ # # Password routes for Recoverable, if User model has :recoverable configured
37
+ # new_user_password GET /users/password/new(.:format) {:controller=>"passwords", :action=>"new"}
38
+ # edit_user_password GET /users/password/edit(.:format) {:controller=>"passwords", :action=>"edit"}
39
+ # user_password PUT /users/password(.:format) {:controller=>"passwords", :action=>"update"}
40
+ # POST /users/password(.:format) {:controller=>"passwords", :action=>"create"}
41
+ #
42
+ # # Confirmation routes for Confirmable, if User model has :confirmable configured
43
+ # new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"confirmations", :action=>"new"}
44
+ # user_confirmation GET /users/confirmation(.:format) {:controller=>"confirmations", :action=>"show"}
45
+ # POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
46
+ #
47
+ # You can configure your routes with some options:
48
+ #
49
+ # * :class_name => setup a different class to be looked up by devise,
50
+ # if it cannot be correctly find by the route name.
51
+ #
52
+ # devise_for :users, :class_name => 'Account'
53
+ #
54
+ # * :as => allows you to setup path name that will be used, as rails routes does.
55
+ # The following route configuration would setup your route as /accounts instead of /users:
56
+ #
57
+ # devise_for :users, :as => 'accounts'
58
+ #
59
+ # * :scope => setup the scope name. This is used as the instance variable name in controller,
60
+ # as the name in routes and the scope given to warden. Defaults to the singular of the given name:
61
+ #
62
+ # devise_for :users, :scope => :account
63
+ #
64
+ # * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
65
+ # :password, :confirmation, :unlock.
66
+ #
67
+ # devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
68
+ #
69
+ # * :path_prefix => the path prefix to be used in all routes.
70
+ #
71
+ # devise_for :users, :path_prefix => "/:locale"
72
+ #
73
+ # If you are using a dynamic prefix, like :locale above, you need to configure default_url_options through Devise.
74
+ # You can do that in config/initializers/devise.rb or setting a Devise.default_url_options:
75
+ #
76
+ # Devise.default_url_options do
77
+ # { :locale => I18n.locale }
78
+ # end
79
+ #
80
+ # * :controllers => the controller which should be used. All routes by default points to Devise controllers.
81
+ # However, if you want them to point to custom controller, you should do:
82
+ #
83
+ # devise_for :users, :controllers => { :sessions => "users/sessions" }
84
+ #
85
+ def devise_for(*resources)
86
+ options = resources.extract_options!
87
+ resources.map!(&:to_sym)
87
88
 
88
- resources.map!(&:to_sym)
89
- resources.each do |resource|
90
- mapping = Devise::Mapping.new(resource, options.dup)
91
- Devise.default_scope ||= mapping.name
92
- Devise.mappings[mapping.name] = mapping
89
+ controllers = Hash.new { |h,k| h[k] = "devise/#{k}" }
90
+ controllers.merge!(options.delete(:controllers) || {})
93
91
 
94
- route_options = mapping.route_options.merge(:path_prefix => mapping.raw_path, :name_prefix => "#{mapping.name}_")
92
+ resources.each do |resource|
93
+ mapping = Devise::Mapping.new(resource, options.dup)
95
94
 
96
- with_options(route_options) do |routes|
97
- mapping.for.each do |mod|
98
- send(mod, routes, mapping) if self.respond_to?(mod, true)
99
- end
100
- end
95
+ Devise.default_scope ||= mapping.name
96
+ Devise.mappings[mapping.name] = mapping
97
+
98
+ mapping.for.each do |mod|
99
+ send(mod, mapping, controllers) if self.respond_to?(mod, true)
101
100
  end
102
101
  end
102
+ end
103
103
 
104
- protected
104
+ protected
105
105
 
106
- def database_authenticatable(routes, mapping)
107
- routes.with_options(:controller => 'sessions', :name_prefix => nil) do |session|
108
- session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'new', :conditions => { :method => :get })
109
- session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => { :method => :post })
110
- destroy_options = { :action => 'destroy' }
111
- destroy_options.merge! :conditions => { :method => mapping.sign_out_via } unless mapping.sign_out_via == :any
112
- session.send(:"destroy_#{mapping.name}_session", mapping.path_names[:sign_out], destroy_options)
113
- end
106
+ def authenticatable(mapping, controllers)
107
+ scope mapping.raw_path do
108
+ get mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#new", :as => :"new_#{mapping.name}_session"
109
+ post mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#create", :as => :"#{mapping.name}_session"
110
+ get mapping.path_names[:sign_out], :to => "#{controllers[:sessions]}#destroy", :as => :"destroy_#{mapping.name}_session"
114
111
  end
115
-
116
- def confirmable(routes, mapping)
117
- routes.resource :confirmation, :only => [:new, :create, :show], :as => mapping.path_names[:confirmation]
112
+ end
113
+
114
+ def recoverable(mapping, controllers)
115
+ scope mapping.raw_path, :name_prefix => mapping.name do
116
+ resource :password, :only => [:new, :create, :edit, :update], :as => mapping.path_names[:password], :controller => controllers[:passwords]
118
117
  end
119
-
120
- def lockable(routes, mapping)
121
- routes.resource :unlock, :only => [:new, :create, :show], :as => mapping.path_names[:unlock]
118
+ end
119
+
120
+ def confirmable(mapping, controllers)
121
+ scope mapping.raw_path, :name_prefix => mapping.name do
122
+ resource :confirmation, :only => [:new, :create, :show], :as => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
122
123
  end
123
-
124
- def recoverable(routes, mapping)
125
- routes.resource :password, :only => [:new, :create, :edit, :update], :as => mapping.path_names[:password]
124
+ end
125
+
126
+ def lockable(mapping, controllers)
127
+ scope mapping.raw_path, :name_prefix => mapping.name do
128
+ resource :unlock, :only => [:new, :create, :show], :as => mapping.path_names[:unlock], :controller => controllers[:unlocks]
126
129
  end
130
+ end
127
131
 
128
- def registerable(routes, mapping)
129
- routes.resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.raw_path[1..-1], :path_prefix => nil, :path_names => { :new => mapping.path_names[:sign_up] }
132
+ def registerable(mapping, controllers)
133
+ scope :name_prefix => mapping.name do
134
+ resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.raw_path[1..-1],
135
+ :path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations]
130
136
  end
131
- end
137
+ end
132
138
  end
133
- end
139
+ end