ultra-max-kit 0.0.1

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 (114) hide show
  1. checksums.yaml +7 -0
  2. data/devise-5.0.4/CHANGELOG.md +88 -0
  3. data/devise-5.0.4/MIT-LICENSE +21 -0
  4. data/devise-5.0.4/README.md +776 -0
  5. data/devise-5.0.4/app/controllers/devise/confirmations_controller.rb +54 -0
  6. data/devise-5.0.4/app/controllers/devise/omniauth_callbacks_controller.rb +36 -0
  7. data/devise-5.0.4/app/controllers/devise/passwords_controller.rb +88 -0
  8. data/devise-5.0.4/app/controllers/devise/registrations_controller.rb +169 -0
  9. data/devise-5.0.4/app/controllers/devise/sessions_controller.rb +83 -0
  10. data/devise-5.0.4/app/controllers/devise/unlocks_controller.rb +52 -0
  11. data/devise-5.0.4/app/controllers/devise_controller.rb +226 -0
  12. data/devise-5.0.4/app/helpers/devise_helper.rb +5 -0
  13. data/devise-5.0.4/app/mailers/devise/mailer.rb +30 -0
  14. data/devise-5.0.4/app/views/devise/confirmations/new.html.erb +16 -0
  15. data/devise-5.0.4/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  16. data/devise-5.0.4/app/views/devise/mailer/email_changed.html.erb +7 -0
  17. data/devise-5.0.4/app/views/devise/mailer/password_change.html.erb +3 -0
  18. data/devise-5.0.4/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  19. data/devise-5.0.4/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  20. data/devise-5.0.4/app/views/devise/passwords/edit.html.erb +25 -0
  21. data/devise-5.0.4/app/views/devise/passwords/new.html.erb +16 -0
  22. data/devise-5.0.4/app/views/devise/registrations/edit.html.erb +42 -0
  23. data/devise-5.0.4/app/views/devise/registrations/new.html.erb +29 -0
  24. data/devise-5.0.4/app/views/devise/sessions/new.html.erb +26 -0
  25. data/devise-5.0.4/app/views/devise/shared/_error_messages.html.erb +15 -0
  26. data/devise-5.0.4/app/views/devise/shared/_links.html.erb +25 -0
  27. data/devise-5.0.4/app/views/devise/unlocks/new.html.erb +16 -0
  28. data/devise-5.0.4/config/locales/en.yml +65 -0
  29. data/devise-5.0.4/lib/devise/controllers/helpers.rb +295 -0
  30. data/devise-5.0.4/lib/devise/controllers/rememberable.rb +56 -0
  31. data/devise-5.0.4/lib/devise/controllers/responder.rb +35 -0
  32. data/devise-5.0.4/lib/devise/controllers/scoped_views.rb +19 -0
  33. data/devise-5.0.4/lib/devise/controllers/sign_in_out.rb +106 -0
  34. data/devise-5.0.4/lib/devise/controllers/store_location.rb +76 -0
  35. data/devise-5.0.4/lib/devise/controllers/url_helpers.rb +69 -0
  36. data/devise-5.0.4/lib/devise/delegator.rb +18 -0
  37. data/devise-5.0.4/lib/devise/encryptor.rb +24 -0
  38. data/devise-5.0.4/lib/devise/failure_app.rb +287 -0
  39. data/devise-5.0.4/lib/devise/hooks/activatable.rb +12 -0
  40. data/devise-5.0.4/lib/devise/hooks/csrf_cleaner.rb +14 -0
  41. data/devise-5.0.4/lib/devise/hooks/forgetable.rb +11 -0
  42. data/devise-5.0.4/lib/devise/hooks/lockable.rb +9 -0
  43. data/devise-5.0.4/lib/devise/hooks/proxy.rb +23 -0
  44. data/devise-5.0.4/lib/devise/hooks/rememberable.rb +9 -0
  45. data/devise-5.0.4/lib/devise/hooks/timeoutable.rb +35 -0
  46. data/devise-5.0.4/lib/devise/hooks/trackable.rb +11 -0
  47. data/devise-5.0.4/lib/devise/mailers/helpers.rb +87 -0
  48. data/devise-5.0.4/lib/devise/mapping.rb +178 -0
  49. data/devise-5.0.4/lib/devise/models/authenticatable.rb +302 -0
  50. data/devise-5.0.4/lib/devise/models/confirmable.rb +371 -0
  51. data/devise-5.0.4/lib/devise/models/database_authenticatable.rb +204 -0
  52. data/devise-5.0.4/lib/devise/models/lockable.rb +214 -0
  53. data/devise-5.0.4/lib/devise/models/omniauthable.rb +29 -0
  54. data/devise-5.0.4/lib/devise/models/recoverable.rb +156 -0
  55. data/devise-5.0.4/lib/devise/models/registerable.rb +29 -0
  56. data/devise-5.0.4/lib/devise/models/rememberable.rb +158 -0
  57. data/devise-5.0.4/lib/devise/models/timeoutable.rb +45 -0
  58. data/devise-5.0.4/lib/devise/models/trackable.rb +51 -0
  59. data/devise-5.0.4/lib/devise/models/validatable.rb +70 -0
  60. data/devise-5.0.4/lib/devise/models.rb +122 -0
  61. data/devise-5.0.4/lib/devise/modules.rb +30 -0
  62. data/devise-5.0.4/lib/devise/omniauth/config.rb +47 -0
  63. data/devise-5.0.4/lib/devise/omniauth/url_helpers.rb +27 -0
  64. data/devise-5.0.4/lib/devise/omniauth.rb +27 -0
  65. data/devise-5.0.4/lib/devise/orm/active_record.rb +7 -0
  66. data/devise-5.0.4/lib/devise/orm/mongoid.rb +7 -0
  67. data/devise-5.0.4/lib/devise/orm.rb +80 -0
  68. data/devise-5.0.4/lib/devise/parameter_filter.rb +44 -0
  69. data/devise-5.0.4/lib/devise/parameter_sanitizer.rb +172 -0
  70. data/devise-5.0.4/lib/devise/rails/routes.rb +514 -0
  71. data/devise-5.0.4/lib/devise/rails/warden_compat.rb +15 -0
  72. data/devise-5.0.4/lib/devise/rails.rb +57 -0
  73. data/devise-5.0.4/lib/devise/strategies/authenticatable.rb +178 -0
  74. data/devise-5.0.4/lib/devise/strategies/base.rb +22 -0
  75. data/devise-5.0.4/lib/devise/strategies/database_authenticatable.rb +31 -0
  76. data/devise-5.0.4/lib/devise/strategies/rememberable.rb +67 -0
  77. data/devise-5.0.4/lib/devise/test/controller_helpers.rb +156 -0
  78. data/devise-5.0.4/lib/devise/test/integration_helpers.rb +63 -0
  79. data/devise-5.0.4/lib/devise/time_inflector.rb +16 -0
  80. data/devise-5.0.4/lib/devise/token_generator.rb +32 -0
  81. data/devise-5.0.4/lib/devise/version.rb +5 -0
  82. data/devise-5.0.4/lib/devise.rb +533 -0
  83. data/devise-5.0.4/lib/generators/active_record/devise_generator.rb +119 -0
  84. data/devise-5.0.4/lib/generators/active_record/templates/migration.rb +20 -0
  85. data/devise-5.0.4/lib/generators/active_record/templates/migration_existing.rb +27 -0
  86. data/devise-5.0.4/lib/generators/devise/controllers_generator.rb +46 -0
  87. data/devise-5.0.4/lib/generators/devise/devise_generator.rb +28 -0
  88. data/devise-5.0.4/lib/generators/devise/install_generator.rb +42 -0
  89. data/devise-5.0.4/lib/generators/devise/orm_helpers.rb +36 -0
  90. data/devise-5.0.4/lib/generators/devise/views_generator.rb +145 -0
  91. data/devise-5.0.4/lib/generators/mongoid/devise_generator.rb +57 -0
  92. data/devise-5.0.4/lib/generators/templates/README +36 -0
  93. data/devise-5.0.4/lib/generators/templates/controllers/README +14 -0
  94. data/devise-5.0.4/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
  95. data/devise-5.0.4/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
  96. data/devise-5.0.4/lib/generators/templates/controllers/passwords_controller.rb +34 -0
  97. data/devise-5.0.4/lib/generators/templates/controllers/registrations_controller.rb +62 -0
  98. data/devise-5.0.4/lib/generators/templates/controllers/sessions_controller.rb +27 -0
  99. data/devise-5.0.4/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
  100. data/devise-5.0.4/lib/generators/templates/devise.rb +316 -0
  101. data/devise-5.0.4/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  102. data/devise-5.0.4/lib/generators/templates/markerb/email_changed.markerb +7 -0
  103. data/devise-5.0.4/lib/generators/templates/markerb/password_change.markerb +3 -0
  104. data/devise-5.0.4/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  105. data/devise-5.0.4/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  106. data/devise-5.0.4/lib/generators/templates/simple_form_for/confirmations/new.html.erb +20 -0
  107. data/devise-5.0.4/lib/generators/templates/simple_form_for/passwords/edit.html.erb +27 -0
  108. data/devise-5.0.4/lib/generators/templates/simple_form_for/passwords/new.html.erb +18 -0
  109. data/devise-5.0.4/lib/generators/templates/simple_form_for/registrations/edit.html.erb +35 -0
  110. data/devise-5.0.4/lib/generators/templates/simple_form_for/registrations/new.html.erb +25 -0
  111. data/devise-5.0.4/lib/generators/templates/simple_form_for/sessions/new.html.erb +20 -0
  112. data/devise-5.0.4/lib/generators/templates/simple_form_for/unlocks/new.html.erb +19 -0
  113. data/ultra-max-kit.gemspec +12 -0
  114. metadata +153 -0
@@ -0,0 +1,776 @@
1
+ ![Devise Logo](https://raw.github.com/heartcombo/devise/main/devise.png)
2
+
3
+ Devise is a flexible authentication solution for Rails based on Warden. It:
4
+
5
+ * Is Rack based;
6
+ * Is a complete MVC solution based on Rails engines;
7
+ * Allows you to have multiple models signed in at the same time;
8
+ * Is based on a modularity concept: use only what you really need.
9
+
10
+ It's composed of 10 modules:
11
+
12
+ * [Database Authenticatable](https://www.rubydoc.info/gems/devise/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](https://www.rubydoc.info/gems/devise/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
14
+ * [Confirmable](https://www.rubydoc.info/gems/devise/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
15
+ * [Recoverable](https://www.rubydoc.info/gems/devise/Devise/Models/Recoverable): resets the user password and sends reset instructions.
16
+ * [Registerable](https://www.rubydoc.info/gems/devise/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
17
+ * [Rememberable](https://www.rubydoc.info/gems/devise/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
18
+ * [Trackable](https://www.rubydoc.info/gems/devise/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
19
+ * [Timeoutable](https://www.rubydoc.info/gems/devise/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
20
+ * [Validatable](https://www.rubydoc.info/gems/devise/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](https://www.rubydoc.info/gems/devise/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.
22
+
23
+ ## Table of Contents
24
+
25
+ <!-- TOC depthFrom:1 depthTo:6 withLinks:1 orderedList:0 -->
26
+
27
+ - [Information](#information)
28
+ - [The Devise wiki](#the-devise-wiki)
29
+ - [Bug reports](#bug-reports)
30
+ - [StackOverflow and Mailing List](#stackoverflow-and-mailing-list)
31
+ - [RDocs](#rdocs)
32
+ - [Example applications](#example-applications)
33
+ - [Extensions](#extensions)
34
+ - [Supported Ruby / Rails versions](#supported-ruby--rails-versions)
35
+ - [Contributing](#contributing)
36
+ - [Starting with Rails?](#starting-with-rails)
37
+ - [Getting started](#getting-started)
38
+ - [Controller filters and helpers](#controller-filters-and-helpers)
39
+ - [Configuring Models](#configuring-models)
40
+ - [Strong Parameters](#strong-parameters)
41
+ - [Configuring views](#configuring-views)
42
+ - [Configuring controllers](#configuring-controllers)
43
+ - [Configuring routes](#configuring-routes)
44
+ - [I18n](#i18n)
45
+ - [Test helpers](#test-helpers)
46
+ - [Controller tests](#controller-tests)
47
+ - [Integration tests](#integration-tests)
48
+ - [OmniAuth](#omniauth)
49
+ - [Configuring multiple models](#configuring-multiple-models)
50
+ - [Active Job Integration](#active-job-integration)
51
+ - [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs)
52
+ - [Other ORMs](#other-orms)
53
+ - [Rails API mode](#rails-api-mode)
54
+ - [Additional information](#additional-information)
55
+ - [Warden](#warden)
56
+ - [License](#license)
57
+
58
+ <!-- /TOC -->
59
+
60
+
61
+
62
+ ## Information
63
+
64
+ ### The Devise wiki
65
+
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:
67
+
68
+ https://github.com/heartcombo/devise/wiki
69
+
70
+ ### Bug reports
71
+
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:
73
+
74
+ https://github.com/heartcombo/devise/wiki/Bug-reports
75
+
76
+ If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to heartcombo.oss@gmail.com.
77
+
78
+ ### StackOverflow and Mailing List
79
+
80
+ If you have any questions, comments, or concerns, please use StackOverflow instead of the GitHub issue tracker:
81
+
82
+ https://stackoverflow.com/questions/tagged/devise
83
+
84
+ The deprecated mailing lists can still be read on:
85
+
86
+ https://groups.google.com/group/plataformatec-devise
87
+ https://groups.google.com/group/heartcombo
88
+
89
+ ### RDocs
90
+
91
+ You can view the Devise documentation in RDoc format here:
92
+
93
+ https://rubydoc.info/github/heartcombo/devise/main/frames
94
+
95
+ 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.
96
+
97
+ ### Example applications
98
+
99
+ 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:
100
+
101
+ https://github.com/heartcombo/devise/wiki/Example-Applications
102
+
103
+ ### Extensions
104
+
105
+ 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:
106
+
107
+ https://github.com/heartcombo/devise/wiki/Extensions
108
+
109
+ ### Supported Ruby / Rails versions
110
+
111
+ We intend to maintain support for all Ruby / Rails versions that haven't reached end-of-life.
112
+
113
+ For more information about specific versions please check [Ruby](https://www.ruby-lang.org/en/downloads/branches/)
114
+ and [Rails](https://guides.rubyonrails.org/maintenance_policy.html) maintenance policies, and our test matrix.
115
+
116
+ ### Contributing
117
+
118
+ We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
119
+
120
+ https://github.com/heartcombo/devise/wiki/Contributing
121
+
122
+ 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
+ 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
+
125
+ #### DEVISE_ORM
126
+ Since Devise supports 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`:
128
+ ```
129
+ DEVISE_ORM=mongoid bin/test
130
+
131
+ ==> Devise.orm = :mongoid
132
+ ```
133
+ When running the tests for Mongoid, you will need to have a MongoDB server (version 2.0 or newer) running on your system.
134
+
135
+ Please note that the command output will show the variable value being used.
136
+
137
+ #### BUNDLE_GEMFILE
138
+ 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/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
+ For example, if the tests broke using Ruby 3.4 and Rails 8.0, you can do the following:
141
+ ```bash
142
+ chruby 3.4.0 # or rbenv shell 3.4.0, or rvm use 3.4.0, etc.
143
+ BUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 bundle install
144
+ BUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 bin/test
145
+ ```
146
+
147
+ You can also combine both of them if the tests broke for Mongoid:
148
+ ```bash
149
+ BUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 bundle install
150
+ BUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 DEVISE_ORM=mongoid bin/test
151
+ ```
152
+
153
+ ### Running tests
154
+ Devise uses [minitest](https://github.com/seattlerb/minitest) as test framework.
155
+
156
+ * Running all tests:
157
+ ```bash
158
+ bin/test
159
+ ```
160
+
161
+ * Running tests for an specific file:
162
+ ```bash
163
+ bin/test test/models/trackable_test.rb
164
+ ```
165
+
166
+ * Running a specific test given a line number or a regex:
167
+ ```bash
168
+ bin/test test/models/trackable_test.rb:16
169
+ bin/test test/models/trackable_test.rb -n '/update.*record/'
170
+ ```
171
+
172
+ ## Starting with Rails?
173
+
174
+ 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:
175
+
176
+ * Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
177
+ * Ryan Bates' Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/250-authentication-from-scratch-revised
178
+ * Codecademy's Ruby on Rails: Authentication and Authorization: https://www.codecademy.com/learn/rails-auth
179
+
180
+ Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
181
+
182
+ ## Getting started
183
+
184
+ Devise 5 works with Rails 7 onwards. Run:
185
+
186
+ ```sh
187
+ bundle add devise
188
+ ```
189
+
190
+ Next, you need to run the generator:
191
+
192
+ ```console
193
+ rails generate devise:install
194
+ ```
195
+
196
+ At this point, a number of instructions will appear in the console. Among these instructions, you'll need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
197
+
198
+ ```ruby
199
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
200
+ ```
201
+
202
+ The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator.
203
+
204
+
205
+ In the following command you will replace `MODEL` with the class name used for the application’s users (it’s frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with the default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller.
206
+
207
+ ```console
208
+ rails generate devise MODEL
209
+ ```
210
+
211
+ Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.
212
+
213
+ Then run `rails db:migrate`
214
+
215
+ You should restart your application after changing Devise's configuration options (this includes stopping spring). Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.
216
+
217
+ ### Controller filters and helpers
218
+
219
+ Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_action (assuming your devise model is 'User'):
220
+
221
+ ```ruby
222
+ before_action :authenticate_user!
223
+ ```
224
+
225
+ For Rails 5, note that `protect_from_forgery` is no longer prepended to the `before_action` chain, so if you have set `authenticate_user` before `protect_from_forgery`, your request will result in "Can't verify CSRF token authenticity." To resolve this, either change the order in which you call them, or use `protect_from_forgery prepend: true`.
226
+
227
+ If your devise model is something other than User, replace "_user" with "_yourmodel". The same logic applies to the instructions below.
228
+
229
+ To verify if a user is signed in, use the following helper:
230
+
231
+ ```ruby
232
+ user_signed_in?
233
+ ```
234
+
235
+ For the current signed-in user, this helper is available:
236
+
237
+ ```ruby
238
+ current_user
239
+ ```
240
+
241
+ You can access the session for this scope:
242
+
243
+ ```ruby
244
+ user_session
245
+ ```
246
+
247
+ After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect to. For instance, when using a `:user` resource, the `user_root_path` will be used if it exists; otherwise, the default `root_path` will be used. This means that you need to set the root inside your routes:
248
+
249
+ ```ruby
250
+ root to: 'home#index'
251
+ ```
252
+
253
+ You can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
254
+
255
+ Notice that if your Devise model is called `Member` instead of `User`, for example, then the helpers available are:
256
+
257
+ ```ruby
258
+ before_action :authenticate_member!
259
+
260
+ member_signed_in?
261
+
262
+ current_member
263
+
264
+ member_session
265
+ ```
266
+
267
+ ### Configuring Models
268
+
269
+ 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
+
271
+ ```ruby
272
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13
273
+ ```
274
+
275
+ 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
+
277
+ ### Strong Parameters
278
+
279
+ The Parameter Sanitizer API has changed for Devise 4 :warning:
280
+
281
+ *For previous Devise versions see https://github.com/heartcombo/devise/tree/3-stable#strong-parameters*
282
+
283
+ 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
+
285
+ There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and default permitted parameters are:
286
+
287
+ * `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`)
288
+ * `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
289
+ * `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
290
+
291
+ In case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:
292
+
293
+ ```ruby
294
+ class ApplicationController < ActionController::Base
295
+ before_action :configure_permitted_parameters, if: :devise_controller?
296
+
297
+ protected
298
+
299
+ def configure_permitted_parameters
300
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
301
+ end
302
+ end
303
+ ```
304
+
305
+ The above works for any additional fields where the parameters are simple scalar types. If you have nested attributes (say you're using `accepts_nested_attributes_for`), then you will need to tell devise about those nestings and types:
306
+
307
+ ```ruby
308
+ class ApplicationController < ActionController::Base
309
+ before_action :configure_permitted_parameters, if: :devise_controller?
310
+
311
+ protected
312
+
313
+ def configure_permitted_parameters
314
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, address_attributes: [:country, :state, :city, :area, :postal_code]])
315
+ end
316
+ end
317
+ ```
318
+
319
+ Devise allows you to completely change Devise defaults or invoke custom behavior by passing a block:
320
+
321
+ To permit simple scalar values for username and email, use this
322
+
323
+ ```ruby
324
+ def configure_permitted_parameters
325
+ devise_parameter_sanitizer.permit(:sign_in) do |user_params|
326
+ user_params.permit(:username, :email)
327
+ end
328
+ end
329
+ ```
330
+
331
+ If you have some checkboxes that express the roles a user may take on registration, the browser will send those selected checkboxes as an array. An array is not one of Strong Parameters' permitted scalars, so we need to configure Devise in the following way:
332
+
333
+ ```ruby
334
+ def configure_permitted_parameters
335
+ devise_parameter_sanitizer.permit(:sign_up) do |user_params|
336
+ user_params.permit({ roles: [] }, :email, :password, :password_confirmation)
337
+ end
338
+ end
339
+ ```
340
+ For the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see
341
+
342
+ https://github.com/rails/strong_parameters#nested-parameters
343
+
344
+ If you have multiple Devise models, you may want to set up a different parameter sanitizer per model. In this case, we recommend inheriting from `Devise::ParameterSanitizer` and adding your own logic:
345
+
346
+ ```ruby
347
+ class User::ParameterSanitizer < Devise::ParameterSanitizer
348
+ def initialize(*)
349
+ super
350
+ permit(:sign_up, keys: [:username, :email])
351
+ end
352
+ end
353
+ ```
354
+
355
+ And then configure your controllers to use it:
356
+
357
+ ```ruby
358
+ class ApplicationController < ActionController::Base
359
+ protected
360
+
361
+ def devise_parameter_sanitizer
362
+ if resource_class == User
363
+ User::ParameterSanitizer.new(User, :user, params)
364
+ else
365
+ super # Use the default one
366
+ end
367
+ end
368
+ end
369
+ ```
370
+
371
+ The example above overrides the permitted parameters for the user to be both `:username` and `:email`. The non-lazy way to configure parameters would be by defining the before filter above in a custom controller. We detail how to configure and customize controllers in some sections below.
372
+
373
+ ### Configuring views
374
+
375
+ We built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.
376
+
377
+ Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
378
+
379
+ ```console
380
+ rails generate devise:views
381
+ ```
382
+
383
+ If you have more than one Devise model in your application (such as `User` and `Admin`), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set `config.scoped_views = true` inside the `config/initializers/devise.rb` file.
384
+
385
+ After doing so, you will be able to have views based on the role like `users/sessions/new` and `admins/sessions/new`. If no view is found within the scope, Devise will use the default view at `devise/sessions/new`. You can also use the generator to generate scoped views:
386
+
387
+ ```console
388
+ rails generate devise:views users
389
+ ```
390
+
391
+ 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 views to the generator with the `-v` flag.
393
+
394
+ ```console
395
+ rails generate devise:views -v registrations confirmations
396
+ ```
397
+
398
+ ### Configuring controllers
399
+
400
+ If the customization at the views level is not enough, you can customize each controller by following these steps:
401
+
402
+ 1. Create your custom controllers using the generator which requires a scope:
403
+
404
+ ```console
405
+ rails generate devise:controllers [scope]
406
+ ```
407
+
408
+ If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.
409
+ And the sessions controller will look like this:
410
+
411
+ ```ruby
412
+ class Users::SessionsController < Devise::SessionsController
413
+ # GET /resource/sign_in
414
+ # def new
415
+ # super
416
+ # end
417
+ ...
418
+ end
419
+ ```
420
+ Use the `-c` flag to specify one or more controllers, for example: `rails generate devise:controllers users -c sessions`
421
+
422
+ 2. Tell the router to use this controller:
423
+
424
+ ```ruby
425
+ devise_for :users, controllers: { sessions: 'users/sessions' }
426
+ ```
427
+
428
+ 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
+
430
+ 4. Finally, change or extend the desired controller actions.
431
+
432
+ You can completely override a controller action:
433
+
434
+ ```ruby
435
+ class Users::SessionsController < Devise::SessionsController
436
+ def create
437
+ # custom sign-in code
438
+ end
439
+ end
440
+ ```
441
+
442
+ Or you can simply add new behavior to it:
443
+
444
+ ```ruby
445
+ class Users::SessionsController < Devise::SessionsController
446
+ def create
447
+ super do |resource|
448
+ BackgroundWorker.trigger(resource)
449
+ end
450
+ end
451
+ end
452
+ ```
453
+
454
+ This is useful for triggering background jobs or logging events during certain actions.
455
+
456
+ Remember that Devise uses flash messages to let users know if sign in was successful or unsuccessful. Devise expects your application to call `flash[:notice]` and `flash[:alert]` as appropriate. Do not print the entire flash hash, print only specific keys. In some circumstances, Devise adds a `:timedout` key to the flash hash, which is not meant for display. Remove this key from the hash if you intend to print the entire hash.
457
+
458
+ ### Configuring routes
459
+
460
+ Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
461
+
462
+ ```ruby
463
+ 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
+ ```
465
+
466
+ Be sure to check `devise_for` [documentation](https://www.rubydoc.info/gems/devise/ActionDispatch/Routing/Mapper#devise_for-instance_method) for details.
467
+
468
+ 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
+
470
+ ```ruby
471
+ devise_scope :user do
472
+ get 'sign_in', to: 'devise/sessions#new'
473
+ end
474
+ ```
475
+
476
+ This way, you tell Devise to use the scope `:user` when "/sign_in" is accessed. Notice `devise_scope` is also aliased as `as` in your router.
477
+
478
+ Please note: You will still need to add `devise_for` in your routes in order to use helper methods such as `current_user`.
479
+
480
+ ```ruby
481
+ devise_for :users, skip: :all
482
+ ```
483
+
484
+ ### Hotwire/Turbo
485
+
486
+ 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:
487
+
488
+ ```ruby
489
+ Devise.setup do |config|
490
+ # ...
491
+ # When using Devise with Hotwire/Turbo, the http status for error responses
492
+ # and some redirects must match the following. The default in Devise for existing
493
+ # apps is `200 OK` and `302 Found` respectively, but new apps are generated with
494
+ # these new defaults that match Hotwire/Turbo behavior.
495
+ # Note: These might become the new default in future versions of Devise.
496
+ config.responder.error_status = :unprocessable_content # for Rack 3.1 or higher
497
+ # config.responder.error_status = :unprocessable_entity # for Rack 3.0 or lower
498
+ config.responder.redirect_status = :see_other
499
+ end
500
+ ```
501
+
502
+ **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.
503
+
504
+ _Note_: the above statuses configuration may become the default for Devise in a future release.
505
+
506
+ 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:
507
+
508
+ * 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.
509
+ * 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.
510
+
511
+ 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.)
512
+
513
+ Make sure to inspect your views looking for those, and change appropriately.
514
+
515
+ ### I18n
516
+
517
+ 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:
518
+
519
+ ```yaml
520
+ en:
521
+ devise:
522
+ sessions:
523
+ signed_in: 'Signed in successfully.'
524
+ ```
525
+
526
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
527
+
528
+ ```yaml
529
+ en:
530
+ devise:
531
+ sessions:
532
+ user:
533
+ signed_in: 'Welcome user, you are signed in.'
534
+ admin:
535
+ signed_in: 'Hello admin!'
536
+ ```
537
+
538
+ The Devise mailer uses a similar pattern to create subject messages:
539
+
540
+ ```yaml
541
+ en:
542
+ devise:
543
+ mailer:
544
+ confirmation_instructions:
545
+ subject: 'Hello everybody!'
546
+ user_subject: 'Hello User! Please confirm your email'
547
+ reset_password_instructions:
548
+ subject: 'Reset instructions'
549
+ ```
550
+
551
+ 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:
552
+
553
+ https://github.com/heartcombo/devise/wiki/I18n
554
+
555
+ Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
556
+
557
+ ### Test helpers
558
+
559
+ Devise includes some test helpers for controller and integration tests.
560
+ In order to use them, you need to include the respective module in your test
561
+ cases/specs.
562
+
563
+ ### Controller tests
564
+
565
+ Controller tests require that you include `Devise::Test::IntegrationHelpers` on
566
+ your test case or its parent `ActionController::TestCase` superclass.
567
+ For Rails versions prior to 5, include `Devise::Test::ControllerHelpers` instead, since the superclass
568
+ for controller tests was changed to ActionDispatch::IntegrationTest
569
+ (for more details, see the [Integration tests](#integration-tests) section).
570
+
571
+ ```ruby
572
+ class PostsControllerTest < ActionController::TestCase
573
+ include Devise::Test::IntegrationHelpers # Rails >= 5
574
+ end
575
+ ```
576
+
577
+ ```ruby
578
+ class PostsControllerTest < ActionController::TestCase
579
+ include Devise::Test::ControllerHelpers # Rails < 5
580
+ end
581
+ ```
582
+
583
+ If you're using RSpec, you can put the following inside a file named
584
+ `spec/support/devise.rb` or in your `spec/spec_helper.rb` (or
585
+ `spec/rails_helper.rb` if you are using `rspec-rails`):
586
+
587
+ ```ruby
588
+ RSpec.configure do |config|
589
+ config.include Devise::Test::ControllerHelpers, type: :controller
590
+ config.include Devise::Test::ControllerHelpers, type: :view
591
+ end
592
+ ```
593
+
594
+ Just be sure that this inclusion is made *after* the `require 'rspec/rails'` directive.
595
+
596
+ Now you are ready to use the `sign_in` and `sign_out` methods on your controller
597
+ tests:
598
+
599
+ ```ruby
600
+ sign_in @user
601
+ sign_in @user, scope: :admin
602
+ ```
603
+
604
+ If you are testing Devise internal controllers or a controller that inherits
605
+ from Devise's, you need to tell Devise which mapping should be used before a
606
+ request. This is necessary because Devise gets this information from the router,
607
+ but since controller tests do not pass through the router, it needs to be stated
608
+ explicitly. For example, if you are testing the user scope, simply use:
609
+
610
+ ```ruby
611
+ test 'GET new' do
612
+ # Mimic the router behavior of setting the Devise scope through the env.
613
+ @request.env['devise.mapping'] = Devise.mappings[:user]
614
+
615
+ # Use the sign_in helper to sign in a fixture `User` record.
616
+ sign_in users(:alice)
617
+
618
+ get :new
619
+
620
+ # assert something
621
+ end
622
+ ```
623
+
624
+ ### Integration tests
625
+
626
+ Integration test helpers are available by including the
627
+ `Devise::Test::IntegrationHelpers` module.
628
+
629
+ ```ruby
630
+ class PostsTests < ActionDispatch::IntegrationTest
631
+ include Devise::Test::IntegrationHelpers
632
+ end
633
+ ```
634
+
635
+ Now you can use the following `sign_in` and `sign_out` methods in your integration
636
+ tests:
637
+
638
+ ```ruby
639
+ sign_in users(:bob)
640
+ sign_in users(:bob), scope: :admin
641
+
642
+ sign_out :user
643
+ ```
644
+
645
+ RSpec users can include the `IntegrationHelpers` module on their `:feature` specs.
646
+
647
+ ```ruby
648
+ RSpec.configure do |config|
649
+ config.include Devise::Test::IntegrationHelpers, type: :feature
650
+ end
651
+ ```
652
+
653
+ Unlike controller tests, integration tests do not need to supply the
654
+ `devise.mapping` `env` value, as the mapping can be inferred by the routes that
655
+ are executed in your tests.
656
+
657
+ You can read more about testing your Rails controllers with RSpec in the wiki:
658
+
659
+ * https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
660
+
661
+ ### OmniAuth
662
+
663
+ Devise comes with OmniAuth support out of the box to authenticate with other providers. To use it, simply specify your OmniAuth configuration in `config/initializers/devise.rb`:
664
+
665
+ ```ruby
666
+ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
667
+ ```
668
+
669
+ You can read more about OmniAuth support in the wiki:
670
+
671
+ * https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
672
+
673
+ ### Configuring multiple models
674
+
675
+ Devise allows you to set up as many Devise models as you want. If you want to have an Admin model with just authentication and timeout features, in addition to the User model above, just run:
676
+
677
+ ```ruby
678
+ # Create a migration with the required fields
679
+ create_table :admins do |t|
680
+ t.string :email
681
+ t.string :encrypted_password
682
+ t.timestamps null: false
683
+ end
684
+
685
+ # Inside your Admin model
686
+ devise :database_authenticatable, :timeoutable
687
+
688
+ # Inside your routes
689
+ devise_for :admins
690
+
691
+ # Inside your protected controller
692
+ before_action :authenticate_admin!
693
+
694
+ # Inside your controllers and views
695
+ admin_signed_in?
696
+ current_admin
697
+ admin_session
698
+ ```
699
+
700
+ Alternatively, you can simply run the Devise generator.
701
+
702
+ Keep in mind that those models will have completely different routes. They **do not** and **cannot** share the same controller for sign in, sign out and so on. In case you want to have different roles sharing the same actions, we recommend that you use a role-based approach, by either providing a role column or using a dedicated gem for authorization.
703
+
704
+ ### Active Job Integration
705
+
706
+ If you are using Active Job to deliver Action Mailer messages in the
707
+ background through a queuing back-end, you can send Devise emails through your
708
+ existing queue by overriding the `send_devise_notification` method in your model.
709
+
710
+ ```ruby
711
+ def send_devise_notification(notification, *args)
712
+ devise_mailer.send(notification, self, *args).deliver_later
713
+ end
714
+ ```
715
+
716
+ ### Password reset tokens and Rails logs
717
+
718
+ If you enable the [Recoverable](https://www.rubydoc.info/gems/devise/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:
719
+
720
+ 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.
721
+ 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.
722
+
723
+ 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`:
724
+
725
+ ```ruby
726
+ config.log_level = :warn
727
+ ```
728
+
729
+
730
+ ### Other ORMs
731
+
732
+ Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.
733
+
734
+ ### Rails API Mode
735
+
736
+ 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/))
737
+
738
+ #### Supported Authentication Strategies
739
+ 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))
740
+
741
+ The devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:
742
+
743
+ ```ruby
744
+ config.http_authenticatable = [:database]
745
+ ```
746
+
747
+ This restriction does not limit you from implementing custom warden strategies, either in your application or via gem-based extensions for devise.
748
+ 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](https://blog.plataformatec.com.br/2019/01/custom-authentication-methods-with-devise/).
749
+
750
+ #### Testing
751
+ 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:
752
+
753
+ ```ruby
754
+ Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
755
+ Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
756
+ ```
757
+
758
+ For a deeper understanding of this, review [this issue](https://github.com/heartcombo/devise/issues/4696).
759
+
760
+ Additionally be mindful that without views supported, some email-based flows from Confirmable, Recoverable and Lockable are not supported directly at this time.
761
+
762
+ ## Additional information
763
+
764
+ ### Warden
765
+
766
+ 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:
767
+
768
+ https://github.com/wardencommunity/warden
769
+
770
+ ## License
771
+
772
+ MIT License.
773
+ Copyright 2020-CURRENT Rafael França, Carlos Antonio da Silva.
774
+ Copyright 2009-2019 Plataformatec.
775
+
776
+ The Devise logo is licensed under [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License](https://creativecommons.org/licenses/by-nc-nd/4.0/).