namxam-devise 1.1.0.win

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. data/CHANGELOG.rdoc +455 -0
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +118 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +311 -0
  6. data/Rakefile +55 -0
  7. data/TODO +3 -0
  8. data/app/controllers/devise/confirmations_controller.rb +33 -0
  9. data/app/controllers/devise/passwords_controller.rb +41 -0
  10. data/app/controllers/devise/registrations_controller.rb +57 -0
  11. data/app/controllers/devise/sessions_controller.rb +23 -0
  12. data/app/controllers/devise/unlocks_controller.rb +34 -0
  13. data/app/helpers/devise_helper.rb +17 -0
  14. data/app/mailers/devise/mailer.rb +71 -0
  15. data/app/views/devise/confirmations/new.html.erb +12 -0
  16. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  17. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  18. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  19. data/app/views/devise/passwords/edit.html.erb +16 -0
  20. data/app/views/devise/passwords/new.html.erb +12 -0
  21. data/app/views/devise/registrations/edit.html.erb +25 -0
  22. data/app/views/devise/registrations/new.html.erb +18 -0
  23. data/app/views/devise/sessions/new.html.erb +17 -0
  24. data/app/views/devise/shared/_links.erb +19 -0
  25. data/app/views/devise/unlocks/new.html.erb +12 -0
  26. data/config/locales/en.yml +39 -0
  27. data/lib/devise.rb +290 -0
  28. data/lib/devise/controllers/helpers.rb +231 -0
  29. data/lib/devise/controllers/internal_helpers.rb +98 -0
  30. data/lib/devise/controllers/scoped_views.rb +35 -0
  31. data/lib/devise/controllers/url_helpers.rb +41 -0
  32. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  33. data/lib/devise/encryptors/base.rb +20 -0
  34. data/lib/devise/encryptors/bcrypt.rb +19 -0
  35. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  36. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  37. data/lib/devise/encryptors/sha1.rb +25 -0
  38. data/lib/devise/encryptors/sha512.rb +25 -0
  39. data/lib/devise/failure_app.rb +107 -0
  40. data/lib/devise/hooks/activatable.rb +11 -0
  41. data/lib/devise/hooks/forgetable.rb +11 -0
  42. data/lib/devise/hooks/rememberable.rb +35 -0
  43. data/lib/devise/hooks/timeoutable.rb +22 -0
  44. data/lib/devise/hooks/trackable.rb +9 -0
  45. data/lib/devise/mapping.rb +103 -0
  46. data/lib/devise/models.rb +80 -0
  47. data/lib/devise/models/authenticatable.rb +126 -0
  48. data/lib/devise/models/confirmable.rb +164 -0
  49. data/lib/devise/models/database_authenticatable.rb +110 -0
  50. data/lib/devise/models/lockable.rb +165 -0
  51. data/lib/devise/models/recoverable.rb +81 -0
  52. data/lib/devise/models/registerable.rb +8 -0
  53. data/lib/devise/models/rememberable.rb +104 -0
  54. data/lib/devise/models/timeoutable.rb +26 -0
  55. data/lib/devise/models/token_authenticatable.rb +60 -0
  56. data/lib/devise/models/trackable.rb +30 -0
  57. data/lib/devise/models/validatable.rb +53 -0
  58. data/lib/devise/modules.rb +23 -0
  59. data/lib/devise/orm/active_record.rb +36 -0
  60. data/lib/devise/orm/mongoid.rb +29 -0
  61. data/lib/devise/path_checker.rb +18 -0
  62. data/lib/devise/rails.rb +69 -0
  63. data/lib/devise/rails/routes.rb +248 -0
  64. data/lib/devise/rails/warden_compat.rb +39 -0
  65. data/lib/devise/schema.rb +97 -0
  66. data/lib/devise/strategies/authenticatable.rb +111 -0
  67. data/lib/devise/strategies/base.rb +33 -0
  68. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  69. data/lib/devise/strategies/rememberable.rb +43 -0
  70. data/lib/devise/strategies/token_authenticatable.rb +49 -0
  71. data/lib/devise/test_helpers.rb +90 -0
  72. data/lib/devise/version.rb +3 -0
  73. data/lib/generators/active_record/devise_generator.rb +28 -0
  74. data/lib/generators/active_record/templates/migration.rb +29 -0
  75. data/lib/generators/devise/devise_generator.rb +17 -0
  76. data/lib/generators/devise/install_generator.rb +24 -0
  77. data/lib/generators/devise/orm_helpers.rb +23 -0
  78. data/lib/generators/devise/templates/README +25 -0
  79. data/lib/generators/devise/templates/devise.rb +139 -0
  80. data/lib/generators/devise/views_generator.rb +63 -0
  81. data/lib/generators/devise_install_generator.rb +4 -0
  82. data/lib/generators/devise_views_generator.rb +4 -0
  83. data/lib/generators/mongoid/devise_generator.rb +17 -0
  84. data/test/controllers/helpers_test.rb +213 -0
  85. data/test/controllers/internal_helpers_test.rb +51 -0
  86. data/test/controllers/url_helpers_test.rb +58 -0
  87. data/test/devise_test.rb +65 -0
  88. data/test/encryptors_test.rb +30 -0
  89. data/test/failure_app_test.rb +123 -0
  90. data/test/integration/authenticatable_test.rb +344 -0
  91. data/test/integration/confirmable_test.rb +104 -0
  92. data/test/integration/database_authenticatable_test.rb +38 -0
  93. data/test/integration/http_authenticatable_test.rb +49 -0
  94. data/test/integration/lockable_test.rb +109 -0
  95. data/test/integration/recoverable_test.rb +141 -0
  96. data/test/integration/registerable_test.rb +153 -0
  97. data/test/integration/rememberable_test.rb +91 -0
  98. data/test/integration/timeoutable_test.rb +80 -0
  99. data/test/integration/token_authenticatable_test.rb +88 -0
  100. data/test/integration/trackable_test.rb +64 -0
  101. data/test/mailers/confirmation_instructions_test.rb +80 -0
  102. data/test/mailers/reset_password_instructions_test.rb +68 -0
  103. data/test/mailers/unlock_instructions_test.rb +62 -0
  104. data/test/mapping_test.rb +85 -0
  105. data/test/models/confirmable_test.rb +221 -0
  106. data/test/models/database_authenticatable_test.rb +148 -0
  107. data/test/models/lockable_test.rb +188 -0
  108. data/test/models/recoverable_test.rb +138 -0
  109. data/test/models/rememberable_test.rb +176 -0
  110. data/test/models/timeoutable_test.rb +28 -0
  111. data/test/models/token_authenticatable_test.rb +37 -0
  112. data/test/models/trackable_test.rb +5 -0
  113. data/test/models/validatable_test.rb +99 -0
  114. data/test/models_test.rb +77 -0
  115. data/test/orm/active_record.rb +9 -0
  116. data/test/orm/mongoid.rb +10 -0
  117. data/test/rails_app/app/active_record/admin.rb +3 -0
  118. data/test/rails_app/app/active_record/shim.rb +2 -0
  119. data/test/rails_app/app/active_record/user.rb +7 -0
  120. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  121. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  122. data/test/rails_app/app/controllers/home_controller.rb +7 -0
  123. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  124. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  125. data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
  126. data/test/rails_app/app/controllers/users_controller.rb +18 -0
  127. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  128. data/test/rails_app/app/mongoid/admin.rb +6 -0
  129. data/test/rails_app/app/mongoid/shim.rb +16 -0
  130. data/test/rails_app/app/mongoid/user.rb +10 -0
  131. data/test/rails_app/config/application.rb +35 -0
  132. data/test/rails_app/config/boot.rb +13 -0
  133. data/test/rails_app/config/environment.rb +5 -0
  134. data/test/rails_app/config/environments/development.rb +19 -0
  135. data/test/rails_app/config/environments/production.rb +33 -0
  136. data/test/rails_app/config/environments/test.rb +33 -0
  137. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  138. data/test/rails_app/config/initializers/devise.rb +136 -0
  139. data/test/rails_app/config/initializers/inflections.rb +2 -0
  140. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  141. data/test/rails_app/config/routes.rb +47 -0
  142. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
  143. data/test/rails_app/db/schema.rb +86 -0
  144. data/test/routes_test.rb +146 -0
  145. data/test/support/assertions.rb +24 -0
  146. data/test/support/helpers.rb +54 -0
  147. data/test/support/integration.rb +88 -0
  148. data/test/support/test_silencer.rb +5 -0
  149. data/test/support/webrat/integrations/rails.rb +32 -0
  150. data/test/test_helper.rb +21 -0
  151. data/test/test_helpers_test.rb +72 -0
  152. metadata +230 -0
@@ -0,0 +1,26 @@
1
+ require 'devise/hooks/timeoutable'
2
+
3
+ module Devise
4
+ module Models
5
+ # Timeoutable takes care of veryfing whether a user session has already
6
+ # expired or not. When a session expires after the configured time, the user
7
+ # will be asked for credentials again, it means, he/she will be redirected
8
+ # to the sign in page.
9
+ #
10
+ # Configuration:
11
+ #
12
+ # timeout_in: the time you want to timeout the user session without activity.
13
+ module Timeoutable
14
+ extend ActiveSupport::Concern
15
+
16
+ # Checks whether the user session has expired based on configured time.
17
+ def timedout?(last_access)
18
+ last_access && last_access <= self.class.timeout_in.ago
19
+ end
20
+
21
+ module ClassMethods
22
+ Devise::Models.config(self, :timeout_in)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,60 @@
1
+ require 'devise/strategies/token_authenticatable'
2
+
3
+ module Devise
4
+ module Models
5
+ # The TokenAuthenticatable module is responsible for generating an authentication token and
6
+ # validating the authenticity of the same while signing in.
7
+ #
8
+ # This module only provides a few helpers to help you manage the token. Creating and resetting
9
+ # the token is your responsibility.
10
+ #
11
+ # == Configuration:
12
+ #
13
+ # You can overwrite configuration values by setting in globally in Devise (+Devise.setup+),
14
+ # using devise method, or overwriting the respective instance method.
15
+ #
16
+ # +token_authentication_key+ - Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
17
+ #
18
+ module TokenAuthenticatable
19
+ extend ActiveSupport::Concern
20
+
21
+ # Generate new authentication token (a.k.a. "single access token").
22
+ def reset_authentication_token
23
+ self.authentication_token = self.class.authentication_token
24
+ end
25
+
26
+ # Generate new authentication token and save the record.
27
+ def reset_authentication_token!
28
+ reset_authentication_token
29
+ self.save(:validate => false)
30
+ end
31
+
32
+ # Generate authentication token unless already exists.
33
+ def ensure_authentication_token
34
+ self.reset_authentication_token if self.authentication_token.blank?
35
+ end
36
+
37
+ # Generate authentication token unless already exists and save the record.
38
+ def ensure_authentication_token!
39
+ self.reset_authentication_token! if self.authentication_token.blank?
40
+ end
41
+
42
+ # Hook called after token authentication.
43
+ def after_token_authentication
44
+ end
45
+
46
+ module ClassMethods
47
+ def find_for_token_authentication(conditions)
48
+ find_for_authentication(:authentication_token => conditions[token_authentication_key])
49
+ end
50
+
51
+ # Generate a token checking if one does not already exist in the database.
52
+ def authentication_token
53
+ generate_token(:authentication_token)
54
+ end
55
+
56
+ ::Devise::Models.config(self, :token_authentication_key)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,30 @@
1
+ require 'devise/hooks/trackable'
2
+
3
+ module Devise
4
+ module Models
5
+ # Track information about your user sign in. It tracks the following columns:
6
+ #
7
+ # * sign_in_count - Increased every time a sign in is made (by form, openid, oauth)
8
+ # * current_sign_in_at - A tiemstamp updated when the user signs in
9
+ # * last_sign_in_at - Holds the timestamp of the previous sign in
10
+ # * current_sign_in_ip - The remote ip updated when the user sign in
11
+ # * last_sign_in_at - Holds the remote ip of the previous sign in
12
+ #
13
+ module Trackable
14
+ def update_tracked_fields!(request)
15
+ old_current, new_current = self.current_sign_in_at, Time.now
16
+ self.last_sign_in_at = old_current || new_current
17
+ self.current_sign_in_at = new_current
18
+
19
+ old_current, new_current = self.current_sign_in_ip, request.remote_ip
20
+ self.last_sign_in_ip = old_current || new_current
21
+ self.current_sign_in_ip = new_current
22
+
23
+ self.sign_in_count ||= 0
24
+ self.sign_in_count += 1
25
+
26
+ save(:validate => false)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,53 @@
1
+ module Devise
2
+ module Models
3
+
4
+ # Validatable creates all needed validations for a user email and password.
5
+ # It's optional, given you may want to create the validations by yourself.
6
+ # Automatically validate if the email is present, unique and it's format is
7
+ # valid. Also tests presence of password, confirmation and length
8
+ module Validatable
9
+ # All validations used by this module.
10
+ VALIDATIONS = [ :validates_presence_of, :validates_uniqueness_of, :validates_format_of,
11
+ :validates_confirmation_of, :validates_length_of ].freeze
12
+
13
+ def self.included(base)
14
+ base.extend ClassMethods
15
+ assert_validations_api!(base)
16
+
17
+ base.class_eval do
18
+ validates_presence_of :email
19
+ validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :case_sensitive => false, :allow_blank => true
20
+ validates_format_of :email, :with => email_regexp, :allow_blank => true
21
+
22
+ with_options :if => :password_required? do |v|
23
+ v.validates_presence_of :password
24
+ v.validates_confirmation_of :password
25
+ v.validates_length_of :password, :within => password_length, :allow_blank => true
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.assert_validations_api!(base) #:nodoc:
31
+ unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }
32
+
33
+ unless unavailable_validations.empty?
34
+ raise "Could not use :validatable module since #{base} does not respond " <<
35
+ "to the following methods: #{unavailable_validations.to_sentence}."
36
+ end
37
+ end
38
+
39
+ protected
40
+
41
+ # Checks whether a password is needed or not. For validations only.
42
+ # Passwords are always required if it's a new record, or if the password
43
+ # or confirmation are being set somewhere.
44
+ def password_required?
45
+ !persisted? || !password.nil? || !password_confirmation.nil?
46
+ end
47
+
48
+ module ClassMethods
49
+ Devise::Models.config(self, :email_regexp, :password_length)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_support/core_ext/object/with_options'
2
+
3
+ Devise.with_options :model => true do |d|
4
+ # Strategies first
5
+ d.with_options :strategy => true do |s|
6
+ s.add_module :database_authenticatable, :controller => :sessions, :route => :session
7
+ s.add_module :token_authenticatable, :controller => :sessions, :route => :session
8
+ s.add_module :rememberable
9
+ end
10
+
11
+ # Misc after
12
+ d.add_module :recoverable, :controller => :passwords, :route => :password
13
+ d.add_module :registerable, :controller => :registrations, :route => :registration
14
+ d.add_module :validatable
15
+
16
+ # The ones which can sign out after
17
+ d.add_module :confirmable, :controller => :confirmations, :route => :confirmation
18
+ d.add_module :lockable, :controller => :unlocks, :route => :unlock
19
+ d.add_module :timeoutable
20
+
21
+ # Stats for last, so we make sure the user is really signed in
22
+ d.add_module :trackable
23
+ end
@@ -0,0 +1,36 @@
1
+ module Devise
2
+ module Orm
3
+ # This module contains some helpers and handle schema (migrations):
4
+ #
5
+ # create_table :accounts do |t|
6
+ # t.database_authenticatable
7
+ # t.confirmable
8
+ # t.recoverable
9
+ # t.rememberable
10
+ # t.trackable
11
+ # t.lockable
12
+ # t.timestamps
13
+ # end
14
+ #
15
+ # However this method does not add indexes. If you need them, here is the declaration:
16
+ #
17
+ # add_index "accounts", ["email"], :name => "email", :unique => true
18
+ # add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
19
+ # add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
20
+ #
21
+ module ActiveRecord
22
+ module Schema
23
+ include Devise::Schema
24
+
25
+ # Tell how to apply schema methods.
26
+ def apply_devise_schema(name, type, options={})
27
+ column name, type.to_s.downcase.to_sym, options
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ ActiveRecord::Base.extend Devise::Models
35
+ ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema
36
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema
@@ -0,0 +1,29 @@
1
+ module Devise
2
+ module Orm
3
+ module Mongoid
4
+ module Hook
5
+ def devise_modules_hook!
6
+ extend Schema
7
+ yield
8
+ return unless Devise.apply_schema
9
+ devise_modules.each { |m| send(m) if respond_to?(m, true) }
10
+ end
11
+ end
12
+
13
+ module Schema
14
+ include Devise::Schema
15
+
16
+ # Tell how to apply schema methods
17
+ def apply_devise_schema(name, type, options={})
18
+ type = Time if type == DateTime
19
+ field name, { :type => type }.merge(options)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Mongoid::Document::ClassMethods.class_eval do
27
+ include Devise::Models
28
+ include Devise::Orm::Mongoid::Hook
29
+ end
@@ -0,0 +1,18 @@
1
+ module Devise
2
+ class PathChecker
3
+ include Rails.application.routes.url_helpers
4
+
5
+ def self.default_url_options(*args)
6
+ ApplicationController.default_url_options(*args)
7
+ end
8
+
9
+ def initialize(env, scope)
10
+ @current_path = "/#{env["SCRIPT_NAME"]}/#{env["PATH_INFO"]}".squeeze("/")
11
+ @scope = scope
12
+ end
13
+
14
+ def signing_out?
15
+ @current_path == send("destroy_#{@scope}_session_path")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,69 @@
1
+ require 'devise/rails/routes'
2
+ require 'devise/rails/warden_compat'
3
+
4
+ # Include UrlHelpers in ActionController and ActionView as soon as they are loaded.
5
+ ActiveSupport.on_load(:action_controller) { include Devise::Controllers::UrlHelpers }
6
+ ActiveSupport.on_load(:action_view) { include Devise::Controllers::UrlHelpers }
7
+
8
+ module Devise
9
+ class Engine < ::Rails::Engine
10
+ config.devise = Devise
11
+
12
+ config.app_middleware.use Warden::Manager do |config|
13
+ Devise.warden_config = config
14
+ end
15
+
16
+ # Force routes to be loaded if we are doing any eager load.
17
+ config.before_eager_load { |app| app.reload_routes! }
18
+
19
+ config.after_initialize do
20
+ Devise.encryptor ||= begin
21
+ warn "[WARNING] config.encryptor is not set in your config/initializers/devise.rb. " \
22
+ "Devise will then set it to :bcrypt. If you were using the previous default " \
23
+ "encryptor, please add config.encryptor = :sha1 to your configuration file." if Devise.mailer_sender
24
+ :authlogic_sha512
25
+ end
26
+ end
27
+
28
+ initializer "devise.add_filters" do |app|
29
+ app.config.filter_parameters += [:password, :password_confirmation]
30
+ app.config.filter_parameters.uniq
31
+ end
32
+
33
+ unless Rails.env.production?
34
+ config.after_initialize do
35
+ actions = [:confirmation_instructions, :reset_password_instructions, :unlock_instructions]
36
+
37
+ translations = begin
38
+ I18n.t("devise.mailer", :raise => true).map { |k, v| k if v.is_a?(String) }.compact
39
+ rescue Exception => e # Do not care if something fails
40
+ []
41
+ end
42
+
43
+ keys = actions & translations
44
+
45
+ keys.each do |key|
46
+ ActiveSupport::Deprecation.warn "The I18n message 'devise.mailer.#{key}' is deprecated. " \
47
+ "Please use 'devise.mailer.#{key}.subject' instead."
48
+ end
49
+ end
50
+
51
+ config.after_initialize do
52
+ flash = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
53
+
54
+ translations = begin
55
+ I18n.t("devise.sessions", :raise => true).keys
56
+ rescue Exception => e # Do not care if something fails
57
+ []
58
+ end
59
+
60
+ keys = flash & translations
61
+
62
+ if keys.any?
63
+ ActiveSupport::Deprecation.warn "The following I18n messages in 'devise.sessions' " \
64
+ "are deprecated: #{keys.to_sentence}. Please move them to 'devise.failure' instead."
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,248 @@
1
+ module ActionDispatch::Routing
2
+ class RouteSet #:nodoc:
3
+ # Ensure Devise modules are included only after loading routes, because we
4
+ # need devise_for mappings already declared to create filters and helpers.
5
+ def finalize_with_devise!
6
+ finalize_without_devise!
7
+ Devise.configure_warden!
8
+ ActionController::Base.send :include, Devise::Controllers::Helpers
9
+ end
10
+ alias_method_chain :finalize!, :devise
11
+ end
12
+
13
+ class Mapper
14
+ # Includes devise_for method for routes. This method is responsible to
15
+ # generate all needed routes for devise, based on what modules you have
16
+ # defined in your model.
17
+ #
18
+ # ==== Examples
19
+ #
20
+ # Let's say you have an User model configured to use authenticatable,
21
+ # confirmable and recoverable modules. After creating this inside your routes:
22
+ #
23
+ # devise_for :users
24
+ #
25
+ # This method is going to look inside your User model and create the
26
+ # needed routes:
27
+ #
28
+ # # Session routes for Authenticatable (default)
29
+ # new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"}
30
+ # user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
31
+ # destroy_user_session GET /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
32
+ #
33
+ # # Password routes for Recoverable, if User model has :recoverable configured
34
+ # new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
35
+ # edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
36
+ # user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
37
+ # POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
38
+ #
39
+ # # Confirmation routes for Confirmable, if User model has :confirmable configured
40
+ # new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
41
+ # user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
42
+ # POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
43
+ #
44
+ # ==== Options
45
+ #
46
+ # You can configure your routes with some options:
47
+ #
48
+ # * :class_name => setup a different class to be looked up by devise,
49
+ # if it cannot be correctly find by the route name.
50
+ #
51
+ # devise_for :users, :class_name => 'Account'
52
+ #
53
+ # * :path => allows you to setup path name that will be used, as rails routes does.
54
+ # The following route configuration would setup your route as /accounts instead of /users:
55
+ #
56
+ # devise_for :users, :path => 'accounts'
57
+ #
58
+ # * :singular => setup the singular name for the given resource. This is used as the instance variable name in
59
+ # controller, as the name in routes and the scope given to warden.
60
+ #
61
+ # devise_for :users, :singular => :user
62
+ #
63
+ # * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
64
+ # :password, :confirmation, :unlock.
65
+ #
66
+ # devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
67
+ #
68
+ # * :controllers => the controller which should be used. All routes by default points to Devise controllers.
69
+ # However, if you want them to point to custom controller, you should do:
70
+ #
71
+ # devise_for :users, :controllers => { :sessions => "users/sessions" }
72
+ #
73
+ # * :module => the namespace to find controlers. By default, devise will access devise/sessions,
74
+ # devise/registrations and so on. If you want to namespace all at once, use module:
75
+ #
76
+ # devise_for :users, :module => "users"
77
+ #
78
+ # Notice that whenever you use namespace in the router DSL, it automatically sets the module.
79
+ # So the following setup:
80
+ #
81
+ # namespace :publisher
82
+ # devise_for :account
83
+ # end
84
+ #
85
+ # Will use publisher/sessions controller instead of devise/sessions controller. You can revert
86
+ # this by providing the :module option to devise_for.
87
+ #
88
+ # * :skip => tell which controller you want to skip routes from being created:
89
+ #
90
+ # devise_for :users, :skip => :sessions
91
+ #
92
+ # ==== Scoping
93
+ #
94
+ # Following Rails 3 routes DSL, you can nest devise_for calls inside a scope:
95
+ #
96
+ # scope "/my" do
97
+ # devise_for :users
98
+ # end
99
+ #
100
+ # However, since Devise uses the request path to retrieve the current user, it has one caveats.
101
+ # If you are using a dynamic segment, as below:
102
+ #
103
+ # scope ":locale" do
104
+ # devise_for :users
105
+ # end
106
+ #
107
+ # You are required to configure default_url_options in your ApplicationController class level, so
108
+ # Devise can pick it:
109
+ #
110
+ # class ApplicationController < ActionController::Base
111
+ # def self.default_url_options
112
+ # { :locale => I18n.locale }
113
+ # end
114
+ # end
115
+ #
116
+ def devise_for(*resources)
117
+ options = resources.extract_options!
118
+
119
+ if as = options.delete(:as)
120
+ ActiveSupport::Deprecation.warn ":as is deprecated, please use :path instead."
121
+ options[:path] ||= as
122
+ end
123
+
124
+ if scope = options.delete(:scope)
125
+ ActiveSupport::Deprecation.warn ":scope is deprecated, please use :singular instead."
126
+ options[:singular] ||= scope
127
+ end
128
+
129
+ options[:as] ||= @scope[:as] if @scope[:as].present?
130
+ options[:module] ||= @scope[:module] if @scope[:module].present?
131
+ options[:path_prefix] ||= @scope[:path] if @scope[:path].present?
132
+ options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {})
133
+
134
+ resources.map!(&:to_sym)
135
+
136
+ resources.each do |resource|
137
+ mapping = Devise.add_mapping(resource, options)
138
+
139
+ begin
140
+ raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise)
141
+ rescue NameError => e
142
+ raise unless mapping.class_name == resource.to_s.classify
143
+ warn "[WARNING] You provided devise_for #{resource.inspect} but there is " <<
144
+ "no model #{mapping.class_name} defined in your application"
145
+ next
146
+ rescue NoMethodError => e
147
+ raise unless e.message.include?("undefined method `devise'")
148
+ raise_no_devise_method_error!(mapping.class_name)
149
+ end
150
+
151
+ routes = mapping.routes
152
+ routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym }
153
+
154
+ devise_scope mapping.name do
155
+ yield if block_given?
156
+ with_devise_exclusive_scope mapping.fullpath, mapping.name do
157
+ routes.each { |mod| send(:"devise_#{mod}", mapping, mapping.controllers) }
158
+ end
159
+ end
160
+ end
161
+ end
162
+
163
+ # Allow you to add authentication request from the router:
164
+ #
165
+ # authenticate(:user) do
166
+ # resources :post
167
+ # end
168
+ #
169
+ def authenticate(scope)
170
+ constraint = lambda do |request|
171
+ request.env["warden"].authenticate!(:scope => scope)
172
+ end
173
+
174
+ constraints(constraint) do
175
+ yield
176
+ end
177
+ end
178
+
179
+ # Sets the devise scope to be used in the controller. If you have custom routes,
180
+ # you are required to call this method (also aliased as :as) in order to specify
181
+ # to which controller it is targetted.
182
+ #
183
+ # as :user do
184
+ # get "sign_in", :to => "devise/sessions#new"
185
+ # end
186
+ #
187
+ # Notice you cannot have two scopes mapping to the same URL. And remember, if
188
+ # you try to access a devise controller without specifying a scope, it will
189
+ # raise ActionNotFound error.
190
+ def devise_scope(scope)
191
+ constraint = lambda do |request|
192
+ request.env["devise.mapping"] = Devise.mappings[scope]
193
+ true
194
+ end
195
+
196
+ constraints(constraint) do
197
+ yield
198
+ end
199
+ end
200
+ alias :as :devise_scope
201
+
202
+ protected
203
+
204
+ def devise_session(mapping, controllers) #:nodoc:
205
+ scope :controller => controllers[:sessions], :as => :session do
206
+ get :new, :path => mapping.path_names[:sign_in]
207
+ post :create, :path => mapping.path_names[:sign_in], :as => ""
208
+ get :destroy, :path => mapping.path_names[:sign_out]
209
+ end
210
+ end
211
+
212
+ def devise_password(mapping, controllers) #:nodoc:
213
+ resource :password, :only => [:new, :create, :edit, :update],
214
+ :path => mapping.path_names[:password], :controller => controllers[:passwords]
215
+ end
216
+
217
+ def devise_confirmation(mapping, controllers) #:nodoc:
218
+ resource :confirmation, :only => [:new, :create, :show],
219
+ :path => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
220
+ end
221
+
222
+ def devise_unlock(mapping, controllers) #:nodoc:
223
+ if mapping.to.unlock_strategy_enabled?(:email)
224
+ resource :unlock, :only => [:new, :create, :show],
225
+ :path => mapping.path_names[:unlock], :controller => controllers[:unlocks]
226
+ end
227
+ end
228
+
229
+ def devise_registration(mapping, controllers) #:nodoc:
230
+ resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration],
231
+ :path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations]
232
+ end
233
+
234
+ def with_devise_exclusive_scope(new_path, new_as) #:nodoc:
235
+ old_as, old_path, old_module = @scope[:as], @scope[:path], @scope[:module]
236
+ @scope[:as], @scope[:path], @scope[:module] = new_as, new_path, nil
237
+ yield
238
+ ensure
239
+ @scope[:as], @scope[:path], @scope[:module] = old_as, old_path, old_module
240
+ end
241
+
242
+ def raise_no_devise_method_error!(klass) #:nodoc:
243
+ raise "#{klass} does not respond to 'devise' method. This usually means you haven't " <<
244
+ "loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' " <<
245
+ "inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'"
246
+ end
247
+ end
248
+ end