devise 4.7.1 → 4.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -4
  3. data/MIT-LICENSE +2 -1
  4. data/README.md +100 -65
  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 +1 -1
  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/registrations/edit.html.erb +1 -1
  14. data/app/views/devise/shared/_error_messages.html.erb +1 -1
  15. data/app/views/devise/shared/_links.html.erb +1 -1
  16. data/config/locales/en.yml +2 -2
  17. data/lib/devise/controllers/helpers.rb +7 -7
  18. data/lib/devise/controllers/responder.rb +35 -0
  19. data/lib/devise/controllers/sign_in_out.rb +7 -5
  20. data/lib/devise/controllers/url_helpers.rb +1 -1
  21. data/lib/devise/failure_app.rb +8 -5
  22. data/lib/devise/hooks/csrf_cleaner.rb +6 -1
  23. data/lib/devise/hooks/lockable.rb +2 -5
  24. data/lib/devise/hooks/timeoutable.rb +2 -2
  25. data/lib/devise/mapping.rb +1 -1
  26. data/lib/devise/models/authenticatable.rb +13 -8
  27. data/lib/devise/models/confirmable.rb +18 -39
  28. data/lib/devise/models/database_authenticatable.rb +16 -31
  29. data/lib/devise/models/lockable.rb +11 -3
  30. data/lib/devise/models/omniauthable.rb +2 -2
  31. data/lib/devise/models/recoverable.rb +8 -19
  32. data/lib/devise/models/rememberable.rb +2 -2
  33. data/lib/devise/models/timeoutable.rb +1 -1
  34. data/lib/devise/models/trackable.rb +1 -1
  35. data/lib/devise/models/validatable.rb +4 -9
  36. data/lib/devise/models.rb +1 -0
  37. data/lib/devise/omniauth.rb +2 -5
  38. data/lib/devise/orm.rb +71 -0
  39. data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
  40. data/lib/devise/rails/routes.rb +4 -4
  41. data/lib/devise/rails.rb +4 -0
  42. data/lib/devise/test/controller_helpers.rb +4 -2
  43. data/lib/devise/test/integration_helpers.rb +1 -1
  44. data/lib/devise/test_helpers.rb +1 -1
  45. data/lib/devise/version.rb +1 -1
  46. data/lib/devise.rb +35 -12
  47. data/lib/generators/active_record/devise_generator.rb +17 -2
  48. data/lib/generators/devise/devise_generator.rb +1 -1
  49. data/lib/generators/devise/install_generator.rb +1 -5
  50. data/lib/generators/devise/views_generator.rb +1 -1
  51. data/lib/generators/templates/README +9 -1
  52. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
  53. data/lib/generators/templates/devise.rb +25 -11
  54. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
  55. metadata +21 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dc5ab8b0dc2a902bcf6f66b156b87cdb5348a336f05fb8605b6db1d1f688bc5
4
- data.tar.gz: 3be07eb3511c19857e9ddd2071b469833ac88d5c780c0a3c831c94523252663b
3
+ metadata.gz: 1dc134957d3855a45dd68b04b36bca2a993b095b1c05f5d87f4a68d2469660df
4
+ data.tar.gz: '09de3502b6e5afdb42d9c34b7896dfd9fcc0d58fa088951a2aab2f39095246c4'
5
5
  SHA512:
6
- metadata.gz: 599ee2531bd66335b49e7282d2af71be9e02594fc36733ec3c8f96110a256ee918e45a56c88640558b16e943a599881435cdd0dbaa2029636d830364cfbcfeb4
7
- data.tar.gz: e785db9c81e1275f283896d604124067b67685bced32267a75f0205f39d98a0985d68d40933859e31196cd773ccf260841cf1663a4ee9dcaab9c397af2f1c1b2
6
+ metadata.gz: 2413954e6decdda1c1e0adf5bf39b8ede790ef90dfc61d433528e28948f248a598ac1772b2606ff1b79f07ae330aec153e92b53aa0b2708a1b7ca19156034e81
7
+ data.tar.gz: a04f21e33fb88287ff808102c76e550a70165b2fddbde92c3984a4fa3c325fe507b68366c4b1a11d847ddce3e3722e4bda7d09642f140a872c7c0c73de32ba50
data/CHANGELOG.md CHANGED
@@ -1,4 +1,87 @@
1
- ### Unreleased
1
+ ### 4.9.3 - 2023-10-11
2
+
3
+ * enhancements
4
+ * Add support for Rails 7.1.
5
+ * Add `Devise.deprecator` to integrate with new application deprecators in Rails 7.1. (@soartec-lab, @etiennebarrie)
6
+
7
+ ### 4.9.2 - 2023-04-03
8
+
9
+ * deprecations
10
+ * Bring back `Devise.activerecord51?` and deprecate it, in order to avoid breakage with some libraries that apparently relied on it.
11
+
12
+ ### 4.9.1 - 2023-03-31
13
+
14
+ * enhancements
15
+ * 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)
16
+ * Refactor conditional dirty tracking logic to a centralized module to simplify usage throughout the codebase. [#5575](https://github.com/heartcombo/devise/pull/5575)
17
+ * 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)
18
+
19
+ * bug fixes
20
+ * 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)
21
+ * 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)
22
+
23
+ ### 4.9.0 - 2023-02-17
24
+
25
+ * enhancements
26
+ * Add support for Ruby 3.1/3.2.
27
+ * Add support for Hotwire + Turbo, default in Rails 7+.
28
+ * 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:
29
+
30
+ ```ruby
31
+ # config/initializers/devise.rb
32
+ Devise.setup do |config|
33
+ # ...
34
+ config.responder.error_status = :unprocessable_entity
35
+ config.responder.redirect_status = :see_other
36
+ # ...
37
+ end
38
+ ```
39
+
40
+ 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.
41
+ * 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.
42
+ * 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.
43
+ * `: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.
44
+ * 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.
45
+ * 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.
46
+ * 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.
47
+ * 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.
48
+
49
+ ### 4.8.1 - 2021-12-16
50
+
51
+ * enhancements
52
+ * Add support for Rails 7.0. Please note that Turbo integration is not fully supported by Devise yet.
53
+
54
+ ### 4.8.0 - 2021-04-29
55
+
56
+ * enhancements
57
+ * 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.
58
+ - 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.)
59
+ - 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.
60
+ * Introduce `Lockable#reset_failed_attempts!` model method to reset failed attempts counter to 0 after the user signs in.
61
+ - 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!`.
62
+ * Add support for Ruby 3.
63
+ * Add support for Rails 6.1.
64
+ * Move CI to GitHub Actions.
65
+
66
+ * deprecations
67
+ * `Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION` is deprecated in favor of `Devise::Models::Authenticatable::UNSAFE_ATTRIBUTES_FOR_SERIALIZATION` (@hanachin)
68
+
69
+ ### 4.7.3 - 2020-09-20
70
+
71
+ * bug fixes
72
+ * Do not modify `:except` option given to `#serializable_hash`. (by @dpep)
73
+ * Fix thor deprecation when running the devise generator. (by @deivid-rodriguez)
74
+ * Fix hanging tests for streaming controllers using Devise. (by @afn)
75
+
76
+ ### 4.7.2 - 2020-06-10
77
+
78
+ * enhancements
79
+ * Increase default stretches to 12 (by @sergey-alekseev)
80
+ * Ruby 2.7 support (kwarg warnings removed)
81
+
82
+ * bug fixes
83
+ * Generate scoped views with proper scoped errors partial (by @shobhitic)
84
+ * Allow to set scoped `already_authenticated` error messages (by @gurgelrenan)
2
85
 
3
86
  ### 4.7.1 - 2019-09-06
4
87
 
@@ -21,7 +104,7 @@
21
104
  ### 4.6.2 - 2019-03-26
22
105
 
23
106
  * bug fixes
24
- * 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/plataformatec/devise/issues/5033#issuecomment-476386275 (by @mracos)
107
+ * 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)
25
108
 
26
109
  ### 4.6.1 - 2019-02-11
27
110
 
@@ -68,7 +151,7 @@
68
151
  * Add `autocomplete="new-password"` to new password fields (by @gssbzn)
69
152
  * Add `autocomplete="current-password"` to current password fields (by @gssbzn)
70
153
  * Remove redundant `self` from `database_authenticatable` module (by @abhishekkanojia)
71
- * Update `simple_form` templates with changes from https://github.com/plataformatec/devise/commit/16b3d6d67c7e017d461ea17ed29ea9738dc77e83 and https://github.com/plataformatec/devise/commit/6260c29a867b9a656f1e1557abe347a523178fab (by @gssbzn)
154
+ * Update `simple_form` templates with changes from https://github.com/heartcombo/devise/commit/16b3d6d67c7e017d461ea17ed29ea9738dc77e83 and https://github.com/heartcombo/devise/commit/6260c29a867b9a656f1e1557abe347a523178fab (by @gssbzn)
72
155
  * Remove `:trackable` from the default modules in the generators, to be more GDPR-friendly (by @fakenine)
73
156
 
74
157
  * bug fixes
@@ -315,5 +398,5 @@ configured (by @joshpencheon)
315
398
  You can check more examples and explanations on the [README section](README.md#strong-parameters)
316
399
  and on the [ParameterSanitizer docs](lib/devise/parameter_sanitizer.rb).
317
400
 
318
- Please check [3-stable](https://github.com/plataformatec/devise/blob/3-stable/CHANGELOG.md)
401
+ Please check [3-stable](https://github.com/heartcombo/devise/blob/3-stable/CHANGELOG.md)
319
402
  for previous changes.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright 2009-2019 Plataformatec. http://plataformatec.com.br
1
+ Copyright 2020-2023 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
 
@@ -58,7 +51,6 @@ It's composed of 10 modules:
58
51
  - [Other ORMs](#other-orms)
59
52
  - [Rails API mode](#rails-api-mode)
60
53
  - [Additional information](#additional-information)
61
- - [Heroku](#heroku)
62
54
  - [Warden](#warden)
63
55
  - [Contributors](#contributors)
64
56
  - [License](#license)
@@ -73,15 +65,15 @@ It's composed of 10 modules:
73
65
 
74
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:
75
67
 
76
- https://github.com/plataformatec/devise/wiki
68
+ https://github.com/heartcombo/devise/wiki
77
69
 
78
70
  ### Bug reports
79
71
 
80
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:
81
73
 
82
- https://github.com/plataformatec/devise/wiki/Bug-reports
74
+ https://github.com/heartcombo/devise/wiki/Bug-reports
83
75
 
84
- 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.
85
77
 
86
78
  ### StackOverflow and Mailing List
87
79
 
@@ -97,7 +89,7 @@ https://groups.google.com/group/plataformatec-devise
97
89
 
98
90
  You can view the Devise documentation in RDoc format here:
99
91
 
100
- http://rubydoc.info/github/plataformatec/devise/master/frames
92
+ http://rubydoc.info/github/heartcombo/devise/main/frames
101
93
 
102
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.
103
95
 
@@ -105,26 +97,26 @@ If you need to use Devise with previous versions of Rails, you can always run "g
105
97
 
106
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:
107
99
 
108
- https://github.com/plataformatec/devise/wiki/Example-Applications
100
+ https://github.com/heartcombo/devise/wiki/Example-Applications
109
101
 
110
102
  ### Extensions
111
103
 
112
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:
113
105
 
114
- https://github.com/plataformatec/devise/wiki/Extensions
106
+ https://github.com/heartcombo/devise/wiki/Extensions
115
107
 
116
108
  ### Contributing
117
109
 
118
110
  We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
119
111
 
120
- https://github.com/plataformatec/devise/wiki/Contributing
112
+ https://github.com/heartcombo/devise/wiki/Contributing
121
113
 
122
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`.
123
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`.
124
116
 
125
117
  ### DEVISE_ORM
126
- Since Devise support both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.
127
- 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`:
128
120
  ```
129
121
  DEVISE_ORM=mongoid bin/test
130
122
 
@@ -136,7 +128,7 @@ Please note that the command output will show the variable value being used.
136
128
 
137
129
  ### BUNDLE_GEMFILE
138
130
  We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
139
- 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.
140
132
  For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
141
133
  ```bash
142
134
  rbenv shell 2.4.2 # or rvm use 2.4.2
@@ -170,10 +162,10 @@ bin/test test/models/trackable_test.rb:16
170
162
 
171
163
  ## Starting with Rails?
172
164
 
173
- 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:
174
166
 
175
167
  * Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
176
- * Ryan Bates' Railscast: http://railscasts.com/episodes/250-authentication-from-scratch
168
+ * Ryan Bates' Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/250-authentication-from-scratch-revised
177
169
  * Codecademy's Ruby on Rails: Authentication and Authorization: https://www.codecademy.com/learn/rails-auth
178
170
 
179
171
  Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
@@ -270,16 +262,16 @@ member_session
270
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:
271
263
 
272
264
  ```ruby
273
- devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 12
265
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13
274
266
  ```
275
267
 
276
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`.
277
269
 
278
270
  ### Strong Parameters
279
271
 
280
- ![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:
281
273
 
282
- *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*
283
275
 
284
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.
285
277
 
@@ -289,7 +281,7 @@ There are just three actions in Devise that allow any set of parameters to be pa
289
281
  * `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
290
282
  * `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
291
283
 
292
- 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`:
293
285
 
294
286
  ```ruby
295
287
  class ApplicationController < ActionController::Base
@@ -317,7 +309,7 @@ class ApplicationController < ActionController::Base
317
309
  end
318
310
  ```
319
311
 
320
- 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:
321
313
 
322
314
  To permit simple scalar values for username and email, use this
323
315
 
@@ -390,7 +382,7 @@ $ rails generate devise:views users
390
382
  ```
391
383
 
392
384
  If you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,
393
- 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.
394
386
 
395
387
  ```console
396
388
  $ rails generate devise:views -v registrations confirmations
@@ -418,7 +410,7 @@ If the customization at the views level is not enough, you can customize each co
418
410
  ...
419
411
  end
420
412
  ```
421
- (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`)
422
414
 
423
415
  2. Tell the router to use this controller:
424
416
 
@@ -426,7 +418,7 @@ If the customization at the views level is not enough, you can customize each co
426
418
  devise_for :users, controllers: { sessions: 'users/sessions' }
427
419
  ```
428
420
 
429
- 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.
430
422
 
431
423
  4. Finally, change or extend the desired controller actions.
432
424
 
@@ -440,7 +432,7 @@ If the customization at the views level is not enough, you can customize each co
440
432
  end
441
433
  ```
442
434
 
443
- Or you can simply add new behaviour to it:
435
+ Or you can simply add new behavior to it:
444
436
 
445
437
  ```ruby
446
438
  class Users::SessionsController < Devise::SessionsController
@@ -464,7 +456,7 @@ Devise also ships with default routes. If you need to customize them, you should
464
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' }
465
457
  ```
466
458
 
467
- 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.
468
460
 
469
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:
470
462
 
@@ -482,6 +474,36 @@ Please note: You will still need to add `devise_for` in your routes in order to
482
474
  devise_for :users, skip: :all
483
475
  ```
484
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
+
485
507
  ### I18n
486
508
 
487
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:
@@ -520,7 +542,7 @@ en:
520
542
 
521
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:
522
544
 
523
- https://github.com/plataformatec/devise/wiki/I18n
545
+ https://github.com/heartcombo/devise/wiki/I18n
524
546
 
525
547
  Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
526
548
 
@@ -532,15 +554,21 @@ cases/specs.
532
554
 
533
555
  ### Controller tests
534
556
 
535
- Controller tests require that you include `Devise::Test::ControllerHelpers` on
557
+ Controller tests require that you include `Devise::Test::IntegrationHelpers` on
536
558
  your test case or its parent `ActionController::TestCase` superclass.
537
- For Rails 5, include `Devise::Test::IntegrationHelpers` instead, since the superclass
538
- 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
539
561
  (for more details, see the [Integration tests](#integration-tests) section).
540
562
 
541
563
  ```ruby
542
564
  class PostsControllerTest < ActionController::TestCase
543
- 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
544
572
  end
545
573
  ```
546
574
 
@@ -620,7 +648,7 @@ are executed in your tests.
620
648
 
621
649
  You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
622
650
 
623
- * https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
651
+ * https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
624
652
 
625
653
  ### OmniAuth
626
654
 
@@ -632,7 +660,7 @@ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
632
660
 
633
661
  You can read more about OmniAuth support in the wiki:
634
662
 
635
- * https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview
663
+ * https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
636
664
 
637
665
  ### Configuring multiple models
638
666
 
@@ -679,12 +707,12 @@ end
679
707
 
680
708
  ### Password reset tokens and Rails logs
681
709
 
682
- 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:
683
711
 
684
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.
685
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.
686
714
 
687
- 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`:
688
716
 
689
717
  ```ruby
690
718
  config.log_level = :warn
@@ -697,41 +725,48 @@ Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simpl
697
725
 
698
726
  ### Rails API Mode
699
727
 
700
- Rails 5+ has a built-in [API Mode](https://edgeguides.rubyonrails.org/api_app.html) which optimizes Rails for use as an API (only). One of the side effects is that it 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:
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/))
701
729
 
702
- ```ruby
703
- Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
704
- Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
705
- ```
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))
706
732
 
707
- For a deeper understanding of this, review [this issue](https://github.com/plataformatec/devise/issues/4696).
733
+ The devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:
708
734
 
709
- ## Additional information
735
+ ```ruby
736
+ config.http_authenticatable = [:database]
737
+ ```
710
738
 
711
- ### Heroku
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/).
712
741
 
713
- Using Devise on Heroku with Ruby on Rails 3.2 requires setting:
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:
714
744
 
715
745
  ```ruby
716
- config.assets.initialize_on_precompile = false
746
+ Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
747
+ Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
717
748
  ```
718
749
 
719
- Read more about the potential issues at http://guides.rubyonrails.org/asset_pipeline.html
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
720
755
 
721
756
  ### Warden
722
757
 
723
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:
724
759
 
725
- https://github.com/hassox/warden
760
+ https://github.com/wardencommunity/warden
726
761
 
727
762
  ### Contributors
728
763
 
729
764
  We have a long list of valued contributors. Check them all at:
730
765
 
731
- https://github.com/plataformatec/devise/graphs/contributors
766
+ https://github.com/heartcombo/devise/graphs/contributors
732
767
 
733
768
  ## License
734
769
 
735
- MIT License. Copyright 2009-2019 Plataformatec. http://plataformatec.com.br
770
+ MIT License. Copyright 2020-2023 Rafael França, Leonardo Tegon, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
736
771
 
737
- 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
@@ -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
@@ -15,6 +15,7 @@ class DeviseController < Devise.parent_controller.constantize
15
15
  end
16
16
 
17
17
  prepend_before_action :assert_is_devise_resource!
18
+ self.responder = Devise.responder
18
19
  respond_to :html if mimes_for_respond_to.empty?
19
20
 
20
21
  # Override prefixes to consider the scoped view.
@@ -32,6 +33,19 @@ class DeviseController < Devise.parent_controller.constantize
32
33
  end
33
34
  end
34
35
 
36
+ # Override internal methods to exclude `_prefixes` from action methods since
37
+ # we override it above.
38
+ #
39
+ # There was an intentional change in Rails 7.1 that will allow it to become
40
+ # an action method because it's a public method of a non-abstract controller,
41
+ # but we also can't make this abstract because it can affect potential actions
42
+ # defined in the parent controller, so instead we ensure `_prefixes` is going
43
+ # to be considered internal. (and thus, won't become an action method.)
44
+ # Ref: https://github.com/rails/rails/pull/48699
45
+ def self.internal_methods #:nodoc:
46
+ super << :_prefixes
47
+ end
48
+
35
49
  protected
36
50
 
37
51
  # Gets the actual resource stored in the instance variable
@@ -112,7 +126,7 @@ MESSAGE
112
126
  end
113
127
 
114
128
  if authenticated && resource = warden.user(resource_name)
115
- flash[:alert] = I18n.t("devise.failure.already_authenticated")
129
+ set_flash_message(:alert, 'already_authenticated', scope: 'devise.failure')
116
130
  redirect_to after_sign_in_path_for(resource)
117
131
  end
118
132
  end
@@ -184,7 +198,7 @@ MESSAGE
184
198
  options[:default] = Array(options[:default]).unshift(kind.to_sym)
185
199
  options[:resource_name] = resource_name
186
200
  options = devise_i18n_options(options)
187
- I18n.t("#{options[:resource_name]}.#{kind}", options)
201
+ I18n.t("#{options[:resource_name]}.#{kind}", **options)
188
202
  end
189
203
 
190
204
  # Controllers inheriting DeviseController are advised to override this