devise 4.3.0 → 4.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +205 -2
- data/MIT-LICENSE +2 -1
- data/README.md +214 -57
- data/app/controllers/devise/confirmations_controller.rb +3 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +3 -1
- data/app/controllers/devise/passwords_controller.rb +5 -2
- data/app/controllers/devise/registrations_controller.rb +32 -12
- data/app/controllers/devise/sessions_controller.rb +4 -2
- data/app/controllers/devise/unlocks_controller.rb +3 -0
- data/app/controllers/devise_controller.rb +6 -3
- data/app/helpers/devise_helper.rb +23 -18
- data/app/mailers/devise/mailer.rb +7 -5
- data/app/views/devise/confirmations/new.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +3 -3
- data/app/views/devise/passwords/new.html.erb +2 -2
- data/app/views/devise/registrations/edit.html.erb +6 -6
- data/app/views/devise/registrations/new.html.erb +4 -4
- data/app/views/devise/sessions/new.html.erb +4 -4
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/_links.html.erb +8 -8
- data/app/views/devise/unlocks/new.html.erb +2 -2
- data/config/locales/en.yml +3 -2
- data/lib/devise/controllers/helpers.rb +10 -8
- data/lib/devise/controllers/rememberable.rb +2 -0
- data/lib/devise/controllers/responder.rb +35 -0
- data/lib/devise/controllers/scoped_views.rb +2 -0
- data/lib/devise/controllers/sign_in_out.rb +14 -4
- data/lib/devise/controllers/store_location.rb +24 -6
- data/lib/devise/controllers/url_helpers.rb +3 -1
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +2 -0
- data/lib/devise/failure_app.rb +33 -7
- data/lib/devise/hooks/activatable.rb +2 -0
- data/lib/devise/hooks/csrf_cleaner.rb +8 -1
- data/lib/devise/hooks/forgetable.rb +2 -0
- data/lib/devise/hooks/lockable.rb +4 -5
- data/lib/devise/hooks/proxy.rb +2 -0
- data/lib/devise/hooks/rememberable.rb +2 -0
- data/lib/devise/hooks/timeoutable.rb +4 -2
- data/lib/devise/hooks/trackable.rb +2 -0
- data/lib/devise/mailers/helpers.rb +2 -0
- data/lib/devise/mapping.rb +3 -1
- data/lib/devise/models/authenticatable.rb +55 -50
- data/lib/devise/models/confirmable.rb +36 -40
- data/lib/devise/models/database_authenticatable.rb +57 -36
- data/lib/devise/models/lockable.rb +18 -4
- data/lib/devise/models/omniauthable.rb +4 -2
- data/lib/devise/models/recoverable.rb +10 -19
- data/lib/devise/models/registerable.rb +4 -0
- data/lib/devise/models/rememberable.rb +5 -3
- data/lib/devise/models/timeoutable.rb +3 -1
- data/lib/devise/models/trackable.rb +15 -1
- data/lib/devise/models/validatable.rb +7 -10
- data/lib/devise/models.rb +3 -0
- data/lib/devise/modules.rb +2 -0
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +2 -0
- data/lib/devise/omniauth.rb +4 -5
- data/lib/devise/orm/active_record.rb +2 -0
- data/lib/devise/orm/mongoid.rb +2 -0
- data/lib/devise/orm.rb +71 -0
- data/lib/devise/parameter_filter.rb +4 -0
- data/lib/devise/parameter_sanitizer.rb +15 -1
- data/lib/devise/rails/deprecated_constant_accessor.rb +39 -0
- data/lib/devise/rails/routes.rb +8 -6
- data/lib/devise/rails/warden_compat.rb +2 -0
- data/lib/devise/rails.rb +3 -5
- data/lib/devise/secret_key_finder.rb +27 -0
- data/lib/devise/strategies/authenticatable.rb +3 -1
- data/lib/devise/strategies/base.rb +2 -0
- data/lib/devise/strategies/database_authenticatable.rb +8 -1
- data/lib/devise/strategies/rememberable.rb +2 -0
- data/lib/devise/test/controller_helpers.rb +6 -1
- data/lib/devise/test/integration_helpers.rb +3 -1
- data/lib/devise/test_helpers.rb +2 -0
- data/lib/devise/time_inflector.rb +2 -0
- data/lib/devise/token_generator.rb +2 -0
- data/lib/devise/version.rb +3 -1
- data/lib/devise.rb +38 -12
- data/lib/generators/active_record/devise_generator.rb +40 -12
- data/lib/generators/active_record/templates/migration.rb +3 -1
- data/lib/generators/active_record/templates/migration_existing.rb +2 -0
- data/lib/generators/devise/controllers_generator.rb +3 -1
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +3 -5
- data/lib/generators/devise/orm_helpers.rb +9 -3
- data/lib/generators/devise/views_generator.rb +8 -9
- data/lib/generators/mongoid/devise_generator.rb +7 -5
- data/lib/generators/templates/README +9 -1
- data/lib/generators/templates/controllers/confirmations_controller.rb +2 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +3 -1
- data/lib/generators/templates/controllers/passwords_controller.rb +2 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +2 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +2 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +2 -0
- data/lib/generators/templates/devise.rb +43 -7
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +5 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +10 -2
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +4 -1
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +12 -4
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +7 -2
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
- metadata +24 -307
- data/.gitignore +0 -10
- data/.travis.yml +0 -58
- data/.yardopts +0 -9
- data/CODE_OF_CONDUCT.md +0 -22
- data/CONTRIBUTING.md +0 -79
- data/Gemfile +0 -40
- data/Gemfile.lock +0 -194
- data/Rakefile +0 -36
- data/bin/test +0 -13
- data/devise.gemspec +0 -26
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-4.1-stable +0 -30
- data/gemfiles/Gemfile.rails-4.1-stable.lock +0 -171
- data/gemfiles/Gemfile.rails-4.2-stable +0 -30
- data/gemfiles/Gemfile.rails-4.2-stable.lock +0 -192
- data/gemfiles/Gemfile.rails-5.0-stable +0 -34
- data/gemfiles/Gemfile.rails-5.0-stable.lock +0 -193
- data/guides/bug_report_templates/integration_test.rb +0 -104
- data/test/controllers/custom_registrations_controller_test.rb +0 -40
- data/test/controllers/custom_strategy_test.rb +0 -64
- data/test/controllers/helper_methods_test.rb +0 -22
- data/test/controllers/helpers_test.rb +0 -316
- data/test/controllers/inherited_controller_i18n_messages_test.rb +0 -51
- data/test/controllers/internal_helpers_test.rb +0 -127
- data/test/controllers/load_hooks_controller_test.rb +0 -19
- data/test/controllers/passwords_controller_test.rb +0 -32
- data/test/controllers/sessions_controller_test.rb +0 -106
- data/test/controllers/url_helpers_test.rb +0 -65
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -107
- data/test/failure_app_test.rb +0 -338
- data/test/generators/active_record_generator_test.rb +0 -83
- data/test/generators/controllers_generator_test.rb +0 -48
- data/test/generators/devise_generator_test.rb +0 -39
- data/test/generators/install_generator_test.rb +0 -24
- data/test/generators/mongoid_generator_test.rb +0 -23
- data/test/generators/views_generator_test.rb +0 -103
- data/test/helpers/devise_helper_test.rb +0 -49
- data/test/integration/authenticatable_test.rb +0 -698
- data/test/integration/confirmable_test.rb +0 -324
- data/test/integration/database_authenticatable_test.rb +0 -95
- data/test/integration/http_authenticatable_test.rb +0 -106
- data/test/integration/lockable_test.rb +0 -240
- data/test/integration/mounted_engine_test.rb +0 -36
- data/test/integration/omniauthable_test.rb +0 -135
- data/test/integration/recoverable_test.rb +0 -347
- data/test/integration/registerable_test.rb +0 -363
- data/test/integration/rememberable_test.rb +0 -217
- data/test/integration/timeoutable_test.rb +0 -184
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -115
- data/test/mailers/email_changed_test.rb +0 -130
- data/test/mailers/mailer_test.rb +0 -18
- data/test/mailers/reset_password_instructions_test.rb +0 -96
- data/test/mailers/unlock_instructions_test.rb +0 -91
- data/test/mapping_test.rb +0 -134
- data/test/models/authenticatable_test.rb +0 -23
- data/test/models/confirmable_test.rb +0 -536
- data/test/models/database_authenticatable_test.rb +0 -281
- data/test/models/lockable_test.rb +0 -350
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -261
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -182
- data/test/models/serializable_test.rb +0 -54
- data/test/models/timeoutable_test.rb +0 -51
- data/test/models/trackable_test.rb +0 -41
- data/test/models/validatable_test.rb +0 -119
- data/test/models_test.rb +0 -153
- data/test/omniauth/config_test.rb +0 -59
- data/test/omniauth/url_helpers_test.rb +0 -51
- data/test/orm/active_record.rb +0 -17
- data/test/orm/mongoid.rb +0 -13
- data/test/parameter_sanitizer_test.rb +0 -75
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -6
- data/test/rails_app/app/active_record/shim.rb +0 -2
- data/test/rails_app/app/active_record/user.rb +0 -7
- data/test/rails_app/app/active_record/user_on_engine.rb +0 -7
- data/test/rails_app/app/active_record/user_on_main_app.rb +0 -7
- data/test/rails_app/app/active_record/user_without_email.rb +0 -8
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -6
- data/test/rails_app/app/controllers/application_controller.rb +0 -11
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +0 -30
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +0 -31
- data/test/rails_app/app/controllers/home_controller.rb +0 -29
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
- data/test/rails_app/app/controllers/users_controller.rb +0 -31
- data/test/rails_app/app/helpers/application_helper.rb +0 -3
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +0 -3
- data/test/rails_app/app/mailers/users/mailer.rb +0 -3
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +0 -4
- data/test/rails_app/app/mongoid/admin.rb +0 -29
- data/test/rails_app/app/mongoid/shim.rb +0 -23
- data/test/rails_app/app/mongoid/user.rb +0 -39
- data/test/rails_app/app/mongoid/user_on_engine.rb +0 -39
- data/test/rails_app/app/mongoid/user_on_main_app.rb +0 -39
- data/test/rails_app/app/mongoid/user_without_email.rb +0 -33
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config/application.rb +0 -44
- data/test/rails_app/config/boot.rb +0 -20
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -30
- data/test/rails_app/config/environments/production.rb +0 -86
- data/test/rails_app/config/environments/test.rb +0 -45
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -180
- data/test/rails_app/config/initializers/inflections.rb +0 -2
- data/test/rails_app/config/initializers/secret_token.rb +0 -3
- data/test/rails_app/config/initializers/session_store.rb +0 -1
- data/test/rails_app/config/routes.rb +0 -126
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -75
- data/test/rails_app/db/schema.rb +0 -55
- data/test/rails_app/lib/shared_admin.rb +0 -21
- data/test/rails_app/lib/shared_user.rb +0 -30
- data/test/rails_app/lib/shared_user_without_email.rb +0 -26
- data/test/rails_app/lib/shared_user_without_omniauth.rb +0 -13
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_test.rb +0 -9
- data/test/routes_test.rb +0 -279
- data/test/support/action_controller/record_identifier.rb +0 -10
- data/test/support/assertions.rb +0 -28
- data/test/support/helpers.rb +0 -77
- data/test/support/http_method_compatibility.rb +0 -51
- data/test/support/integration.rb +0 -92
- data/test/support/locale/en.yml +0 -8
- data/test/support/mongoid.yml +0 -6
- data/test/support/webrat/integrations/rails.rb +0 -33
- data/test/test/controller_helpers_test.rb +0 -186
- data/test/test/integration_helpers_test.rb +0 -32
- data/test/test_helper.rb +0 -34
- data/test/test_models.rb +0 -33
data/README.md
CHANGED
@@ -1,11 +1,4 @@
|
|
1
|
-
![Devise Logo](https://raw.github.com/
|
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,55 @@ 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://rubydoc.info/github/
|
20
|
-
* [Omniauthable](http://rubydoc.info/github/
|
21
|
-
* [Confirmable](http://rubydoc.info/github/
|
22
|
-
* [Recoverable](http://rubydoc.info/github/
|
23
|
-
* [Registerable](http://rubydoc.info/github/
|
24
|
-
* [Rememberable](http://rubydoc.info/github/
|
25
|
-
* [Trackable](http://rubydoc.info/github/
|
26
|
-
* [Timeoutable](http://rubydoc.info/github/
|
27
|
-
* [Validatable](http://rubydoc.info/github/
|
28
|
-
* [Lockable](http://rubydoc.info/github/
|
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.
|
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
|
+
- [Contributing](#contributing)
|
35
|
+
- [Starting with Rails?](#starting-with-rails)
|
36
|
+
- [Getting started](#getting-started)
|
37
|
+
- [Controller filters and helpers](#controller-filters-and-helpers)
|
38
|
+
- [Configuring Models](#configuring-models)
|
39
|
+
- [Strong Parameters](#strong-parameters)
|
40
|
+
- [Configuring views](#configuring-views)
|
41
|
+
- [Configuring controllers](#configuring-controllers)
|
42
|
+
- [Configuring routes](#configuring-routes)
|
43
|
+
- [I18n](#i18n)
|
44
|
+
- [Test helpers](#test-helpers)
|
45
|
+
- [Controller tests](#controller-tests)
|
46
|
+
- [Integration tests](#integration-tests)
|
47
|
+
- [OmniAuth](#omniauth)
|
48
|
+
- [Configuring multiple models](#configuring-multiple-models)
|
49
|
+
- [ActiveJob Integration](#activejob-integration)
|
50
|
+
- [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs)
|
51
|
+
- [Other ORMs](#other-orms)
|
52
|
+
- [Rails API mode](#rails-api-mode)
|
53
|
+
- [Additional information](#additional-information)
|
54
|
+
- [Warden](#warden)
|
55
|
+
- [Contributors](#contributors)
|
56
|
+
- [License](#license)
|
57
|
+
|
58
|
+
<!-- /TOC -->
|
59
|
+
|
60
|
+
|
29
61
|
|
30
62
|
## Information
|
31
63
|
|
@@ -33,15 +65,15 @@ It's composed of 10 modules:
|
|
33
65
|
|
34
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:
|
35
67
|
|
36
|
-
https://github.com/
|
68
|
+
https://github.com/heartcombo/devise/wiki
|
37
69
|
|
38
70
|
### Bug reports
|
39
71
|
|
40
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:
|
41
73
|
|
42
|
-
https://github.com/
|
74
|
+
https://github.com/heartcombo/devise/wiki/Bug-reports
|
43
75
|
|
44
|
-
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to
|
76
|
+
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to heartcombo@googlegroups.com.
|
45
77
|
|
46
78
|
### StackOverflow and Mailing List
|
47
79
|
|
@@ -57,7 +89,7 @@ https://groups.google.com/group/plataformatec-devise
|
|
57
89
|
|
58
90
|
You can view the Devise documentation in RDoc format here:
|
59
91
|
|
60
|
-
http://rubydoc.info/github/
|
92
|
+
http://rubydoc.info/github/heartcombo/devise/main/frames
|
61
93
|
|
62
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.
|
63
95
|
|
@@ -65,35 +97,82 @@ If you need to use Devise with previous versions of Rails, you can always run "g
|
|
65
97
|
|
66
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:
|
67
99
|
|
68
|
-
https://github.com/
|
100
|
+
https://github.com/heartcombo/devise/wiki/Example-Applications
|
69
101
|
|
70
102
|
### Extensions
|
71
103
|
|
72
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:
|
73
105
|
|
74
|
-
https://github.com/
|
106
|
+
https://github.com/heartcombo/devise/wiki/Extensions
|
75
107
|
|
76
108
|
### Contributing
|
77
109
|
|
78
110
|
We hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:
|
79
111
|
|
80
|
-
https://github.com/
|
112
|
+
https://github.com/heartcombo/devise/wiki/Contributing
|
113
|
+
|
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`.
|
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`.
|
116
|
+
|
117
|
+
### DEVISE_ORM
|
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`:
|
120
|
+
```
|
121
|
+
DEVISE_ORM=mongoid bin/test
|
122
|
+
|
123
|
+
==> Devise.orm = :mongoid
|
124
|
+
```
|
125
|
+
When running the tests for Mongoid, you will need to have a MongoDB server (version 2.0 or newer) running on your system.
|
126
|
+
|
127
|
+
Please note that the command output will show the variable value being used.
|
128
|
+
|
129
|
+
### BUNDLE_GEMFILE
|
130
|
+
We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
|
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.
|
132
|
+
For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
|
133
|
+
```bash
|
134
|
+
rbenv shell 2.4.2 # or rvm use 2.4.2
|
135
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
|
136
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bin/test
|
137
|
+
```
|
138
|
+
|
139
|
+
You can also combine both of them if the tests broke for Mongoid:
|
140
|
+
```bash
|
141
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
|
142
|
+
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable DEVISE_ORM=mongoid bin/test
|
143
|
+
```
|
144
|
+
|
145
|
+
### Running tests
|
146
|
+
Devise uses [Mini Test](https://github.com/seattlerb/minitest) as test framework.
|
81
147
|
|
82
|
-
|
148
|
+
* Running all tests:
|
149
|
+
```bash
|
150
|
+
bin/test
|
151
|
+
```
|
152
|
+
|
153
|
+
* Running tests for an specific file:
|
154
|
+
```bash
|
155
|
+
bin/test test/models/trackable_test.rb
|
156
|
+
```
|
157
|
+
|
158
|
+
* Running a specific test given a regex:
|
159
|
+
```bash
|
160
|
+
bin/test test/models/trackable_test.rb:16
|
161
|
+
```
|
83
162
|
|
84
163
|
## Starting with Rails?
|
85
164
|
|
86
|
-
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.
|
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:
|
87
166
|
|
88
167
|
* Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users
|
89
|
-
* Ryan Bates'
|
90
|
-
* Codecademy's Ruby on Rails: Authentication and Authorization:
|
168
|
+
* Ryan Bates' Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/250-authentication-from-scratch-revised
|
169
|
+
* Codecademy's Ruby on Rails: Authentication and Authorization: https://www.codecademy.com/learn/rails-auth
|
91
170
|
|
92
171
|
Once you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:
|
93
172
|
|
94
173
|
## Getting started
|
95
174
|
|
96
|
-
Devise 4.0 works with Rails 4.1 onwards.
|
175
|
+
Devise 4.0 works with Rails 4.1 onwards. Add the following line to your Gemfile:
|
97
176
|
|
98
177
|
```ruby
|
99
178
|
gem 'devise'
|
@@ -122,11 +201,11 @@ In the following command you will replace `MODEL` with the class name used for t
|
|
122
201
|
$ rails generate devise MODEL
|
123
202
|
```
|
124
203
|
|
125
|
-
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.
|
204
|
+
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.
|
126
205
|
|
127
206
|
Then run `rails db:migrate`
|
128
207
|
|
129
|
-
You should restart your application after changing Devise's configuration options. Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.
|
208
|
+
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.
|
130
209
|
|
131
210
|
### Controller filters and helpers
|
132
211
|
|
@@ -183,16 +262,16 @@ member_session
|
|
183
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:
|
184
263
|
|
185
264
|
```ruby
|
186
|
-
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches:
|
265
|
+
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13
|
187
266
|
```
|
188
267
|
|
189
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`.
|
190
269
|
|
191
270
|
### Strong Parameters
|
192
271
|
|
193
|
-
|
272
|
+
The Parameter Sanitizer API has changed for Devise 4 :warning:
|
194
273
|
|
195
|
-
*For previous Devise versions see https://github.com/
|
274
|
+
*For previous Devise versions see https://github.com/heartcombo/devise/tree/3-stable#strong-parameters*
|
196
275
|
|
197
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.
|
198
277
|
|
@@ -202,7 +281,7 @@ There are just three actions in Devise that allow any set of parameters to be pa
|
|
202
281
|
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
|
203
282
|
* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
|
204
283
|
|
205
|
-
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before
|
284
|
+
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:
|
206
285
|
|
207
286
|
```ruby
|
208
287
|
class ApplicationController < ActionController::Base
|
@@ -216,7 +295,21 @@ class ApplicationController < ActionController::Base
|
|
216
295
|
end
|
217
296
|
```
|
218
297
|
|
219
|
-
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
|
298
|
+
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:
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
class ApplicationController < ActionController::Base
|
302
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
303
|
+
|
304
|
+
protected
|
305
|
+
|
306
|
+
def configure_permitted_parameters
|
307
|
+
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, address_attributes: [:country, :state, :city, :area, :postal_code]])
|
308
|
+
end
|
309
|
+
end
|
310
|
+
```
|
311
|
+
|
312
|
+
Devise allows you to completely change Devise defaults or invoke custom behavior by passing a block:
|
220
313
|
|
221
314
|
To permit simple scalar values for username and email, use this
|
222
315
|
|
@@ -289,7 +382,7 @@ $ rails generate devise:views users
|
|
289
382
|
```
|
290
383
|
|
291
384
|
If you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,
|
292
|
-
you can pass a list of
|
385
|
+
you can pass a list of views to the generator with the `-v` flag.
|
293
386
|
|
294
387
|
```console
|
295
388
|
$ rails generate devise:views -v registrations confirmations
|
@@ -317,6 +410,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
317
410
|
...
|
318
411
|
end
|
319
412
|
```
|
413
|
+
Use the `-c` flag to specify one or more controllers, for example: `rails generate devise:controllers users -c sessions`)
|
320
414
|
|
321
415
|
2. Tell the router to use this controller:
|
322
416
|
|
@@ -324,7 +418,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
324
418
|
devise_for :users, controllers: { sessions: 'users/sessions' }
|
325
419
|
```
|
326
420
|
|
327
|
-
3.
|
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.
|
328
422
|
|
329
423
|
4. Finally, change or extend the desired controller actions.
|
330
424
|
|
@@ -338,7 +432,7 @@ If the customization at the views level is not enough, you can customize each co
|
|
338
432
|
end
|
339
433
|
```
|
340
434
|
|
341
|
-
Or you can simply add new
|
435
|
+
Or you can simply add new behavior to it:
|
342
436
|
|
343
437
|
```ruby
|
344
438
|
class Users::SessionsController < Devise::SessionsController
|
@@ -362,7 +456,7 @@ Devise also ships with default routes. If you need to customize them, you should
|
|
362
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' }
|
363
457
|
```
|
364
458
|
|
365
|
-
Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/
|
459
|
+
Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/heartcombo/devise/main/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
|
366
460
|
|
367
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:
|
368
462
|
|
@@ -374,6 +468,42 @@ end
|
|
374
468
|
|
375
469
|
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.
|
376
470
|
|
471
|
+
Please note: You will still need to add `devise_for` in your routes in order to use helper methods such as `current_user`.
|
472
|
+
|
473
|
+
```ruby
|
474
|
+
devise_for :users, skip: :all
|
475
|
+
```
|
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
|
+
|
377
507
|
### I18n
|
378
508
|
|
379
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:
|
@@ -412,7 +542,7 @@ en:
|
|
412
542
|
|
413
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:
|
414
544
|
|
415
|
-
https://github.com/
|
545
|
+
https://github.com/heartcombo/devise/wiki/I18n
|
416
546
|
|
417
547
|
Caution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.
|
418
548
|
|
@@ -424,12 +554,21 @@ cases/specs.
|
|
424
554
|
|
425
555
|
### Controller tests
|
426
556
|
|
427
|
-
Controller tests require that you include `Devise::Test::
|
557
|
+
Controller tests require that you include `Devise::Test::IntegrationHelpers` on
|
428
558
|
your test case or its parent `ActionController::TestCase` superclass.
|
559
|
+
For Rails versions prior to 5, include `Devise::Test::ControllerHelpers` instead, since the superclass
|
560
|
+
for controller tests was changed to ActionDispatch::IntegrationTest
|
561
|
+
(for more details, see the [Integration tests](#integration-tests) section).
|
562
|
+
|
563
|
+
```ruby
|
564
|
+
class PostsControllerTest < ActionController::TestCase
|
565
|
+
include Devise::Test::IntegrationHelpers # Rails >= 5
|
566
|
+
end
|
567
|
+
```
|
429
568
|
|
430
569
|
```ruby
|
431
570
|
class PostsControllerTest < ActionController::TestCase
|
432
|
-
include Devise::Test::ControllerHelpers
|
571
|
+
include Devise::Test::ControllerHelpers # Rails < 5
|
433
572
|
end
|
434
573
|
```
|
435
574
|
|
@@ -509,7 +648,7 @@ are executed in your tests.
|
|
509
648
|
|
510
649
|
You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
|
511
650
|
|
512
|
-
* https://github.com/
|
651
|
+
* https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)
|
513
652
|
|
514
653
|
### OmniAuth
|
515
654
|
|
@@ -521,7 +660,7 @@ config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
|
521
660
|
|
522
661
|
You can read more about OmniAuth support in the wiki:
|
523
662
|
|
524
|
-
* https://github.com/
|
663
|
+
* https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview
|
525
664
|
|
526
665
|
### Configuring multiple models
|
527
666
|
|
@@ -568,12 +707,12 @@ end
|
|
568
707
|
|
569
708
|
### Password reset tokens and Rails logs
|
570
709
|
|
571
|
-
If you enable the [Recoverable](http://rubydoc.info/github/
|
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:
|
572
711
|
|
573
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.
|
574
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.
|
575
714
|
|
576
|
-
Rails sets the production logger level to
|
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`:
|
577
716
|
|
578
717
|
```ruby
|
579
718
|
config.log_level = :warn
|
@@ -584,32 +723,50 @@ config.log_level = :warn
|
|
584
723
|
|
585
724
|
Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.
|
586
725
|
|
587
|
-
|
726
|
+
### Rails API Mode
|
727
|
+
|
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/))
|
588
729
|
|
589
|
-
|
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))
|
590
732
|
|
591
|
-
|
733
|
+
The devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:
|
592
734
|
|
593
735
|
```ruby
|
594
|
-
config.
|
736
|
+
config.http_authenticatable = [:database]
|
595
737
|
```
|
596
738
|
|
597
|
-
|
739
|
+
This restriction does not limit you from implementing custom warden strategies, either in your application or via gem-based extensions for devise.
|
740
|
+
A common authentication strategy for APIs is token-based authentication. For more information on extending devise to support this type of authentication and others, see the wiki article for [Simple Token Authentication Examples and alternatives](https://github.com/heartcombo/devise/wiki/How-To:-Simple-Token-Authentication-Example#alternatives) or this blog post on [Custom authentication methods with Devise](http://blog.plataformatec.com.br/2019/01/custom-authentication-methods-with-devise/).
|
741
|
+
|
742
|
+
#### Testing
|
743
|
+
API Mode changes the order of the middleware stack, and this can cause problems for `Devise::Test::IntegrationHelpers`. This problem usually surfaces as an ```undefined method `[]=' for nil:NilClass``` error when using integration test helpers, such as `#sign_in`. The solution is simply to reorder the middlewares by adding the following to test.rb:
|
744
|
+
|
745
|
+
```ruby
|
746
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies
|
747
|
+
Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore
|
748
|
+
```
|
749
|
+
|
750
|
+
For a deeper understanding of this, review [this issue](https://github.com/heartcombo/devise/issues/4696).
|
751
|
+
|
752
|
+
Additionally be mindful that without views supported, some email-based flows from Confirmable, Recoverable and Lockable are not supported directly at this time.
|
753
|
+
|
754
|
+
## Additional information
|
598
755
|
|
599
756
|
### Warden
|
600
757
|
|
601
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:
|
602
759
|
|
603
|
-
https://github.com/
|
760
|
+
https://github.com/wardencommunity/warden
|
604
761
|
|
605
762
|
### Contributors
|
606
763
|
|
607
764
|
We have a long list of valued contributors. Check them all at:
|
608
765
|
|
609
|
-
https://github.com/
|
766
|
+
https://github.com/heartcombo/devise/graphs/contributors
|
610
767
|
|
611
768
|
## License
|
612
769
|
|
613
|
-
MIT License. Copyright 2009-
|
770
|
+
MIT License. Copyright 2020-2023 Rafael França, Leonardo Tegon, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
|
614
771
|
|
615
|
-
|
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/).
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::ConfirmationsController < DeviseController
|
2
4
|
# GET /resource/confirmation/new
|
3
5
|
def new
|
@@ -25,6 +27,7 @@ class Devise::ConfirmationsController < DeviseController
|
|
25
27
|
set_flash_message!(:notice, :confirmed)
|
26
28
|
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
27
29
|
else
|
30
|
+
# TODO: use `error_status` when the default changes to `:unprocessable_entity`.
|
28
31
|
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
29
32
|
end
|
30
33
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::OmniauthCallbacksController < DeviseController
|
2
4
|
prepend_before_action { request.env["devise.skip_timeout"] = true }
|
3
5
|
|
@@ -6,7 +8,7 @@ class Devise::OmniauthCallbacksController < DeviseController
|
|
6
8
|
end
|
7
9
|
|
8
10
|
def failure
|
9
|
-
set_flash_message :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
|
11
|
+
set_flash_message! :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
|
10
12
|
redirect_to after_omniauth_failure_path_for(resource_name)
|
11
13
|
end
|
12
14
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::PasswordsController < DeviseController
|
2
4
|
prepend_before_action :require_no_authentication
|
3
5
|
# Render the #edit only if coming from a reset password email link
|
@@ -34,9 +36,10 @@ class Devise::PasswordsController < DeviseController
|
|
34
36
|
|
35
37
|
if resource.errors.empty?
|
36
38
|
resource.unlock_access! if unlockable?(resource)
|
37
|
-
if
|
39
|
+
if resource_class.sign_in_after_reset_password
|
38
40
|
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
39
41
|
set_flash_message!(:notice, flash_message)
|
42
|
+
resource.after_database_authentication
|
40
43
|
sign_in(resource_name, resource)
|
41
44
|
else
|
42
45
|
set_flash_message!(:notice, :updated_not_active)
|
@@ -50,7 +53,7 @@ class Devise::PasswordsController < DeviseController
|
|
50
53
|
|
51
54
|
protected
|
52
55
|
def after_resetting_password_path_for(resource)
|
53
|
-
|
56
|
+
resource_class.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
|
54
57
|
end
|
55
58
|
|
56
59
|
# The path used after sending reset password instructions
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::RegistrationsController < DeviseController
|
2
4
|
prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
|
3
5
|
prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
|
@@ -5,7 +7,7 @@ class Devise::RegistrationsController < DeviseController
|
|
5
7
|
|
6
8
|
# GET /resource/sign_up
|
7
9
|
def new
|
8
|
-
build_resource
|
10
|
+
build_resource
|
9
11
|
yield resource if block_given?
|
10
12
|
respond_with resource
|
11
13
|
end
|
@@ -48,12 +50,9 @@ class Devise::RegistrationsController < DeviseController
|
|
48
50
|
resource_updated = update_resource(resource, account_update_params)
|
49
51
|
yield resource if block_given?
|
50
52
|
if resource_updated
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
set_flash_message :notice, flash_key
|
55
|
-
end
|
56
|
-
bypass_sign_in resource, scope: resource_name
|
53
|
+
set_flash_message_for_update(resource, prev_unconfirmed_email)
|
54
|
+
bypass_sign_in resource, scope: resource_name if sign_in_after_change_password?
|
55
|
+
|
57
56
|
respond_with resource, location: after_update_path_for(resource)
|
58
57
|
else
|
59
58
|
clean_up_passwords resource
|
@@ -68,7 +67,7 @@ class Devise::RegistrationsController < DeviseController
|
|
68
67
|
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
69
68
|
set_flash_message! :notice, :destroyed
|
70
69
|
yield resource if block_given?
|
71
|
-
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 }
|
72
71
|
end
|
73
72
|
|
74
73
|
# GET /resource/cancel
|
@@ -97,8 +96,8 @@ class Devise::RegistrationsController < DeviseController
|
|
97
96
|
|
98
97
|
# Build a devise resource passing in the session. Useful to move
|
99
98
|
# temporary session data to the newly created user.
|
100
|
-
def build_resource(hash=
|
101
|
-
self.resource = resource_class.new_with_session(hash
|
99
|
+
def build_resource(hash = {})
|
100
|
+
self.resource = resource_class.new_with_session(hash, session)
|
102
101
|
end
|
103
102
|
|
104
103
|
# Signs in a user on sign up. You can overwrite this method in your own
|
@@ -110,7 +109,7 @@ class Devise::RegistrationsController < DeviseController
|
|
110
109
|
# The path used after sign up. You need to overwrite this method
|
111
110
|
# in your own RegistrationsController.
|
112
111
|
def after_sign_up_path_for(resource)
|
113
|
-
after_sign_in_path_for(resource)
|
112
|
+
after_sign_in_path_for(resource) if is_navigational_format?
|
114
113
|
end
|
115
114
|
|
116
115
|
# The path used after sign up for inactive accounts. You need to overwrite
|
@@ -125,7 +124,7 @@ class Devise::RegistrationsController < DeviseController
|
|
125
124
|
# The default url to be used after updating a resource. You need to overwrite
|
126
125
|
# this method in your own RegistrationsController.
|
127
126
|
def after_update_path_for(resource)
|
128
|
-
signed_in_root_path(resource)
|
127
|
+
sign_in_after_change_password? ? signed_in_root_path(resource) : new_session_path(resource_name)
|
129
128
|
end
|
130
129
|
|
131
130
|
# Authenticates the current scope and gets the current resource from the session.
|
@@ -145,4 +144,25 @@ class Devise::RegistrationsController < DeviseController
|
|
145
144
|
def translation_scope
|
146
145
|
'devise.registrations'
|
147
146
|
end
|
147
|
+
|
148
|
+
private
|
149
|
+
|
150
|
+
def set_flash_message_for_update(resource, prev_unconfirmed_email)
|
151
|
+
return unless is_flashing_format?
|
152
|
+
|
153
|
+
flash_key = if update_needs_confirmation?(resource, prev_unconfirmed_email)
|
154
|
+
:update_needs_confirmation
|
155
|
+
elsif sign_in_after_change_password?
|
156
|
+
:updated
|
157
|
+
else
|
158
|
+
:updated_but_not_signed_in
|
159
|
+
end
|
160
|
+
set_flash_message :notice, flash_key
|
161
|
+
end
|
162
|
+
|
163
|
+
def sign_in_after_change_password?
|
164
|
+
return true if account_update_params[:password].blank?
|
165
|
+
|
166
|
+
Devise.sign_in_after_change_password
|
167
|
+
end
|
148
168
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::SessionsController < DeviseController
|
2
4
|
prepend_before_action :require_no_authentication, only: [:new, :create]
|
3
5
|
prepend_before_action :allow_params_authentication!, only: :create
|
4
6
|
prepend_before_action :verify_signed_out_user, only: :destroy
|
5
|
-
prepend_before_action
|
7
|
+
prepend_before_action(only: [:create, :destroy]) { request.env["devise.skip_timeout"] = true }
|
6
8
|
|
7
9
|
# GET /resource/sign_in
|
8
10
|
def new
|
@@ -75,7 +77,7 @@ class Devise::SessionsController < DeviseController
|
|
75
77
|
# support returning empty response on GET request
|
76
78
|
respond_to do |format|
|
77
79
|
format.all { head :no_content }
|
78
|
-
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 }
|
79
81
|
end
|
80
82
|
end
|
81
83
|
end
|