devise 4.6.0 → 4.9.4

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 (58) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +122 -3
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +108 -61
  5. data/app/controllers/devise/confirmations_controller.rb +1 -0
  6. data/app/controllers/devise/passwords_controller.rb +2 -2
  7. data/app/controllers/devise/registrations_controller.rb +1 -1
  8. data/app/controllers/devise/sessions_controller.rb +2 -2
  9. data/app/controllers/devise/unlocks_controller.rb +1 -0
  10. data/app/controllers/devise_controller.rb +16 -2
  11. data/app/helpers/devise_helper.rb +19 -7
  12. data/app/mailers/devise/mailer.rb +5 -5
  13. data/app/views/devise/passwords/edit.html.erb +1 -1
  14. data/app/views/devise/registrations/edit.html.erb +1 -1
  15. data/app/views/devise/shared/_error_messages.html.erb +1 -1
  16. data/app/views/devise/shared/_links.html.erb +1 -1
  17. data/config/locales/en.yml +3 -3
  18. data/lib/devise/controllers/helpers.rb +9 -7
  19. data/lib/devise/controllers/responder.rb +35 -0
  20. data/lib/devise/controllers/sign_in_out.rb +7 -5
  21. data/lib/devise/controllers/url_helpers.rb +1 -1
  22. data/lib/devise/failure_app.rb +22 -16
  23. data/lib/devise/hooks/csrf_cleaner.rb +6 -1
  24. data/lib/devise/hooks/lockable.rb +2 -5
  25. data/lib/devise/hooks/timeoutable.rb +2 -2
  26. data/lib/devise/mapping.rb +1 -1
  27. data/lib/devise/models/authenticatable.rb +13 -9
  28. data/lib/devise/models/confirmable.rb +30 -39
  29. data/lib/devise/models/database_authenticatable.rb +18 -34
  30. data/lib/devise/models/lockable.rb +11 -3
  31. data/lib/devise/models/omniauthable.rb +2 -2
  32. data/lib/devise/models/recoverable.rb +8 -19
  33. data/lib/devise/models/rememberable.rb +2 -2
  34. data/lib/devise/models/timeoutable.rb +1 -1
  35. data/lib/devise/models/trackable.rb +1 -1
  36. data/lib/devise/models/validatable.rb +4 -9
  37. data/lib/devise/models.rb +1 -0
  38. data/lib/devise/omniauth.rb +2 -5
  39. data/lib/devise/orm.rb +71 -0
  40. data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
  41. data/lib/devise/rails/routes.rb +6 -6
  42. data/lib/devise/rails.rb +4 -0
  43. data/lib/devise/strategies/authenticatable.rb +1 -1
  44. data/lib/devise/test/controller_helpers.rb +4 -2
  45. data/lib/devise/test/integration_helpers.rb +1 -1
  46. data/lib/devise/test_helpers.rb +1 -1
  47. data/lib/devise/version.rb +1 -1
  48. data/lib/devise.rb +35 -12
  49. data/lib/generators/active_record/devise_generator.rb +17 -2
  50. data/lib/generators/devise/devise_generator.rb +1 -1
  51. data/lib/generators/devise/install_generator.rb +1 -5
  52. data/lib/generators/devise/views_generator.rb +1 -1
  53. data/lib/generators/templates/README +9 -1
  54. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
  55. data/lib/generators/templates/devise.rb +25 -11
  56. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -1
  57. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
  58. metadata +21 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f89e0e322bb87fda7dfb21c558c38138065368ba
4
- data.tar.gz: 88f2a5d3e8aeddaf2dd1a9dc6f6a366cf4b3a3ef
2
+ SHA256:
3
+ metadata.gz: 5ee56c70aa194195a4ce7ee729124c9701fa62a1ca71a0b74fa1d45f7b452c8e
4
+ data.tar.gz: f6d6fbd0a844de35d7a27ebb52eadc8da5440436cd8b037e917be40e8379b670
5
5
  SHA512:
6
- metadata.gz: 40734474103c3aabd38dfae149a0f38d690d30ac2aa465510869616338a2968ab9f5a128f3263ca34009fb98b7bbb3b4bcd344119532bb56f459d23b3e6d326c
7
- data.tar.gz: 80a1ef0816372c91f91ad27389b1abbe21c80d76ade44f9afce5ef1221b21b195466b1fe74a8a78bc20e70772eeacda06f7b7d06a208355fbf0f858ad3de33e7
6
+ metadata.gz: d29b37afe41e4751cdbdc259c3cb7f0926bfde20949054e652677175dec119bfa49054b829103ce382ddb9655f2a51ba9f75576a2ce112bf9e179cf6f617e228
7
+ data.tar.gz: 5bd002f04b9296993f48af6e312fe94a5a0ea80cacaf3226ba78317a3a100fcdd3060c70b6592398fb8206dd98a12aa6ed906ffb29ed589b144fb1f59c923fc9
data/CHANGELOG.md CHANGED
@@ -1,4 +1,123 @@
1
- ### Unreleased
1
+ ### 4.9.4 - 2024-04-10
2
+
3
+ * enhancements
4
+ * Add support for Ruby 3.3. (no changes needed)
5
+
6
+ * bug fixes
7
+ * Respect locale set by controller in failure app. Devise will carry over the current I18n.locale option when triggering authentication, and will wrap the failure app call with it. [#5567](https://github.com/heartcombo/devise/pull/5567)
8
+
9
+ ### 4.9.3 - 2023-10-11
10
+
11
+ * enhancements
12
+ * Add support for Rails 7.1.
13
+ * Add `Devise.deprecator` to integrate with new application deprecators in Rails 7.1. (@soartec-lab, @etiennebarrie)
14
+
15
+ ### 4.9.2 - 2023-04-03
16
+
17
+ * deprecations
18
+ * Bring back `Devise.activerecord51?` and deprecate it, in order to avoid breakage with some libraries that apparently relied on it.
19
+
20
+ ### 4.9.1 - 2023-03-31
21
+
22
+ * enhancements
23
+ * Allow resource class scopes to override the global configuration for `sign_in_after_reset_password` behaviour. [#5429](https://github.com/heartcombo/devise/pull/5429) [@mattr](https://github.com/mattr)
24
+ * Refactor conditional dirty tracking logic to a centralized module to simplify usage throughout the codebase. [#5575](https://github.com/heartcombo/devise/pull/5575)
25
+ * Improve support for Devise in apps with Active Record and Mongoid ORMs loaded, so it does not incorrectly uses new Active Record dirty tracking APIs with a Mongoid Devise model. [#5576](https://github.com/heartcombo/devise/pull/5576)
26
+
27
+ * bug fixes
28
+ * Failure app will respond with configured `redirect_status` instead of `error_status` if the recall app returns a redirect status (300..399) [#5573](https://github.com/heartcombo/devise/pull/5573)
29
+ * Fix frozen string exception in validatable. [#5563](https://github.com/heartcombo/devise/pull/5563) [#5465](https://github.com/heartcombo/devise/pull/5465) [@mameier](https://github.com/mameier)
30
+
31
+ ### 4.9.0 - 2023-02-17
32
+
33
+ * enhancements
34
+ * Add support for Ruby 3.1/3.2.
35
+ * Add support for Hotwire + Turbo, default in Rails 7+.
36
+ * Devise uses the latest `responders` version (v3.1.0 or higher), which allows configuring the status used for validation error responses (`error_status`) and for redirects after POST/PUT/PATCH/DELETE requests (`redirect_status`). For backwards compatibility, Devise keeps `error_status` as `:ok` which returns a `200 OK` response, and `redirect_status` to `:found` which returns a `302 Found` response, but you can configure it to return `422 Unprocessable Entity` and `303 See Other` respectively, to match the behavior expected by Hotwire/Turbo:
37
+
38
+ ```ruby
39
+ # config/initializers/devise.rb
40
+ Devise.setup do |config|
41
+ # ...
42
+ config.responder.error_status = :unprocessable_entity
43
+ config.responder.redirect_status = :see_other
44
+ # ...
45
+ end
46
+ ```
47
+
48
+ These configs are already generated by default with new apps, and existing apps may opt-in as described above. Trying to set these with an older version of `responders` will issue a warning and have no effect, so please upgrade the `responders` version if you're upgrading Devise for this integration. Note that these defaults may change in future versions of Devise, to better match the Rails + Hotwire/Turbo defaults across the board.
49
+ * If you have a custom responder set on your application and expect it to affect Devise as well, you may need to override the Devise responder entirely with `config.responder = MyApplicationResponder`, so that it uses your custom one. The main reason Devise uses a custom responder is to be able to configure the statuses as described above, but you can also change that config on your own responder if you want. Check the `responders` readme for more info on that.
50
+ * If you have created a custom responder and/or failure app just to customize responses for better Hotwire/Turbo integration, they should no longer be necessary.
51
+ * `:turbo_stream` is now treated as a navigational format, so it works like HTML navigation when using Turbo. Note: if you relied on `:turbo_stream` to be treated as a non-navigational format before, you can reconfigure your `navigational_formats` in the Devise initializer file to exclude it.
52
+ * OmniAuth "Sign in with" links were changed to buttons that generate HTML forms with method=POST, instead of using link + method=POST that required rails-ujs to work. Since rails-ujs is no longer the default for new Rails apps, this allows the OmniAuth buttons to work in any scenario, with or without rails-ujs and/or Turbo. This only affects apps that are using the default `devise/shared/_links.html.erb` partial from Devise with OmniAuth enabled.
53
+ * The "Cancel my account" button was changed to include the `data-turbo-confirm` option, so that it works with both rails-ujs and Turbo by default.
54
+ * Devise does not provide "sign out" links/buttons in its shared views, but if you're using `sign_out_via` with `:delete` (the default), and are using links with `method: :delete`, those need to be updated with `data: { turbo_method: :delete }` instead for Turbo.
55
+ * Check [this upgrade guide](https://github.com/heartcombo/devise/wiki/How-To:-Upgrade-to-Devise-4.9.0-[Hotwire-Turbo-integration]) for more detailed information.
56
+
57
+ ### 4.8.1 - 2021-12-16
58
+
59
+ * enhancements
60
+ * Add support for Rails 7.0. Please note that Turbo integration is not fully supported by Devise yet.
61
+
62
+ ### 4.8.0 - 2021-04-29
63
+
64
+ * enhancements
65
+ * Devise now enables the upgrade of OmniAuth 2+. Previously Devise would raise an error if you'd try to upgrade. Please note that OmniAuth 2 is considered a security upgrade and recommended to everyone. You can read more about the details (and possible necessary changes to your app as part of the upgrade) in [their release notes](https://github.com/omniauth/omniauth/releases/tag/v2.0.0). [Devise's OmniAuth Overview wiki](https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview) was also updated to cover OmniAuth 2.0 requirements.
66
+ - Note that the upgrade required Devise shared links that initiate the OmniAuth flow to be changed to `method: :post`, which is now a requirement for OmniAuth, part of the security improvement. If you have copied and customized the Devise shared links partial to your app, or if you have other links in your app that initiate the OmniAuth flow, they will have to be updated to use `method: :post`, or changed to use buttons (e.g. `button_to`) to work with OmniAuth 2. (if you're using links with `method: :post`, make sure your app has `rails-ujs` or `jquery-ujs` included in order for these links to work properly.)
67
+ - As part of the OmniAuth 2.0 upgrade you might also need to add the [`omniauth-rails_csrf_protection`](https://github.com/cookpad/omniauth-rails_csrf_protection) gem to your app if you don't have it already. (and you don't want to roll your own code to verify requests.) Check the OmniAuth v2 release notes for more info.
68
+ * Introduce `Lockable#reset_failed_attempts!` model method to reset failed attempts counter to 0 after the user signs in.
69
+ - This logic existed inside the lockable warden hook and is triggered automatically after the user signs in. The new model method is an extraction to allow you to override it in the application to implement things like switching to a write database if you're using the new multi-DB infrastructure from Rails for example, similar to how it's already possible with `Trackable#update_tracked_fields!`.
70
+ * Add support for Ruby 3.
71
+ * Add support for Rails 6.1.
72
+ * Move CI to GitHub Actions.
73
+
74
+ * deprecations
75
+ * `Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION` is deprecated in favor of `Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION` (@hanachin)
76
+
77
+ ### 4.7.3 - 2020-09-20
78
+
79
+ * bug fixes
80
+ * Do not modify `:except` option given to `#serializable_hash`. (by @dpep)
81
+ * Fix thor deprecation when running the devise generator. (by @deivid-rodriguez)
82
+ * Fix hanging tests for streaming controllers using Devise. (by @afn)
83
+
84
+ ### 4.7.2 - 2020-06-10
85
+
86
+ * enhancements
87
+ * Increase default stretches to 12 (by @sergey-alekseev)
88
+ * Ruby 2.7 support (kwarg warnings removed)
89
+
90
+ * bug fixes
91
+ * Generate scoped views with proper scoped errors partial (by @shobhitic)
92
+ * Allow to set scoped `already_authenticated` error messages (by @gurgelrenan)
93
+
94
+ ### 4.7.1 - 2019-09-06
95
+
96
+ * bug fixes
97
+ * Fix an edge case where records with a blank `confirmation_token` could be confirmed (by @tegon)
98
+ * Fix typo inside `update_needs_confirmation` i18n key (by @lslm)
99
+
100
+ ### 4.7.0 - 2019-08-19
101
+
102
+ * enhancements
103
+ * Support Rails 6.0
104
+ * Update CI to rails 6.0.0.beta3 (by @tunnes)
105
+ * refactor method name to be more consistent (by @saiqulhaq)
106
+ * Fix rails 6.0.rc1 email uniqueness validation deprecation warning (by @Vasfed)
107
+
108
+ * bug fixes
109
+ * Add `autocomplete="new-password"` to `password_confirmation` fields (by @ferrl)
110
+ * Fix rails_51_and_up? method for Rails 6.rc1 (by @igorkasyanchuk)
111
+
112
+ ### 4.6.2 - 2019-03-26
113
+
114
+ * bug fixes
115
+ * Revert "Set `encrypted_password` to `nil` when `password` is set to `nil`" since it broke backward compatibility with existing applications. See more on https://github.com/heartcombo/devise/issues/5033#issuecomment-476386275 (by @mracos)
116
+
117
+ ### 4.6.1 - 2019-02-11
118
+
119
+ * bug fixes
120
+ * Check if `root_path` is defined with `#respond_to?` instead of `#present` (by @tegon)
2
121
 
3
122
  ### 4.6.0 - 2019-02-07
4
123
 
@@ -40,7 +159,7 @@
40
159
  * Add `autocomplete="new-password"` to new password fields (by @gssbzn)
41
160
  * Add `autocomplete="current-password"` to current password fields (by @gssbzn)
42
161
  * Remove redundant `self` from `database_authenticatable` module (by @abhishekkanojia)
43
- * Update `simple_form` templates with changes from https://github.com/plataformatec/devise/commit/16b3d6d67c7e017d461ea17ed29ea9738dc77e83 and https://github.com/plataformatec/devise/commit/6260c29a867b9a656f1e1557abe347a523178fab (by @gssbzn)
162
+ * Update `simple_form` templates with changes from https://github.com/heartcombo/devise/commit/16b3d6d67c7e017d461ea17ed29ea9738dc77e83 and https://github.com/heartcombo/devise/commit/6260c29a867b9a656f1e1557abe347a523178fab (by @gssbzn)
44
163
  * Remove `:trackable` from the default modules in the generators, to be more GDPR-friendly (by @fakenine)
45
164
 
46
165
  * bug fixes
@@ -287,5 +406,5 @@ configured (by @joshpencheon)
287
406
  You can check more examples and explanations on the [README section](README.md#strong-parameters)
288
407
  and on the [ParameterSanitizer docs](lib/devise/parameter_sanitizer.rb).
289
408
 
290
- Please check [3-stable](https://github.com/plataformatec/devise/blob/3-stable/CHANGELOG.md)
409
+ Please check [3-stable](https://github.com/heartcombo/devise/blob/3-stable/CHANGELOG.md)
291
410
  for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright 2009-2019 Plataformatec. http://plataformatec.com.br
1
+ Copyright 2020-2024 Rafael França, Leonardo Tegon, Carlos Antônio da Silva.
2
+ Copyright 2009-2019 Plataformatec.
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,11 +1,4 @@
1
- ![Devise Logo](https://raw.github.com/plataformatec/devise/master/devise.png)
2
-
3
- By [Plataformatec](http://plataformatec.com.br/).
4
-
5
- [![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](http://travis-ci.org/plataformatec/devise)
6
- [![Code Climate](https://codeclimate.com/github/plataformatec/devise.svg)](https://codeclimate.com/github/plataformatec/devise)
7
-
8
- This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
1
+ ![Devise Logo](https://raw.github.com/heartcombo/devise/main/devise.png)
9
2
 
10
3
  Devise is a flexible authentication solution for Rails based on Warden. It:
11
4
 
@@ -16,16 +9,16 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
16
9
 
17
10
  It's composed of 10 modules:
18
11
 
19
- * [Database Authenticatable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
20
- * [Omniauthable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
21
- * [Confirmable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
22
- * [Recoverable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
23
- * [Registerable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
24
- * [Rememberable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
25
- * [Trackable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
26
- * [Timeoutable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
27
- * [Validatable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
28
- * [Lockable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
12
+ * [Database Authenticatable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/DatabaseAuthenticatable): hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
13
+ * [Omniauthable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
14
+ * [Confirmable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
15
+ * [Recoverable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Recoverable): resets the user password and sends reset instructions.
16
+ * [Registerable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
17
+ * [Rememberable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
18
+ * [Trackable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
19
+ * [Timeoutable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
20
+ * [Validatable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
21
+ * [Lockable](http://www.rubydoc.info/github/heartcombo/devise/main/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
29
22
 
30
23
  ## Table of Contents
31
24
 
@@ -53,11 +46,11 @@ It's composed of 10 modules:
53
46
  - [Integration tests](#integration-tests)
54
47
  - [OmniAuth](#omniauth)
55
48
  - [Configuring multiple models](#configuring-multiple-models)
56
- - [ActiveJob Integration](#activejob-integration)
49
+ - [Active Job Integration](#active-job-integration)
57
50
  - [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs)
58
51
  - [Other ORMs](#other-orms)
52
+ - [Rails API mode](#rails-api-mode)
59
53
  - [Additional information](#additional-information)
60
- - [Heroku](#heroku)
61
54
  - [Warden](#warden)
62
55
  - [Contributors](#contributors)
63
56
  - [License](#license)
@@ -72,15 +65,15 @@ It's composed of 10 modules:
72
65
 
73
66
  The Devise Wiki has lots of additional information about Devise including many "how-to" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:
74
67
 
75
- https://github.com/plataformatec/devise/wiki
68
+ https://github.com/heartcombo/devise/wiki
76
69
 
77
70
  ### Bug reports
78
71
 
79
72
  If you discover a problem with Devise, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:
80
73
 
81
- https://github.com/plataformatec/devise/wiki/Bug-reports
74
+ https://github.com/heartcombo/devise/wiki/Bug-reports
82
75
 
83
- If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to opensource@plataformatec.com.br.
76
+ If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to heartcombo@googlegroups.com.
84
77
 
85
78
  ### StackOverflow and Mailing List
86
79
 
@@ -96,7 +89,7 @@ https://groups.google.com/group/plataformatec-devise
96
89
 
97
90
  You can view the Devise documentation in RDoc format here:
98
91
 
99
- http://rubydoc.info/github/plataformatec/devise/master/frames
92
+ http://rubydoc.info/github/heartcombo/devise/main/frames
100
93
 
101
94
  If you need to use Devise with previous versions of Rails, you can always run "gem server" from the command line after you install the gem to access the old documentation.
102
95
 
@@ -104,26 +97,26 @@ If you need to use Devise with previous versions of Rails, you can always run "g
104
97
 
105
98
  There are a few example applications available on GitHub that demonstrate various features of Devise with different versions of Rails. You can view them here:
106
99
 
107
- https://github.com/plataformatec/devise/wiki/Example-Applications
100
+ https://github.com/heartcombo/devise/wiki/Example-Applications
108
101
 
109
102
  ### Extensions
110
103
 
111
104
  Our community has created a number of extensions that add functionality above and beyond what is included with Devise. You can view a list of available extensions and add your own here:
112
105
 
113
- https://github.com/plataformatec/devise/wiki/Extensions
106
+ https://github.com/heartcombo/devise/wiki/Extensions
114
107
 
115
108
  ### Contributing
116
109
 
117
110
  We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
118
111
 
119
- https://github.com/plataformatec/devise/wiki/Contributing
112
+ https://github.com/heartcombo/devise/wiki/Contributing
120
113
 
121
114
  You will usually want to write tests for your changes. To run the test suite, go into Devise's top-level directory and run `bundle install` and `bin/test`.
122
115
  Devise works with multiple Ruby and Rails versions, and ActiveRecord and Mongoid ORMs, which means you can run the test suite with some modifiers: `DEVISE_ORM` and `BUNDLE_GEMFILE`.
123
116
 
124
117
  ### DEVISE_ORM
125
- Since Devise support both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.
126
- The default value of `DEVISE_ORM` is `active_record`. To run the tests for mongoid, you can pass `mongoid`:
118
+ Since Devise supports both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.
119
+ The default value of `DEVISE_ORM` is `active_record`. To run the tests for Mongoid, you can pass `mongoid`:
127
120
  ```
128
121
  DEVISE_ORM=mongoid bin/test
129
122
 
@@ -135,7 +128,7 @@ Please note that the command output will show the variable value being used.
135
128
 
136
129
  ### BUNDLE_GEMFILE
137
130
  We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
138
- Inside the [gemfiles](https://github.com/plataformatec/devise/tree/master/gemfiles) directory, we have one for each version of Rails we support. When you send us a pull request, it may happen that the test suite breaks on Travis using some of them. If that's the case, you can simulate the same environment using the `BUNDLE_GEMFILE` variable.
131
+ Inside the [gemfiles](https://github.com/heartcombo/devise/tree/main/gemfiles) directory, we have one for each version of Rails we support. When you send us a pull request, it may happen that the test suite breaks using some of them. If that's the case, you can simulate the same environment using the `BUNDLE_GEMFILE` variable.
139
132
  For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
140
133
  ```bash
141
134
  rbenv shell 2.4.2 # or rvm use 2.4.2
@@ -169,11 +162,11 @@ bin/test test/models/trackable_test.rb:16
169
162
 
170
163
  ## Starting with Rails?
171
164
 
172
- If you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch. Today, we have three resources that should help you get started:
165
+ If you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch. Here's a few resources that should help you get started:
173
166
 
174
167
  * Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
175
- * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
176
- * Codecademy's Ruby on Rails: Authentication and Authorization: http://www.codecademy.com/en/learn/rails-auth
168
+ * Ryan Bates' Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/250-authentication-from-scratch-revised
169
+ * Codecademy's Ruby on Rails: Authentication and Authorization: https://www.codecademy.com/learn/rails-auth
177
170
 
178
171
  Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
179
172
 
@@ -269,16 +262,16 @@ member_session
269
262
  The Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the hashing algorithm with:
270
263
 
271
264
  ```ruby
272
- devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 12
265
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13
273
266
  ```
274
267
 
275
268
  Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the "devise:install" generator described above. This file is usually located at `/config/initializers/devise.rb`.
276
269
 
277
270
  ### Strong Parameters
278
271
 
279
- ![The Parameter Sanitizer API has changed for Devise 4](http://messages.hellobits.com/warning.svg?message=The%20Parameter%20Sanitizer%20API%20has%20changed%20for%20Devise%204)
272
+ The Parameter Sanitizer API has changed for Devise 4 :warning:
280
273
 
281
- *For previous Devise versions see https://github.com/plataformatec/devise/tree/3-stable#strong-parameters*
274
+ *For previous Devise versions see https://github.com/heartcombo/devise/tree/3-stable#strong-parameters*
282
275
 
283
276
  When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.
284
277
 
@@ -288,7 +281,7 @@ There are just three actions in Devise that allow any set of parameters to be pa
288
281
  * `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
289
282
  * `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
290
283
 
291
- In case you want to permit additional parameters (the lazy way™), you can do so using a simple before filter in your `ApplicationController`:
284
+ In case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:
292
285
 
293
286
  ```ruby
294
287
  class ApplicationController < ActionController::Base
@@ -316,7 +309,7 @@ class ApplicationController < ActionController::Base
316
309
  end
317
310
  ```
318
311
 
319
- Devise allows you to completely change Devise defaults or invoke custom behaviour by passing a block:
312
+ Devise allows you to completely change Devise defaults or invoke custom behavior by passing a block:
320
313
 
321
314
  To permit simple scalar values for username and email, use this
322
315
 
@@ -389,7 +382,7 @@ $ rails generate devise:views users
389
382
  ```
390
383
 
391
384
  If you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,
392
- you can pass a list of modules to the generator with the `-v` flag.
385
+ you can pass a list of views to the generator with the `-v` flag.
393
386
 
394
387
  ```console
395
388
  $ rails generate devise:views -v registrations confirmations
@@ -417,7 +410,7 @@ If the customization at the views level is not enough, you can customize each co
417
410
  ...
418
411
  end
419
412
  ```
420
- (Use the -c flag to specify a controller, for example: `rails generate devise:controllers users -c=sessions`)
413
+ Use the `-c` flag to specify one or more controllers, for example: `rails generate devise:controllers users -c sessions`)
421
414
 
422
415
  2. Tell the router to use this controller:
423
416
 
@@ -425,7 +418,7 @@ If the customization at the views level is not enough, you can customize each co
425
418
  devise_for :users, controllers: { sessions: 'users/sessions' }
426
419
  ```
427
420
 
428
- 3. Copy the views from `devise/sessions` to `users/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
421
+ 3. Recommended but not required: copy (or move) the views from `devise/sessions` to `users/sessions`. Rails will continue using the views from `devise/sessions` due to inheritance if you skip this step, but having the views matching the controller(s) keeps things consistent.
429
422
 
430
423
  4. Finally, change or extend the desired controller actions.
431
424
 
@@ -439,7 +432,7 @@ If the customization at the views level is not enough, you can customize each co
439
432
  end
440
433
  ```
441
434
 
442
- Or you can simply add new behaviour to it:
435
+ Or you can simply add new behavior to it:
443
436
 
444
437
  ```ruby
445
438
  class Users::SessionsController < Devise::SessionsController
@@ -463,7 +456,7 @@ Devise also ships with default routes. If you need to customize them, you should
463
456
  devise_for :users, path: 'auth', path_names: { sign_in: 'login', sign_out: 'logout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'register', sign_up: 'cmon_let_me_in' }
464
457
  ```
465
458
 
466
- Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/plataformatec/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
459
+ Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/heartcombo/devise/main/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
467
460
 
468
461
  If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is create your routes normally and wrap them in a `devise_scope` block in the router:
469
462
 
@@ -481,6 +474,36 @@ Please note: You will still need to add `devise_for` in your routes in order to
481
474
  devise_for :users, skip: :all
482
475
  ```
483
476
 
477
+ ### Hotwire/Turbo
478
+
479
+ Devise integrates with Hotwire/Turbo by treating such requests as navigational, and configuring certain responses for errors and redirects to match the expected behavior. New apps are generated with the following response configuration by default, and existing apps may opt-in by adding the config to their Devise initializers:
480
+
481
+ ```ruby
482
+ Devise.setup do |config|
483
+ # ...
484
+ # When using Devise with Hotwire/Turbo, the http status for error responses
485
+ # and some redirects must match the following. The default in Devise for existing
486
+ # apps is `200 OK` and `302 Found` respectively, but new apps are generated with
487
+ # these new defaults that match Hotwire/Turbo behavior.
488
+ # Note: These might become the new default in future versions of Devise.
489
+ config.responder.error_status = :unprocessable_entity
490
+ config.responder.redirect_status = :see_other
491
+ end
492
+ ```
493
+
494
+ **Important**: these custom responses require the `responders` gem version to be `3.1.0` or higher, please make sure you update it if you're going to use this configuration. Check [this upgrade guide](https://github.com/heartcombo/devise/wiki/How-To:-Upgrade-to-Devise-4.9.0-[Hotwire-Turbo-integration]) for more info.
495
+
496
+ _Note_: the above statuses configuration may become the default for Devise in a future release.
497
+
498
+ There are a couple other changes you might need to make in your app to work with Hotwire/Turbo, if you're migrating from rails-ujs:
499
+
500
+ * The `data-confirm` option that adds a confirmation modal to buttons/forms before submission needs to change to `data-turbo-confirm`, so that Turbo handles those appropriately.
501
+ * The `data-method` option that sets the request method for link submissions needs to change to `data-turbo-method`. This is not necessary for `button_to` or `form`s since Turbo can handle those.
502
+
503
+ If you're setting up Devise to sign out via `:delete`, and you're using links (instead of buttons wrapped in a form) to sign out with the `method: :delete` option, they will need to be updated as described above. (Devise does not provide sign out links/buttons in its shared views.)
504
+
505
+ Make sure to inspect your views looking for those, and change appropriately.
506
+
484
507
  ### I18n
485
508
 
486
509
  Devise uses flash messages with I18n, in conjunction with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
@@ -519,7 +542,7 @@ en:
519
542
 
520
543
  Take a look at our locale file to check all available messages. You may also be interested in one of the many translations that are available on our wiki:
521
544
 
522
- https://github.com/plataformatec/devise/wiki/I18n
545
+ https://github.com/heartcombo/devise/wiki/I18n
523
546
 
524
547
  Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
525
548
 
@@ -531,15 +554,21 @@ cases/specs.
531
554
 
532
555
  ### Controller tests
533
556
 
534
- Controller tests require that you include `Devise::Test::ControllerHelpers` on
557
+ Controller tests require that you include `Devise::Test::IntegrationHelpers` on
535
558
  your test case or its parent `ActionController::TestCase` superclass.
536
- For Rails 5, include `Devise::Test::IntegrationHelpers` instead, since the superclass
537
- for controller tests has been changed to ActionDispatch::IntegrationTest
559
+ For Rails versions prior to 5, include `Devise::Test::ControllerHelpers` instead, since the superclass
560
+ for controller tests was changed to ActionDispatch::IntegrationTest
538
561
  (for more details, see the [Integration tests](#integration-tests) section).
539
562
 
540
563
  ```ruby
541
564
  class PostsControllerTest < ActionController::TestCase
542
- include Devise::Test::ControllerHelpers
565
+ include Devise::Test::IntegrationHelpers # Rails >= 5
566
+ end
567
+ ```
568
+
569
+ ```ruby
570
+ class PostsControllerTest < ActionController::TestCase
571
+ include Devise::Test::ControllerHelpers # Rails < 5
543
572
  end
544
573
  ```
545
574
 
@@ -619,7 +648,7 @@ are executed in your tests.
619
648
 
620
649
  You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
621
650
 
622
- * https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29
651
+ * https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
623
652
 
624
653
  ### OmniAuth
625
654
 
@@ -631,7 +660,7 @@ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
631
660
 
632
661
  You can read more about OmniAuth support in the wiki:
633
662
 
634
- * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
663
+ * https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
635
664
 
636
665
  ### Configuring multiple models
637
666
 
@@ -678,12 +707,12 @@ end
678
707
 
679
708
  ### Password reset tokens and Rails logs
680
709
 
681
- If you enable the [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable) module, note that a stolen password reset token could give an attacker access to your application. Devise takes effort to generate random, secure tokens, and stores only token digests in the database, never plaintext. However the default logging behavior in Rails can cause plaintext tokens to leak into log files:
710
+ If you enable the [Recoverable](http://rubydoc.info/github/heartcombo/devise/main/Devise/Models/Recoverable) module, note that a stolen password reset token could give an attacker access to your application. Devise takes effort to generate random, secure tokens, and stores only token digests in the database, never plaintext. However the default logging behavior in Rails can cause plaintext tokens to leak into log files:
682
711
 
683
712
  1. Action Mailer logs the entire contents of all outgoing emails to the DEBUG level. Password reset tokens delivered to users in email will be leaked.
684
713
  2. Active Job logs all arguments to every enqueued job at the INFO level. If you configure Devise to use `deliver_later` to send password reset emails, password reset tokens will be leaked.
685
714
 
686
- Rails sets the production logger level to DEBUG by default. Consider changing your production logger level to WARN if you wish to prevent tokens from being leaked into your logs. In `config/environments/production.rb`:
715
+ Rails sets the production logger level to INFO by default. Consider changing your production logger level to WARN if you wish to prevent tokens from being leaked into your logs. In `config/environments/production.rb`:
687
716
 
688
717
  ```ruby
689
718
  config.log_level = :warn
@@ -694,32 +723,50 @@ config.log_level = :warn
694
723
 
695
724
  Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.
696
725
 
697
- ## Additional information
726
+ ### Rails API Mode
698
727
 
699
- ### Heroku
728
+ Rails 5+ has a built-in [API Mode](https://edgeguides.rubyonrails.org/api_app.html) which optimizes Rails for use as an API (only). Devise is _somewhat_ able to handle applications that are built in this mode without additional modifications in the sense that it should not raise exceptions and the like. But some issues may still arise during `development`/`testing`, as we still don't know the full extent of this compatibility. (For more information, see [issue #4947](https://github.com/heartcombo/devise/issues/4947/))
700
729
 
701
- Using Devise on Heroku with Ruby on Rails 3.2 requires setting:
730
+ #### Supported Authentication Strategies
731
+ API-only applications don't support browser-based authentication via cookies, which is devise's default. Yet, devise can still provide authentication out of the box in those cases with the `http_authenticatable` strategy, which uses HTTP Basic Auth and authenticates the user on each request. (For more info, see this wiki article for [How To: Use HTTP Basic Authentication](https://github.com/heartcombo/devise/wiki/How-To:-Use-HTTP-Basic-Authentication))
732
+
733
+ The devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:
702
734
 
703
735
  ```ruby
704
- config.assets.initialize_on_precompile = false
736
+ config.http_authenticatable = [:database]
705
737
  ```
706
738
 
707
- Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
739
+ This restriction does not limit you from implementing custom warden strategies, either in your application or via gem-based extensions for devise.
740
+ A common authentication strategy for APIs is token-based authentication. For more information on extending devise to support this type of authentication and others, see the wiki article for [Simple Token Authentication Examples and alternatives](https://github.com/heartcombo/devise/wiki/How-To:-Simple-Token-Authentication-Example#alternatives) or this blog post on [Custom authentication methods with Devise](http://blog.plataformatec.com.br/2019/01/custom-authentication-methods-with-devise/).
741
+
742
+ #### Testing
743
+ API Mode changes the order of the middleware stack, and this can cause problems for `Devise::Test::IntegrationHelpers`. This problem usually surfaces as an ```undefined method `[]=' for nil:NilClass``` error when using integration test helpers, such as `#sign_in`. The solution is simply to reorder the middlewares by adding the following to test.rb:
744
+
745
+ ```ruby
746
+ Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
747
+ Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
748
+ ```
749
+
750
+ For a deeper understanding of this, review [this issue](https://github.com/heartcombo/devise/issues/4696).
751
+
752
+ Additionally be mindful that without views supported, some email-based flows from Confirmable, Recoverable and Lockable are not supported directly at this time.
753
+
754
+ ## Additional information
708
755
 
709
756
  ### Warden
710
757
 
711
758
  Devise is based on Warden, which is a general Rack authentication framework created by Daniel Neighman. We encourage you to read more about Warden here:
712
759
 
713
- https://github.com/hassox/warden
760
+ https://github.com/wardencommunity/warden
714
761
 
715
762
  ### Contributors
716
763
 
717
764
  We have a long list of valued contributors. Check them all at:
718
765
 
719
- https://github.com/plataformatec/devise/graphs/contributors
766
+ https://github.com/heartcombo/devise/graphs/contributors
720
767
 
721
768
  ## License
722
769
 
723
- MIT License. Copyright 2009-2018 Plataformatec. http://plataformatec.com.br
770
+ MIT License. Copyright 2020-2024 Rafael França, Leonardo Tegon, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
724
771
 
725
- You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.
772
+ The Devise logo is licensed under [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License](https://creativecommons.org/licenses/by-nc-nd/4.0/).
@@ -27,6 +27,7 @@ class Devise::ConfirmationsController < DeviseController
27
27
  set_flash_message!(:notice, :confirmed)
28
28
  respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
29
29
  else
30
+ # TODO: use `error_status` when the default changes to `:unprocessable_entity`.
30
31
  respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
31
32
  end
32
33
  end
@@ -36,7 +36,7 @@ class Devise::PasswordsController < DeviseController
36
36
 
37
37
  if resource.errors.empty?
38
38
  resource.unlock_access! if unlockable?(resource)
39
- if Devise.sign_in_after_reset_password
39
+ if resource_class.sign_in_after_reset_password
40
40
  flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
41
41
  set_flash_message!(:notice, flash_message)
42
42
  resource.after_database_authentication
@@ -53,7 +53,7 @@ class Devise::PasswordsController < DeviseController
53
53
 
54
54
  protected
55
55
  def after_resetting_password_path_for(resource)
56
- Devise.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
56
+ resource_class.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
57
57
  end
58
58
 
59
59
  # The path used after sending reset password instructions
@@ -67,7 +67,7 @@ class Devise::RegistrationsController < DeviseController
67
67
  Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
68
68
  set_flash_message! :notice, :destroyed
69
69
  yield resource if block_given?
70
- respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
70
+ respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name), status: Devise.responder.redirect_status }
71
71
  end
72
72
 
73
73
  # GET /resource/cancel
@@ -45,7 +45,7 @@ class Devise::SessionsController < DeviseController
45
45
  end
46
46
 
47
47
  def auth_options
48
- { scope: resource_name, recall: "#{controller_path}#new" }
48
+ { scope: resource_name, recall: "#{controller_path}#new", locale: I18n.locale }
49
49
  end
50
50
 
51
51
  def translation_scope
@@ -77,7 +77,7 @@ class Devise::SessionsController < DeviseController
77
77
  # support returning empty response on GET request
78
78
  respond_to do |format|
79
79
  format.all { head :no_content }
80
- format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
80
+ format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name), status: Devise.responder.redirect_status }
81
81
  end
82
82
  end
83
83
  end
@@ -29,6 +29,7 @@ class Devise::UnlocksController < DeviseController
29
29
  set_flash_message! :notice, :unlocked
30
30
  respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
31
31
  else
32
+ # TODO: use `error_status` when the default changes to `:unprocessable_entity`.
32
33
  respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
33
34
  end
34
35
  end