devise 4.3.0 → 4.9.2

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 (259) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +205 -2
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +214 -57
  5. data/app/controllers/devise/confirmations_controller.rb +3 -0
  6. data/app/controllers/devise/omniauth_callbacks_controller.rb +3 -1
  7. data/app/controllers/devise/passwords_controller.rb +5 -2
  8. data/app/controllers/devise/registrations_controller.rb +32 -12
  9. data/app/controllers/devise/sessions_controller.rb +4 -2
  10. data/app/controllers/devise/unlocks_controller.rb +3 -0
  11. data/app/controllers/devise_controller.rb +6 -3
  12. data/app/helpers/devise_helper.rb +23 -18
  13. data/app/mailers/devise/mailer.rb +7 -5
  14. data/app/views/devise/confirmations/new.html.erb +2 -2
  15. data/app/views/devise/passwords/edit.html.erb +3 -3
  16. data/app/views/devise/passwords/new.html.erb +2 -2
  17. data/app/views/devise/registrations/edit.html.erb +6 -6
  18. data/app/views/devise/registrations/new.html.erb +4 -4
  19. data/app/views/devise/sessions/new.html.erb +4 -4
  20. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  21. data/app/views/devise/shared/_links.html.erb +8 -8
  22. data/app/views/devise/unlocks/new.html.erb +2 -2
  23. data/config/locales/en.yml +3 -2
  24. data/lib/devise/controllers/helpers.rb +10 -8
  25. data/lib/devise/controllers/rememberable.rb +2 -0
  26. data/lib/devise/controllers/responder.rb +35 -0
  27. data/lib/devise/controllers/scoped_views.rb +2 -0
  28. data/lib/devise/controllers/sign_in_out.rb +14 -4
  29. data/lib/devise/controllers/store_location.rb +24 -6
  30. data/lib/devise/controllers/url_helpers.rb +3 -1
  31. data/lib/devise/delegator.rb +2 -0
  32. data/lib/devise/encryptor.rb +2 -0
  33. data/lib/devise/failure_app.rb +33 -7
  34. data/lib/devise/hooks/activatable.rb +2 -0
  35. data/lib/devise/hooks/csrf_cleaner.rb +8 -1
  36. data/lib/devise/hooks/forgetable.rb +2 -0
  37. data/lib/devise/hooks/lockable.rb +4 -5
  38. data/lib/devise/hooks/proxy.rb +2 -0
  39. data/lib/devise/hooks/rememberable.rb +2 -0
  40. data/lib/devise/hooks/timeoutable.rb +4 -2
  41. data/lib/devise/hooks/trackable.rb +2 -0
  42. data/lib/devise/mailers/helpers.rb +2 -0
  43. data/lib/devise/mapping.rb +3 -1
  44. data/lib/devise/models/authenticatable.rb +55 -50
  45. data/lib/devise/models/confirmable.rb +36 -40
  46. data/lib/devise/models/database_authenticatable.rb +57 -36
  47. data/lib/devise/models/lockable.rb +18 -4
  48. data/lib/devise/models/omniauthable.rb +4 -2
  49. data/lib/devise/models/recoverable.rb +10 -19
  50. data/lib/devise/models/registerable.rb +4 -0
  51. data/lib/devise/models/rememberable.rb +5 -3
  52. data/lib/devise/models/timeoutable.rb +3 -1
  53. data/lib/devise/models/trackable.rb +15 -1
  54. data/lib/devise/models/validatable.rb +7 -10
  55. data/lib/devise/models.rb +3 -0
  56. data/lib/devise/modules.rb +2 -0
  57. data/lib/devise/omniauth/config.rb +2 -0
  58. data/lib/devise/omniauth/url_helpers.rb +2 -0
  59. data/lib/devise/omniauth.rb +4 -5
  60. data/lib/devise/orm/active_record.rb +2 -0
  61. data/lib/devise/orm/mongoid.rb +2 -0
  62. data/lib/devise/orm.rb +71 -0
  63. data/lib/devise/parameter_filter.rb +4 -0
  64. data/lib/devise/parameter_sanitizer.rb +15 -1
  65. data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
  66. data/lib/devise/rails/routes.rb +8 -6
  67. data/lib/devise/rails/warden_compat.rb +2 -0
  68. data/lib/devise/rails.rb +3 -5
  69. data/lib/devise/secret_key_finder.rb +27 -0
  70. data/lib/devise/strategies/authenticatable.rb +3 -1
  71. data/lib/devise/strategies/base.rb +2 -0
  72. data/lib/devise/strategies/database_authenticatable.rb +8 -1
  73. data/lib/devise/strategies/rememberable.rb +2 -0
  74. data/lib/devise/test/controller_helpers.rb +6 -1
  75. data/lib/devise/test/integration_helpers.rb +3 -1
  76. data/lib/devise/test_helpers.rb +2 -0
  77. data/lib/devise/time_inflector.rb +2 -0
  78. data/lib/devise/token_generator.rb +2 -0
  79. data/lib/devise/version.rb +3 -1
  80. data/lib/devise.rb +38 -12
  81. data/lib/generators/active_record/devise_generator.rb +40 -12
  82. data/lib/generators/active_record/templates/migration.rb +3 -1
  83. data/lib/generators/active_record/templates/migration_existing.rb +2 -0
  84. data/lib/generators/devise/controllers_generator.rb +3 -1
  85. data/lib/generators/devise/devise_generator.rb +5 -3
  86. data/lib/generators/devise/install_generator.rb +3 -5
  87. data/lib/generators/devise/orm_helpers.rb +9 -3
  88. data/lib/generators/devise/views_generator.rb +8 -9
  89. data/lib/generators/mongoid/devise_generator.rb +7 -5
  90. data/lib/generators/templates/README +9 -1
  91. data/lib/generators/templates/controllers/confirmations_controller.rb +2 -0
  92. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +3 -1
  93. data/lib/generators/templates/controllers/passwords_controller.rb +2 -0
  94. data/lib/generators/templates/controllers/registrations_controller.rb +2 -0
  95. data/lib/generators/templates/controllers/sessions_controller.rb +2 -0
  96. data/lib/generators/templates/controllers/unlocks_controller.rb +2 -0
  97. data/lib/generators/templates/devise.rb +43 -7
  98. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
  99. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
  100. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
  101. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +12 -4
  102. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
  103. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
  104. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
  105. metadata +24 -307
  106. data/.gitignore +0 -10
  107. data/.travis.yml +0 -58
  108. data/.yardopts +0 -9
  109. data/CODE_OF_CONDUCT.md +0 -22
  110. data/CONTRIBUTING.md +0 -79
  111. data/Gemfile +0 -40
  112. data/Gemfile.lock +0 -194
  113. data/Rakefile +0 -36
  114. data/bin/test +0 -13
  115. data/devise.gemspec +0 -26
  116. data/devise.png +0 -0
  117. data/gemfiles/Gemfile.rails-4.1-stable +0 -30
  118. data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
  119. data/gemfiles/Gemfile.rails-4.2-stable +0 -30
  120. data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
  121. data/gemfiles/Gemfile.rails-5.0-stable +0 -34
  122. data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -193
  123. data/guides/bug_report_templates/integration_test.rb +0 -104
  124. data/test/controllers/custom_registrations_controller_test.rb +0 -40
  125. data/test/controllers/custom_strategy_test.rb +0 -64
  126. data/test/controllers/helper_methods_test.rb +0 -22
  127. data/test/controllers/helpers_test.rb +0 -316
  128. data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -51
  129. data/test/controllers/internal_helpers_test.rb +0 -127
  130. data/test/controllers/load_hooks_controller_test.rb +0 -19
  131. data/test/controllers/passwords_controller_test.rb +0 -32
  132. data/test/controllers/sessions_controller_test.rb +0 -106
  133. data/test/controllers/url_helpers_test.rb +0 -65
  134. data/test/delegator_test.rb +0 -19
  135. data/test/devise_test.rb +0 -107
  136. data/test/failure_app_test.rb +0 -338
  137. data/test/generators/active_record_generator_test.rb +0 -83
  138. data/test/generators/controllers_generator_test.rb +0 -48
  139. data/test/generators/devise_generator_test.rb +0 -39
  140. data/test/generators/install_generator_test.rb +0 -24
  141. data/test/generators/mongoid_generator_test.rb +0 -23
  142. data/test/generators/views_generator_test.rb +0 -103
  143. data/test/helpers/devise_helper_test.rb +0 -49
  144. data/test/integration/authenticatable_test.rb +0 -698
  145. data/test/integration/confirmable_test.rb +0 -324
  146. data/test/integration/database_authenticatable_test.rb +0 -95
  147. data/test/integration/http_authenticatable_test.rb +0 -106
  148. data/test/integration/lockable_test.rb +0 -240
  149. data/test/integration/mounted_engine_test.rb +0 -36
  150. data/test/integration/omniauthable_test.rb +0 -135
  151. data/test/integration/recoverable_test.rb +0 -347
  152. data/test/integration/registerable_test.rb +0 -363
  153. data/test/integration/rememberable_test.rb +0 -217
  154. data/test/integration/timeoutable_test.rb +0 -184
  155. data/test/integration/trackable_test.rb +0 -92
  156. data/test/mailers/confirmation_instructions_test.rb +0 -115
  157. data/test/mailers/email_changed_test.rb +0 -130
  158. data/test/mailers/mailer_test.rb +0 -18
  159. data/test/mailers/reset_password_instructions_test.rb +0 -96
  160. data/test/mailers/unlock_instructions_test.rb +0 -91
  161. data/test/mapping_test.rb +0 -134
  162. data/test/models/authenticatable_test.rb +0 -23
  163. data/test/models/confirmable_test.rb +0 -536
  164. data/test/models/database_authenticatable_test.rb +0 -281
  165. data/test/models/lockable_test.rb +0 -350
  166. data/test/models/omniauthable_test.rb +0 -7
  167. data/test/models/recoverable_test.rb +0 -261
  168. data/test/models/registerable_test.rb +0 -7
  169. data/test/models/rememberable_test.rb +0 -182
  170. data/test/models/serializable_test.rb +0 -54
  171. data/test/models/timeoutable_test.rb +0 -51
  172. data/test/models/trackable_test.rb +0 -41
  173. data/test/models/validatable_test.rb +0 -119
  174. data/test/models_test.rb +0 -153
  175. data/test/omniauth/config_test.rb +0 -59
  176. data/test/omniauth/url_helpers_test.rb +0 -51
  177. data/test/orm/active_record.rb +0 -17
  178. data/test/orm/mongoid.rb +0 -13
  179. data/test/parameter_sanitizer_test.rb +0 -75
  180. data/test/rails_app/Rakefile +0 -6
  181. data/test/rails_app/app/active_record/admin.rb +0 -6
  182. data/test/rails_app/app/active_record/shim.rb +0 -2
  183. data/test/rails_app/app/active_record/user.rb +0 -7
  184. data/test/rails_app/app/active_record/user_on_engine.rb +0 -7
  185. data/test/rails_app/app/active_record/user_on_main_app.rb +0 -7
  186. data/test/rails_app/app/active_record/user_without_email.rb +0 -8
  187. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
  188. data/test/rails_app/app/controllers/admins_controller.rb +0 -6
  189. data/test/rails_app/app/controllers/application_controller.rb +0 -11
  190. data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -30
  191. data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -31
  192. data/test/rails_app/app/controllers/home_controller.rb +0 -29
  193. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
  194. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
  195. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
  196. data/test/rails_app/app/controllers/users_controller.rb +0 -31
  197. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  198. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -3
  199. data/test/rails_app/app/mailers/users/mailer.rb +0 -3
  200. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -4
  201. data/test/rails_app/app/mongoid/admin.rb +0 -29
  202. data/test/rails_app/app/mongoid/shim.rb +0 -23
  203. data/test/rails_app/app/mongoid/user.rb +0 -39
  204. data/test/rails_app/app/mongoid/user_on_engine.rb +0 -39
  205. data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -39
  206. data/test/rails_app/app/mongoid/user_without_email.rb +0 -33
  207. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  208. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  209. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  210. data/test/rails_app/app/views/home/index.html.erb +0 -1
  211. data/test/rails_app/app/views/home/join.html.erb +0 -1
  212. data/test/rails_app/app/views/home/private.html.erb +0 -1
  213. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  214. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  215. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  216. data/test/rails_app/app/views/users/index.html.erb +0 -1
  217. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  218. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  219. data/test/rails_app/bin/bundle +0 -3
  220. data/test/rails_app/bin/rails +0 -4
  221. data/test/rails_app/bin/rake +0 -4
  222. data/test/rails_app/config/application.rb +0 -44
  223. data/test/rails_app/config/boot.rb +0 -20
  224. data/test/rails_app/config/database.yml +0 -18
  225. data/test/rails_app/config/environment.rb +0 -5
  226. data/test/rails_app/config/environments/development.rb +0 -30
  227. data/test/rails_app/config/environments/production.rb +0 -86
  228. data/test/rails_app/config/environments/test.rb +0 -45
  229. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  230. data/test/rails_app/config/initializers/devise.rb +0 -180
  231. data/test/rails_app/config/initializers/inflections.rb +0 -2
  232. data/test/rails_app/config/initializers/secret_token.rb +0 -3
  233. data/test/rails_app/config/initializers/session_store.rb +0 -1
  234. data/test/rails_app/config/routes.rb +0 -126
  235. data/test/rails_app/config.ru +0 -4
  236. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -75
  237. data/test/rails_app/db/schema.rb +0 -55
  238. data/test/rails_app/lib/shared_admin.rb +0 -21
  239. data/test/rails_app/lib/shared_user.rb +0 -30
  240. data/test/rails_app/lib/shared_user_without_email.rb +0 -26
  241. data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -13
  242. data/test/rails_app/public/404.html +0 -26
  243. data/test/rails_app/public/422.html +0 -26
  244. data/test/rails_app/public/500.html +0 -26
  245. data/test/rails_app/public/favicon.ico +0 -0
  246. data/test/rails_test.rb +0 -9
  247. data/test/routes_test.rb +0 -279
  248. data/test/support/action_controller/record_identifier.rb +0 -10
  249. data/test/support/assertions.rb +0 -28
  250. data/test/support/helpers.rb +0 -77
  251. data/test/support/http_method_compatibility.rb +0 -51
  252. data/test/support/integration.rb +0 -92
  253. data/test/support/locale/en.yml +0 -8
  254. data/test/support/mongoid.yml +0 -6
  255. data/test/support/webrat/integrations/rails.rb +0 -33
  256. data/test/test/controller_helpers_test.rb +0 -186
  257. data/test/test/integration_helpers_test.rb +0 -32
  258. data/test/test_helper.rb +0 -34
  259. data/test/test_models.rb +0 -33
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/object/try"
2
4
  require "active_support/core_ext/hash/slice"
3
5
 
@@ -133,10 +135,10 @@ module ActionDispatch::Routing
133
135
  # * failure_app: a rack app which is invoked whenever there is a failure. Strings representing a given
134
136
  # are also allowed as parameter.
135
137
  #
136
- # * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :get),
138
+ # * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :delete),
137
139
  # if you wish to restrict this to accept only :post or :delete requests you should do:
138
140
  #
139
- # devise_for :users, sign_out_via: [:post, :delete]
141
+ # devise_for :users, sign_out_via: [:get, :post]
140
142
  #
141
143
  # You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
142
144
  #
@@ -285,7 +287,7 @@ module ActionDispatch::Routing
285
287
  # root to: "admin/dashboard#show", as: :user_root
286
288
  # end
287
289
  #
288
- def authenticate(scope=nil, block=nil)
290
+ def authenticate(scope = nil, block = nil)
289
291
  constraints_for(:authenticate!, scope, block) do
290
292
  yield
291
293
  end
@@ -309,7 +311,7 @@ module ActionDispatch::Routing
309
311
  #
310
312
  # root to: 'landing#show'
311
313
  #
312
- def authenticated(scope=nil, block=nil)
314
+ def authenticated(scope = nil, block = nil)
313
315
  constraints_for(:authenticate?, scope, block) do
314
316
  yield
315
317
  end
@@ -326,7 +328,7 @@ module ActionDispatch::Routing
326
328
  #
327
329
  # root to: 'dashboard#show'
328
330
  #
329
- def unauthenticated(scope=nil)
331
+ def unauthenticated(scope = nil)
330
332
  constraint = lambda do |request|
331
333
  not request.env["warden"].authenticate? scope: scope
332
334
  end
@@ -472,7 +474,7 @@ ERROR
472
474
  @scope = current_scope
473
475
  end
474
476
 
475
- def constraints_for(method_to_apply, scope=nil, block=nil)
477
+ def constraints_for(method_to_apply, scope = nil, block = nil)
476
478
  constraint = lambda do |request|
477
479
  request.env['warden'].send(method_to_apply, scope: scope) &&
478
480
  (block.nil? || block.call(request.env["warden"].user(scope)))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Warden::Mixins::Common
2
4
  def request
3
5
  @request ||= ActionDispatch::Request.new(env)
data/lib/devise/rails.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'devise/rails/routes'
2
4
  require 'devise/rails/warden_compat'
3
5
 
@@ -32,11 +34,7 @@ module Devise
32
34
  end
33
35
 
34
36
  initializer "devise.secret_key" do |app|
35
- if app.respond_to?(:secrets)
36
- Devise.secret_key ||= app.secrets.secret_key_base
37
- elsif app.config.respond_to?(:secret_key_base)
38
- Devise.secret_key ||= app.config.secret_key_base
39
- end
37
+ Devise.secret_key ||= Devise::SecretKeyFinder.new(app).find
40
38
 
41
39
  Devise.token_generator ||=
42
40
  if secret_key = Devise.secret_key
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Devise
4
+ class SecretKeyFinder
5
+ def initialize(application)
6
+ @application = application
7
+ end
8
+
9
+ def find
10
+ if @application.respond_to?(:credentials) && key_exists?(@application.credentials)
11
+ @application.credentials.secret_key_base
12
+ elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
13
+ @application.secrets.secret_key_base
14
+ elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
15
+ @application.config.secret_key_base
16
+ elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
17
+ @application.secret_key_base
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def key_exists?(object)
24
+ object.secret_key_base.present?
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'devise/strategies/base'
2
4
 
3
5
  module Devise
@@ -26,7 +28,7 @@ module Devise
26
28
  private
27
29
 
28
30
  # Receives a resource and check if it is valid by calling valid_for_authentication?
29
- # An optional block that will be triggered while validating can be optionally
31
+ # A block that will be triggered while validating can be optionally
30
32
  # given as parameter. Check Devise::Models::Authenticatable.valid_for_authentication?
31
33
  # for more information.
32
34
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
4
  module Strategies
3
5
  # Base strategy for Devise. Responsible for verifying correct scope and mapping.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'devise/strategies/authenticatable'
2
4
 
3
5
  module Devise
@@ -14,8 +16,13 @@ module Devise
14
16
  success!(resource)
15
17
  end
16
18
 
19
+ # In paranoid mode, hash the password even when a resource doesn't exist for the given authentication key.
20
+ # This is necessary to prevent enumeration attacks - e.g. the request is faster when a resource doesn't
21
+ # exist in the database if the password hashing algorithm is not called.
17
22
  mapping.to.new.password = password if !hashed && Devise.paranoid
18
- fail(:not_found_in_database) unless resource
23
+ unless resource
24
+ Devise.paranoid ? fail(:invalid) : fail(:not_found_in_database)
25
+ end
19
26
  end
20
27
  end
21
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'devise/strategies/authenticatable'
2
4
 
3
5
  module Devise
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
4
  module Test
3
5
  # `Devise::Test::ControllerHelpers` provides a facility to test controllers
@@ -35,6 +37,8 @@ module Devise
35
37
  @response
36
38
  end
37
39
 
40
+ ruby2_keywords(:process) if respond_to?(:ruby2_keywords, true)
41
+
38
42
  # We need to set up the environment variables and the response in the controller.
39
43
  def setup_controller_for_warden #:nodoc:
40
44
  @request.env['action_controller.instance'] = @controller
@@ -137,8 +141,9 @@ module Devise
137
141
 
138
142
  status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
139
143
  @controller.response.headers.merge!(headers)
144
+ @controller.response.content_type = headers["Content-Type"] unless Rails::VERSION::MAJOR >= 5
140
145
  @controller.status = status
141
- @controller.response.body = response.body
146
+ @controller.response_body = response.body
142
147
  nil # causes process return @response
143
148
  end
144
149
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
4
  # Devise::Test::IntegrationHelpers is a helper module for facilitating
3
5
  # authentication on Rails integration tests to bypass the required steps for
@@ -26,7 +28,7 @@ module Devise
26
28
  end
27
29
  end
28
30
 
29
- # Signs in a specific resource, mimicking a successfull sign in
31
+ # Signs in a specific resource, mimicking a successful sign in
30
32
  # operation through +Devise::SessionsController#create+.
31
33
  #
32
34
  # * +resource+ - The resource that should be authenticated
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
4
  module TestHelpers
3
5
  def self.included(base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/module/delegation"
2
4
 
3
5
  module Devise
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
 
3
5
  module Devise
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
- VERSION = "4.3.0".freeze
4
+ VERSION = "4.9.2".freeze
3
5
  end
data/lib/devise.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails'
2
4
  require 'active_support/core_ext/numeric/time'
3
5
  require 'active_support/dependencies'
@@ -11,15 +13,18 @@ module Devise
11
13
  autoload :Encryptor, 'devise/encryptor'
12
14
  autoload :FailureApp, 'devise/failure_app'
13
15
  autoload :OmniAuth, 'devise/omniauth'
16
+ autoload :Orm, 'devise/orm'
14
17
  autoload :ParameterFilter, 'devise/parameter_filter'
15
18
  autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
16
19
  autoload :TestHelpers, 'devise/test_helpers'
17
20
  autoload :TimeInflector, 'devise/time_inflector'
18
21
  autoload :TokenGenerator, 'devise/token_generator'
22
+ autoload :SecretKeyFinder, 'devise/secret_key_finder'
19
23
 
20
24
  module Controllers
21
25
  autoload :Helpers, 'devise/controllers/helpers'
22
26
  autoload :Rememberable, 'devise/controllers/rememberable'
27
+ autoload :Responder, 'devise/controllers/responder'
23
28
  autoload :ScopedViews, 'devise/controllers/scoped_views'
24
29
  autoload :SignInOut, 'devise/controllers/sign_in_out'
25
30
  autoload :StoreLocation, 'devise/controllers/store_location'
@@ -68,7 +73,7 @@ module Devise
68
73
 
69
74
  # The number of times to hash the password.
70
75
  mattr_accessor :stretches
71
- @@stretches = 11
76
+ @@stretches = 12
72
77
 
73
78
  # The default key used when authenticating over http auth.
74
79
  mattr_accessor :http_authentication_key
@@ -149,7 +154,7 @@ module Devise
149
154
  mattr_accessor :timeout_in
150
155
  @@timeout_in = 30.minutes
151
156
 
152
- # Used to hash the password. Please generate one with rake secret.
157
+ # Used to hash the password. Please generate one with rails secret.
153
158
  mattr_accessor :pepper
154
159
  @@pepper = nil
155
160
 
@@ -214,7 +219,16 @@ module Devise
214
219
 
215
220
  # Which formats should be treated as navigational.
216
221
  mattr_accessor :navigational_formats
217
- @@navigational_formats = ["*/*", :html]
222
+ @@navigational_formats = ["*/*", :html, :turbo_stream]
223
+
224
+ # The default responder used by Devise, used to customize status codes with:
225
+ #
226
+ # `config.responder.error_status`
227
+ # `config.responder.redirect_status`
228
+ #
229
+ # Can be replaced by a custom application responder.
230
+ mattr_accessor :responder
231
+ @@responder = Devise::Controllers::Responder
218
232
 
219
233
  # When set to true, signing out a user signs out all other scopes.
220
234
  mattr_accessor :sign_out_all_scopes
@@ -290,13 +304,9 @@ module Devise
290
304
  mattr_accessor :token_generator
291
305
  @@token_generator = nil
292
306
 
293
- def self.rails51? # :nodoc:
294
- Rails.gem_version >= Gem::Version.new("5.1.x")
295
- end
296
-
297
- def self.activerecord51? # :nodoc:
298
- defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
299
- end
307
+ # When set to false, changing a password does not automatically sign in a user
308
+ mattr_accessor :sign_in_after_change_password
309
+ @@sign_in_after_change_password = true
300
310
 
301
311
  # Default way to set up Devise. Run rails generate devise_install to create
302
312
  # a fresh initializer with all configuration values.
@@ -310,12 +320,20 @@ module Devise
310
320
  end
311
321
 
312
322
  def get
313
- ActiveSupport::Dependencies.constantize(@name)
323
+ # TODO: Remove AS::Dependencies usage when dropping support to Rails < 7.
324
+ if ActiveSupport::Dependencies.respond_to?(:constantize)
325
+ ActiveSupport::Dependencies.constantize(@name)
326
+ else
327
+ @name.constantize
328
+ end
314
329
  end
315
330
  end
316
331
 
317
332
  def self.ref(arg)
318
- ActiveSupport::Dependencies.reference(arg)
333
+ # TODO: Remove AS::Dependencies usage when dropping support to Rails < 7.
334
+ if ActiveSupport::Dependencies.respond_to?(:reference)
335
+ ActiveSupport::Dependencies.reference(arg)
336
+ end
319
337
  Getter.new(arg)
320
338
  end
321
339
 
@@ -502,6 +520,14 @@ module Devise
502
520
  b.each_byte { |byte| res |= byte ^ l.shift }
503
521
  res == 0
504
522
  end
523
+
524
+ def self.activerecord51? # :nodoc:
525
+ ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
526
+ [Devise] `Devise.activerecord51?` is deprecated and will be removed in the next major version.
527
+ It is a non-public method that's no longer used internally, but that other libraries have been relying on.
528
+ DEPRECATION
529
+ defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
530
+ end
505
531
  end
506
532
 
507
533
  require 'warden'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/active_record'
2
4
  require 'generators/devise/orm_helpers'
3
5
 
@@ -6,14 +8,16 @@ module ActiveRecord
6
8
  class DeviseGenerator < ActiveRecord::Generators::Base
7
9
  argument :attributes, type: :array, default: [], banner: "field:type field:type"
8
10
 
11
+ class_option :primary_key_type, type: :string, desc: "The type for primary key"
12
+
9
13
  include Devise::Generators::OrmHelpers
10
14
  source_root File.expand_path("../templates", __FILE__)
11
15
 
12
16
  def copy_devise_migration
13
17
  if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
14
- migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb", migration_version: migration_version
18
+ migration_template "migration_existing.rb", "#{migration_path}/add_devise_to_#{table_name}.rb", migration_version: migration_version
15
19
  else
16
- migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb", migration_version: migration_version
20
+ migration_template "migration.rb", "#{migration_path}/devise_create_#{table_name}.rb", migration_version: migration_version
17
21
  end
18
22
  end
19
23
 
@@ -50,11 +54,11 @@ module ActiveRecord
50
54
  t.datetime :remember_created_at
51
55
 
52
56
  ## Trackable
53
- t.integer :sign_in_count, default: 0, null: false
54
- t.datetime :current_sign_in_at
55
- t.datetime :last_sign_in_at
56
- t.#{ip_column} :current_sign_in_ip
57
- t.#{ip_column} :last_sign_in_ip
57
+ # t.integer :sign_in_count, default: 0, null: false
58
+ # t.datetime :current_sign_in_at
59
+ # t.datetime :last_sign_in_at
60
+ # t.#{ip_column} :current_sign_in_ip
61
+ # t.#{ip_column} :last_sign_in_ip
58
62
 
59
63
  ## Confirmable
60
64
  # t.string :confirmation_token
@@ -78,20 +82,44 @@ RUBY
78
82
  postgresql?
79
83
  end
80
84
 
81
- def rails5?
82
- Rails.version.start_with? '5'
85
+ def rails5_and_up?
86
+ Rails::VERSION::MAJOR >= 5
87
+ end
88
+
89
+ def rails61_and_up?
90
+ Rails::VERSION::MAJOR > 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1)
83
91
  end
84
92
 
85
93
  def postgresql?
86
- config = ActiveRecord::Base.configurations[Rails.env]
87
- config && config['adapter'] == 'postgresql'
94
+ ar_config && ar_config['adapter'] == 'postgresql'
95
+ end
96
+
97
+ def ar_config
98
+ if ActiveRecord::Base.configurations.respond_to?(:configs_for)
99
+ if rails61_and_up?
100
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: "primary").configuration_hash
101
+ else
102
+ ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: "primary").config
103
+ end
104
+ else
105
+ ActiveRecord::Base.configurations[Rails.env]
106
+ end
88
107
  end
89
108
 
90
109
  def migration_version
91
- if rails5?
110
+ if rails5_and_up?
92
111
  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
93
112
  end
94
113
  end
114
+
115
+ def primary_key_type
116
+ primary_key_string if rails5_and_up?
117
+ end
118
+
119
+ def primary_key_string
120
+ key_string = options[:primary_key_type]
121
+ ", id: :#{key_string}" if key_string
122
+ end
95
123
  end
96
124
  end
97
125
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
2
4
  def change
3
- create_table :<%= table_name %> do |t|
5
+ create_table :<%= table_name %><%= primary_key_type %> do |t|
4
6
  <%= migration_data -%>
5
7
 
6
8
  <% attributes.each do |attribute| -%>
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
2
4
  def self.up
3
5
  change_table :<%= table_name %> do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/base'
2
4
 
3
5
  module Devise
@@ -16,7 +18,7 @@ module Devise
16
18
 
17
19
  This will create a controller class at app/controllers/users/sessions_controller.rb like this:
18
20
 
19
- class Users::ConfirmationsController < Devise::ConfirmationsController
21
+ class Users::SessionsController < Devise::SessionsController
20
22
  content...
21
23
  end
22
24
  DESC
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/named_base'
2
4
 
3
5
  module Devise
@@ -8,15 +10,15 @@ module Devise
8
10
  namespace "devise"
9
11
  source_root File.expand_path("../templates", __FILE__)
10
12
 
11
- desc "Generates a model with the given NAME (if one does not exist) with devise " <<
13
+ desc "Generates a model with the given NAME (if one does not exist) with devise " \
12
14
  "configuration plus a migration file and devise routes."
13
15
 
14
- hook_for :orm
16
+ hook_for :orm, required: true
15
17
 
16
18
  class_option :routes, desc: "Generate routes", type: :boolean, default: true
17
19
 
18
20
  def add_devise_routes
19
- devise_route = "devise_for :#{plural_name}"
21
+ devise_route = "devise_for :#{plural_name}".dup
20
22
  devise_route << %Q(, class_name: "#{class_name}") if class_name.include?("::")
21
23
  devise_route << %Q(, skip: :all) unless options.routes?
22
24
  route devise_route
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/base'
2
4
  require 'securerandom'
3
5
 
@@ -9,7 +11,7 @@ module Devise
9
11
  source_root File.expand_path("../../templates", __FILE__)
10
12
 
11
13
  desc "Creates a Devise initializer and copy locale files to your application."
12
- class_option :orm
14
+ class_option :orm, required: true
13
15
 
14
16
  def copy_initializer
15
17
  unless options[:orm]
@@ -35,10 +37,6 @@ module Devise
35
37
  def show_readme
36
38
  readme "README" if behavior == :invoke
37
39
  end
38
-
39
- def rails_4?
40
- Rails::VERSION::MAJOR == 4
41
- end
42
40
  end
43
41
  end
44
42
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Devise
2
4
  module Generators
3
5
  module OrmHelpers
4
6
  def model_contents
5
7
  buffer = <<-CONTENT
6
8
  # Include default devise modules. Others available are:
7
- # :confirmable, :lockable, :timeoutable and :omniauthable
9
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
8
10
  devise :database_authenticatable, :registerable,
9
- :recoverable, :rememberable, :trackable, :validatable
11
+ :recoverable, :rememberable, :validatable
10
12
 
11
13
  CONTENT
12
14
  buffer
@@ -23,7 +25,11 @@ CONTENT
23
25
  end
24
26
 
25
27
  def migration_path
26
- @migration_path ||= File.join("db", "migrate")
28
+ if Rails.version >= '5.0.3'
29
+ db_migrate_path
30
+ else
31
+ @migration_path ||= File.join("db", "migrate")
32
+ end
27
33
  end
28
34
 
29
35
  def model_path
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/base'
2
4
 
3
5
  module Devise
@@ -21,13 +23,6 @@ module Devise
21
23
  public_task :copy_views
22
24
  end
23
25
 
24
- # TODO: Add this to Rails itself
25
- module ClassMethods
26
- def hide!
27
- Rails::Generators.hide_namespace self.namespace
28
- end
29
- end
30
-
31
26
  def copy_views
32
27
  if options[:views]
33
28
  options[:views].each do |directory|
@@ -47,7 +42,7 @@ module Devise
47
42
  def view_directory(name, _target_path = nil)
48
43
  directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
49
44
  if scope
50
- content.gsub "devise/shared/links", "#{plural_scope}/shared/links"
45
+ content.gsub("devise/shared", "#{plural_scope}/shared")
51
46
  else
52
47
  content
53
48
  end
@@ -139,7 +134,11 @@ module Devise
139
134
  default: defined?(SimpleForm) ? "simple_form_for" : "form_for"
140
135
 
141
136
  hook_for :markerb, desc: "Generate markerb instead of erb mail views",
142
- default: defined?(Markerb) ? :markerb : :erb,
137
+ default: defined?(Markerb),
138
+ type: :boolean
139
+
140
+ hook_for :erb, desc: "Generate erb mail views",
141
+ default: !defined?(Markerb),
143
142
  type: :boolean
144
143
  end
145
144
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators/named_base'
2
4
  require 'generators/devise/orm_helpers'
3
5
 
@@ -32,11 +34,11 @@ module Mongoid
32
34
  field :remember_created_at, type: Time
33
35
 
34
36
  ## Trackable
35
- field :sign_in_count, type: Integer, default: 0
36
- field :current_sign_in_at, type: Time
37
- field :last_sign_in_at, type: Time
38
- field :current_sign_in_ip, type: String
39
- field :last_sign_in_ip, type: String
37
+ # field :sign_in_count, type: Integer, default: 0
38
+ # field :current_sign_in_at, type: Time
39
+ # field :last_sign_in_at, type: Time
40
+ # field :current_sign_in_ip, type: String
41
+ # field :last_sign_in_ip, type: String
40
42
 
41
43
  ## Confirmable
42
44
  # field :confirmation_token, type: String
@@ -1,6 +1,6 @@
1
1
  ===============================================================================
2
2
 
3
- Some setup you must do manually if you haven't yet:
3
+ Depending on your application's configuration some manual setup may be required:
4
4
 
5
5
  1. Ensure you have defined default url options in your environments files. Here
6
6
  is an example of default_url_options appropriate for a development environment
@@ -10,10 +10,14 @@ Some setup you must do manually if you haven't yet:
10
10
 
11
11
  In production, :host should be set to the actual host of your application.
12
12
 
13
+ * Required for all applications. *
14
+
13
15
  2. Ensure you have defined root_url to *something* in your config/routes.rb.
14
16
  For example:
15
17
 
16
18
  root to: "home#index"
19
+
20
+ * Not required for API-only Applications *
17
21
 
18
22
  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
19
23
  For example:
@@ -21,8 +25,12 @@ Some setup you must do manually if you haven't yet:
21
25
  <p class="notice"><%= notice %></p>
22
26
  <p class="alert"><%= alert %></p>
23
27
 
28
+ * Not required for API-only Applications *
29
+
24
30
  4. You can copy Devise views (for customization) to your app by running:
25
31
 
26
32
  rails g devise:views
33
+
34
+ * Not required *
27
35
 
28
36
  ===============================================================================
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class <%= @scope_prefix %>ConfirmationsController < Devise::ConfirmationsController
2
4
  # GET /resource/confirmation/new
3
5
  # def new