devise 3.2.4 → 4.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +259 -994
- data/MIT-LICENSE +1 -1
- data/README.md +336 -99
- data/app/controllers/devise/confirmations_controller.rb +9 -3
- data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
- data/app/controllers/devise/passwords_controller.rb +19 -6
- data/app/controllers/devise/registrations_controller.rb +55 -22
- data/app/controllers/devise/sessions_controller.rb +44 -14
- data/app/controllers/devise/unlocks_controller.rb +7 -2
- data/app/controllers/devise_controller.rb +65 -29
- data/app/helpers/devise_helper.rb +12 -19
- data/app/mailers/devise/mailer.rb +10 -0
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/passwords/edit.html.erb +15 -6
- data/app/views/devise/passwords/new.html.erb +8 -4
- data/app/views/devise/registrations/edit.html.erb +27 -13
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +18 -9
- data/app/views/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +9 -9
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +22 -16
- data/lib/devise/controllers/helpers.rb +109 -29
- data/lib/devise/controllers/rememberable.rb +12 -3
- data/lib/devise/controllers/scoped_views.rb +2 -0
- data/lib/devise/controllers/sign_in_out.rb +36 -20
- data/lib/devise/controllers/store_location.rb +31 -5
- data/lib/devise/controllers/url_helpers.rb +9 -7
- data/lib/devise/delegator.rb +2 -0
- data/lib/devise/encryptor.rb +24 -0
- data/lib/devise/failure_app.rb +116 -36
- data/lib/devise/hooks/activatable.rb +5 -4
- data/lib/devise/hooks/csrf_cleaner.rb +5 -1
- data/lib/devise/hooks/forgetable.rb +2 -0
- data/lib/devise/hooks/lockable.rb +6 -1
- data/lib/devise/hooks/proxy.rb +3 -1
- data/lib/devise/hooks/rememberable.rb +2 -0
- data/lib/devise/hooks/timeoutable.rb +15 -8
- data/lib/devise/hooks/trackable.rb +2 -0
- data/lib/devise/mailers/helpers.rb +7 -4
- data/lib/devise/mapping.rb +8 -2
- data/lib/devise/models/authenticatable.rb +76 -51
- data/lib/devise/models/confirmable.rb +129 -34
- data/lib/devise/models/database_authenticatable.rb +107 -30
- data/lib/devise/models/lockable.rb +19 -9
- data/lib/devise/models/omniauthable.rb +2 -0
- data/lib/devise/models/recoverable.rb +62 -26
- data/lib/devise/models/registerable.rb +4 -0
- data/lib/devise/models/rememberable.rb +58 -29
- data/lib/devise/models/timeoutable.rb +2 -6
- data/lib/devise/models/trackable.rb +20 -4
- data/lib/devise/models/validatable.rb +12 -5
- data/lib/devise/models.rb +3 -1
- data/lib/devise/modules.rb +2 -0
- data/lib/devise/omniauth/config.rb +2 -0
- data/lib/devise/omniauth/url_helpers.rb +14 -5
- data/lib/devise/omniauth.rb +2 -0
- data/lib/devise/orm/active_record.rb +5 -1
- data/lib/devise/orm/mongoid.rb +6 -2
- data/lib/devise/parameter_filter.rb +4 -0
- data/lib/devise/parameter_sanitizer.rb +139 -65
- data/lib/devise/rails/routes.rb +80 -61
- data/lib/devise/rails/warden_compat.rb +3 -10
- data/lib/devise/rails.rb +8 -17
- data/lib/devise/secret_key_finder.rb +27 -0
- data/lib/devise/strategies/authenticatable.rb +18 -7
- data/lib/devise/strategies/base.rb +2 -0
- data/lib/devise/strategies/database_authenticatable.rb +13 -5
- data/lib/devise/strategies/rememberable.rb +15 -3
- data/lib/devise/test/controller_helpers.rb +165 -0
- data/lib/devise/test/integration_helpers.rb +63 -0
- data/lib/devise/test_helpers.rb +7 -124
- data/lib/devise/time_inflector.rb +2 -0
- data/lib/devise/token_generator.rb +3 -41
- data/lib/devise/version.rb +3 -1
- data/lib/devise.rb +106 -79
- data/lib/generators/active_record/devise_generator.rb +44 -7
- data/lib/generators/active_record/templates/migration.rb +5 -3
- data/lib/generators/active_record/templates/migration_existing.rb +5 -3
- data/lib/generators/devise/controllers_generator.rb +46 -0
- data/lib/generators/devise/devise_generator.rb +4 -2
- data/lib/generators/devise/install_generator.rb +17 -0
- data/lib/generators/devise/orm_helpers.rb +10 -21
- data/lib/generators/devise/views_generator.rb +21 -11
- data/lib/generators/mongoid/devise_generator.rb +7 -5
- data/lib/generators/templates/README +2 -9
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
- data/lib/generators/templates/devise.rb +69 -30
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/email_changed.markerb +7 -0
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
- 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 +11 -3
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +11 -3
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +9 -4
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +4 -1
- metadata +31 -259
- data/.gitignore +0 -11
- data/.travis.yml +0 -28
- data/.yardopts +0 -9
- data/CONTRIBUTING.md +0 -14
- data/Gemfile +0 -29
- data/Gemfile.lock +0 -160
- data/Rakefile +0 -35
- data/devise.gemspec +0 -27
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +0 -29
- data/gemfiles/Gemfile.rails-4.0-stable +0 -29
- data/gemfiles/Gemfile.rails-head +0 -29
- data/test/controllers/custom_strategy_test.rb +0 -62
- data/test/controllers/helpers_test.rb +0 -276
- data/test/controllers/internal_helpers_test.rb +0 -123
- data/test/controllers/passwords_controller_test.rb +0 -31
- data/test/controllers/sessions_controller_test.rb +0 -103
- data/test/controllers/url_helpers_test.rb +0 -59
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -94
- data/test/failure_app_test.rb +0 -232
- data/test/generators/active_record_generator_test.rb +0 -103
- data/test/generators/devise_generator_test.rb +0 -39
- data/test/generators/install_generator_test.rb +0 -13
- data/test/generators/mongoid_generator_test.rb +0 -23
- data/test/generators/views_generator_test.rb +0 -96
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -713
- data/test/integration/confirmable_test.rb +0 -284
- data/test/integration/database_authenticatable_test.rb +0 -84
- data/test/integration/http_authenticatable_test.rb +0 -105
- data/test/integration/lockable_test.rb +0 -239
- data/test/integration/omniauthable_test.rb +0 -133
- data/test/integration/recoverable_test.rb +0 -334
- data/test/integration/registerable_test.rb +0 -349
- data/test/integration/rememberable_test.rb +0 -167
- data/test/integration/timeoutable_test.rb +0 -183
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -115
- 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 -127
- data/test/models/authenticatable_test.rb +0 -13
- data/test/models/confirmable_test.rb +0 -454
- data/test/models/database_authenticatable_test.rb +0 -249
- data/test/models/lockable_test.rb +0 -316
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -184
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -183
- data/test/models/serializable_test.rb +0 -49
- data/test/models/timeoutable_test.rb +0 -51
- data/test/models/trackable_test.rb +0 -13
- data/test/models/validatable_test.rb +0 -127
- data/test/models_test.rb +0 -144
- data/test/omniauth/config_test.rb +0 -57
- data/test/omniauth/url_helpers_test.rb +0 -54
- data/test/orm/active_record.rb +0 -10
- data/test/orm/mongoid.rb +0 -13
- data/test/parameter_sanitizer_test.rb +0 -81
- 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 -6
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -11
- data/test/rails_app/app/controllers/application_controller.rb +0 -9
- data/test/rails_app/app/controllers/home_controller.rb +0 -25
- 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/mailer.rb +0 -12
- 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/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 -40
- data/test/rails_app/config/boot.rb +0 -14
- 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 -80
- data/test/rails_app/config/environments/test.rb +0 -36
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -181
- data/test/rails_app/config/initializers/inflections.rb +0 -2
- data/test/rails_app/config/initializers/secret_token.rb +0 -8
- data/test/rails_app/config/initializers/session_store.rb +0 -1
- data/test/rails_app/config/routes.rb +0 -105
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
- data/test/rails_app/db/schema.rb +0 -55
- data/test/rails_app/lib/shared_admin.rb +0 -17
- data/test/rails_app/lib/shared_user.rb +0 -29
- 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/routes_test.rb +0 -262
- data/test/support/action_controller/record_identifier.rb +0 -10
- data/test/support/assertions.rb +0 -40
- data/test/support/helpers.rb +0 -70
- 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 -24
- data/test/test_helper.rb +0 -27
- data/test/test_helpers_test.rb +0 -173
- data/test/test_models.rb +0 -33
@@ -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
|
@@ -22,7 +24,7 @@ class Devise::ConfirmationsController < DeviseController
|
|
22
24
|
yield resource if block_given?
|
23
25
|
|
24
26
|
if resource.errors.empty?
|
25
|
-
set_flash_message(:notice, :confirmed)
|
27
|
+
set_flash_message!(:notice, :confirmed)
|
26
28
|
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
27
29
|
else
|
28
30
|
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
@@ -33,15 +35,19 @@ class Devise::ConfirmationsController < DeviseController
|
|
33
35
|
|
34
36
|
# The path used after resending confirmation instructions.
|
35
37
|
def after_resending_confirmation_instructions_path_for(resource_name)
|
36
|
-
new_session_path(resource_name)
|
38
|
+
is_navigational_format? ? new_session_path(resource_name) : '/'
|
37
39
|
end
|
38
40
|
|
39
41
|
# The path used after confirmation.
|
40
42
|
def after_confirmation_path_for(resource_name, resource)
|
41
|
-
if signed_in?
|
43
|
+
if signed_in?(resource_name)
|
42
44
|
signed_in_root_path(resource)
|
43
45
|
else
|
44
46
|
new_session_path(resource_name)
|
45
47
|
end
|
46
48
|
end
|
49
|
+
|
50
|
+
def translation_scope
|
51
|
+
'devise.confirmations'
|
52
|
+
end
|
47
53
|
end
|
@@ -1,30 +1,36 @@
|
|
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
|
|
4
6
|
def passthru
|
5
|
-
render status: 404,
|
7
|
+
render status: 404, plain: "Not found. Authentication passthru."
|
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
|
|
13
15
|
protected
|
14
16
|
|
15
17
|
def failed_strategy
|
16
|
-
env["omniauth.error.strategy"]
|
18
|
+
request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : request.env["omniauth.error.strategy"]
|
17
19
|
end
|
18
20
|
|
19
21
|
def failure_message
|
20
|
-
exception = env["omniauth.error"]
|
22
|
+
exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : request.env["omniauth.error"]
|
21
23
|
error = exception.error_reason if exception.respond_to?(:error_reason)
|
22
24
|
error ||= exception.error if exception.respond_to?(:error)
|
23
|
-
error ||= env["omniauth.error.type"].to_s
|
25
|
+
error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : request.env["omniauth.error.type"]).to_s
|
24
26
|
error.to_s.humanize if error
|
25
27
|
end
|
26
28
|
|
27
29
|
def after_omniauth_failure_path_for(scope)
|
28
30
|
new_session_path(scope)
|
29
31
|
end
|
32
|
+
|
33
|
+
def translation_scope
|
34
|
+
'devise.omniauth_callbacks'
|
35
|
+
end
|
30
36
|
end
|
@@ -1,7 +1,9 @@
|
|
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
|
4
|
-
|
6
|
+
append_before_action :assert_reset_token_passed, only: :edit
|
5
7
|
|
6
8
|
# GET /resource/password/new
|
7
9
|
def new
|
@@ -23,6 +25,7 @@ class Devise::PasswordsController < DeviseController
|
|
23
25
|
# GET /resource/password/edit?reset_password_token=abcdef
|
24
26
|
def edit
|
25
27
|
self.resource = resource_class.new
|
28
|
+
set_minimum_password_length
|
26
29
|
resource.reset_password_token = params[:reset_password_token]
|
27
30
|
end
|
28
31
|
|
@@ -33,18 +36,24 @@ class Devise::PasswordsController < DeviseController
|
|
33
36
|
|
34
37
|
if resource.errors.empty?
|
35
38
|
resource.unlock_access! if unlockable?(resource)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
if Devise.sign_in_after_reset_password
|
40
|
+
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
41
|
+
set_flash_message!(:notice, flash_message)
|
42
|
+
resource.after_database_authentication
|
43
|
+
sign_in(resource_name, resource)
|
44
|
+
else
|
45
|
+
set_flash_message!(:notice, :updated_not_active)
|
46
|
+
end
|
39
47
|
respond_with resource, location: after_resetting_password_path_for(resource)
|
40
48
|
else
|
49
|
+
set_minimum_password_length
|
41
50
|
respond_with resource
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
45
54
|
protected
|
46
55
|
def after_resetting_password_path_for(resource)
|
47
|
-
after_sign_in_path_for(resource)
|
56
|
+
Devise.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
|
48
57
|
end
|
49
58
|
|
50
59
|
# The path used after sending reset password instructions
|
@@ -67,4 +76,8 @@ class Devise::PasswordsController < DeviseController
|
|
67
76
|
resource.respond_to?(:unlock_strategy_enabled?) &&
|
68
77
|
resource.unlock_strategy_enabled?(:email)
|
69
78
|
end
|
79
|
+
|
80
|
+
def translation_scope
|
81
|
+
'devise.passwords'
|
82
|
+
end
|
70
83
|
end
|
@@ -1,30 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::RegistrationsController < DeviseController
|
2
|
-
|
3
|
-
|
4
|
+
prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
|
5
|
+
prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
|
6
|
+
prepend_before_action :set_minimum_password_length, only: [:new, :edit]
|
4
7
|
|
5
8
|
# GET /resource/sign_up
|
6
9
|
def new
|
7
|
-
build_resource
|
8
|
-
|
10
|
+
build_resource
|
11
|
+
yield resource if block_given?
|
12
|
+
respond_with resource
|
9
13
|
end
|
10
14
|
|
11
15
|
# POST /resource
|
12
16
|
def create
|
13
17
|
build_resource(sign_up_params)
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
resource.save
|
20
|
+
yield resource if block_given?
|
21
|
+
if resource.persisted?
|
17
22
|
if resource.active_for_authentication?
|
18
|
-
set_flash_message :notice, :signed_up
|
23
|
+
set_flash_message! :notice, :signed_up
|
19
24
|
sign_up(resource_name, resource)
|
20
25
|
respond_with resource, location: after_sign_up_path_for(resource)
|
21
26
|
else
|
22
|
-
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}"
|
27
|
+
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
|
23
28
|
expire_data_after_sign_in!
|
24
29
|
respond_with resource, location: after_inactive_sign_up_path_for(resource)
|
25
30
|
end
|
26
31
|
else
|
27
32
|
clean_up_passwords resource
|
33
|
+
set_minimum_password_length
|
28
34
|
respond_with resource
|
29
35
|
end
|
30
36
|
end
|
@@ -41,17 +47,16 @@ class Devise::RegistrationsController < DeviseController
|
|
41
47
|
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
42
48
|
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
sign_in resource_name, resource, bypass: true
|
50
|
+
resource_updated = update_resource(resource, account_update_params)
|
51
|
+
yield resource if block_given?
|
52
|
+
if resource_updated
|
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
|
+
|
52
56
|
respond_with resource, location: after_update_path_for(resource)
|
53
57
|
else
|
54
58
|
clean_up_passwords resource
|
59
|
+
set_minimum_password_length
|
55
60
|
respond_with resource
|
56
61
|
end
|
57
62
|
end
|
@@ -60,7 +65,7 @@ class Devise::RegistrationsController < DeviseController
|
|
60
65
|
def destroy
|
61
66
|
resource.destroy
|
62
67
|
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
63
|
-
set_flash_message :notice, :destroyed
|
68
|
+
set_flash_message! :notice, :destroyed
|
64
69
|
yield resource if block_given?
|
65
70
|
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
|
66
71
|
end
|
@@ -91,8 +96,8 @@ class Devise::RegistrationsController < DeviseController
|
|
91
96
|
|
92
97
|
# Build a devise resource passing in the session. Useful to move
|
93
98
|
# temporary session data to the newly created user.
|
94
|
-
def build_resource(hash=
|
95
|
-
self.resource = resource_class.new_with_session(hash
|
99
|
+
def build_resource(hash = {})
|
100
|
+
self.resource = resource_class.new_with_session(hash, session)
|
96
101
|
end
|
97
102
|
|
98
103
|
# Signs in a user on sign up. You can overwrite this method in your own
|
@@ -104,19 +109,22 @@ class Devise::RegistrationsController < DeviseController
|
|
104
109
|
# The path used after sign up. You need to overwrite this method
|
105
110
|
# in your own RegistrationsController.
|
106
111
|
def after_sign_up_path_for(resource)
|
107
|
-
after_sign_in_path_for(resource)
|
112
|
+
after_sign_in_path_for(resource) if is_navigational_format?
|
108
113
|
end
|
109
114
|
|
110
115
|
# The path used after sign up for inactive accounts. You need to overwrite
|
111
116
|
# this method in your own RegistrationsController.
|
112
117
|
def after_inactive_sign_up_path_for(resource)
|
113
|
-
|
118
|
+
scope = Devise::Mapping.find_scope!(resource)
|
119
|
+
router_name = Devise.mappings[scope].router_name
|
120
|
+
context = router_name ? send(router_name) : self
|
121
|
+
context.respond_to?(:root_path) ? context.root_path : "/"
|
114
122
|
end
|
115
123
|
|
116
124
|
# The default url to be used after updating a resource. You need to overwrite
|
117
125
|
# this method in your own RegistrationsController.
|
118
126
|
def after_update_path_for(resource)
|
119
|
-
signed_in_root_path(resource)
|
127
|
+
sign_in_after_change_password? ? signed_in_root_path(resource) : new_session_path(resource_name)
|
120
128
|
end
|
121
129
|
|
122
130
|
# Authenticates the current scope and gets the current resource from the session.
|
@@ -132,4 +140,29 @@ class Devise::RegistrationsController < DeviseController
|
|
132
140
|
def account_update_params
|
133
141
|
devise_parameter_sanitizer.sanitize(:account_update)
|
134
142
|
end
|
143
|
+
|
144
|
+
def translation_scope
|
145
|
+
'devise.registrations'
|
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
|
135
168
|
end
|
@@ -1,19 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::SessionsController < DeviseController
|
2
|
-
|
3
|
-
|
4
|
-
|
4
|
+
prepend_before_action :require_no_authentication, only: [:new, :create]
|
5
|
+
prepend_before_action :allow_params_authentication!, only: :create
|
6
|
+
prepend_before_action :verify_signed_out_user, only: :destroy
|
7
|
+
prepend_before_action(only: [:create, :destroy]) { request.env["devise.skip_timeout"] = true }
|
5
8
|
|
6
9
|
# GET /resource/sign_in
|
7
10
|
def new
|
8
11
|
self.resource = resource_class.new(sign_in_params)
|
9
12
|
clean_up_passwords(resource)
|
13
|
+
yield resource if block_given?
|
10
14
|
respond_with(resource, serialize_options(resource))
|
11
15
|
end
|
12
16
|
|
13
17
|
# POST /resource/sign_in
|
14
18
|
def create
|
15
19
|
self.resource = warden.authenticate!(auth_options)
|
16
|
-
set_flash_message(:notice, :signed_in)
|
20
|
+
set_flash_message!(:notice, :signed_in)
|
17
21
|
sign_in(resource_name, resource)
|
18
22
|
yield resource if block_given?
|
19
23
|
respond_with resource, location: after_sign_in_path_for(resource)
|
@@ -21,17 +25,10 @@ class Devise::SessionsController < DeviseController
|
|
21
25
|
|
22
26
|
# DELETE /resource/sign_out
|
23
27
|
def destroy
|
24
|
-
redirect_path = after_sign_out_path_for(resource_name)
|
25
28
|
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
|
26
|
-
set_flash_message :notice, :signed_out if signed_out
|
27
|
-
yield
|
28
|
-
|
29
|
-
# We actually need to hardcode this as Rails default responder doesn't
|
30
|
-
# support returning empty response on GET request
|
31
|
-
respond_to do |format|
|
32
|
-
format.all { head :no_content }
|
33
|
-
format.any(*navigational_formats) { redirect_to redirect_path }
|
34
|
-
end
|
29
|
+
set_flash_message! :notice, :signed_out if signed_out
|
30
|
+
yield if block_given?
|
31
|
+
respond_to_on_destroy
|
35
32
|
end
|
36
33
|
|
37
34
|
protected
|
@@ -50,4 +47,37 @@ class Devise::SessionsController < DeviseController
|
|
50
47
|
def auth_options
|
51
48
|
{ scope: resource_name, recall: "#{controller_path}#new" }
|
52
49
|
end
|
50
|
+
|
51
|
+
def translation_scope
|
52
|
+
'devise.sessions'
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# Check if there is no signed in user before doing the sign out.
|
58
|
+
#
|
59
|
+
# If there is no signed in user, it will set the flash message and redirect
|
60
|
+
# to the after_sign_out path.
|
61
|
+
def verify_signed_out_user
|
62
|
+
if all_signed_out?
|
63
|
+
set_flash_message! :notice, :already_signed_out
|
64
|
+
|
65
|
+
respond_to_on_destroy
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def all_signed_out?
|
70
|
+
users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
|
71
|
+
|
72
|
+
users.all?(&:blank?)
|
73
|
+
end
|
74
|
+
|
75
|
+
def respond_to_on_destroy
|
76
|
+
# We actually need to hardcode this as Rails default responder doesn't
|
77
|
+
# support returning empty response on GET request
|
78
|
+
respond_to do |format|
|
79
|
+
format.all { head :no_content }
|
80
|
+
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
|
81
|
+
end
|
82
|
+
end
|
53
83
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Devise::UnlocksController < DeviseController
|
2
|
-
|
4
|
+
prepend_before_action :require_no_authentication
|
3
5
|
|
4
6
|
# GET /resource/unlock/new
|
5
7
|
def new
|
@@ -24,7 +26,7 @@ class Devise::UnlocksController < DeviseController
|
|
24
26
|
yield resource if block_given?
|
25
27
|
|
26
28
|
if resource.errors.empty?
|
27
|
-
set_flash_message :notice, :unlocked
|
29
|
+
set_flash_message! :notice, :unlocked
|
28
30
|
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
|
29
31
|
else
|
30
32
|
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
@@ -43,4 +45,7 @@ class Devise::UnlocksController < DeviseController
|
|
43
45
|
new_session_path(resource) if is_navigational_format?
|
44
46
|
end
|
45
47
|
|
48
|
+
def translation_scope
|
49
|
+
'devise.unlocks'
|
50
|
+
end
|
46
51
|
end
|
@@ -1,17 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# All Devise controllers are inherited from here.
|
2
4
|
class DeviseController < Devise.parent_controller.constantize
|
3
5
|
include Devise::Controllers::ScopedViews
|
4
6
|
|
5
|
-
helper
|
7
|
+
if respond_to?(:helper)
|
8
|
+
helper DeviseHelper
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
if respond_to?(:helper_method)
|
12
|
+
helpers = %w(resource scope_name resource_name signed_in_resource
|
13
|
+
resource_class resource_params devise_mapping)
|
14
|
+
helper_method(*helpers)
|
15
|
+
end
|
11
16
|
|
12
|
-
|
17
|
+
prepend_before_action :assert_is_devise_resource!
|
13
18
|
respond_to :html if mimes_for_respond_to.empty?
|
14
19
|
|
20
|
+
# Override prefixes to consider the scoped view.
|
21
|
+
# Notice we need to check for the request due to a bug in
|
22
|
+
# Action Controller tests that forces _prefixes to be
|
23
|
+
# loaded before even having a request object.
|
24
|
+
#
|
25
|
+
# This method should be public as it is in ActionPack
|
26
|
+
# itself. Changing its visibility may break other gems.
|
27
|
+
def _prefixes #:nodoc:
|
28
|
+
@_prefixes ||= if self.class.scoped_views? && request && devise_mapping
|
29
|
+
["#{devise_mapping.scoped_path}/#{controller_name}"] + super
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
15
37
|
# Gets the actual resource stored in the instance variable
|
16
38
|
def resource
|
17
39
|
instance_variable_get(:"@#{resource_name}")
|
@@ -38,22 +60,6 @@ class DeviseController < Devise.parent_controller.constantize
|
|
38
60
|
@devise_mapping ||= request.env["devise.mapping"]
|
39
61
|
end
|
40
62
|
|
41
|
-
# Override prefixes to consider the scoped view.
|
42
|
-
# Notice we need to check for the request due to a bug in
|
43
|
-
# Action Controller tests that forces _prefixes to be
|
44
|
-
# loaded before even having a request object.
|
45
|
-
def _prefixes #:nodoc:
|
46
|
-
@_prefixes ||= if self.class.scoped_views? && request && devise_mapping
|
47
|
-
super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
|
48
|
-
else
|
49
|
-
super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
hide_action :_prefixes
|
54
|
-
|
55
|
-
protected
|
56
|
-
|
57
63
|
# Checks whether it's a devise mapped resource or not.
|
58
64
|
def assert_is_devise_resource! #:nodoc:
|
59
65
|
unknown_action! <<-MESSAGE unless devise_mapping
|
@@ -89,10 +95,10 @@ MESSAGE
|
|
89
95
|
instance_variable_set(:"@#{resource_name}", new_resource)
|
90
96
|
end
|
91
97
|
|
92
|
-
# Helper for use in
|
98
|
+
# Helper for use in before_actions where no authentication is required.
|
93
99
|
#
|
94
100
|
# Example:
|
95
|
-
#
|
101
|
+
# before_action :require_no_authentication, only: :new
|
96
102
|
def require_no_authentication
|
97
103
|
assert_is_devise_resource!
|
98
104
|
return unless is_navigational_format?
|
@@ -123,14 +129,17 @@ MESSAGE
|
|
123
129
|
end
|
124
130
|
|
125
131
|
if notice
|
126
|
-
set_flash_message :notice, notice
|
132
|
+
set_flash_message! :notice, notice
|
127
133
|
true
|
128
134
|
end
|
129
135
|
end
|
130
136
|
|
131
137
|
# Sets the flash message with :key, using I18n. By default you are able
|
132
|
-
# to
|
133
|
-
# found we look to default scope.
|
138
|
+
# to set up your messages using specific resource scope, and if no message is
|
139
|
+
# found we look to the default scope. Set the "now" options key to a true
|
140
|
+
# value to populate the flash.now hash in lieu of the default flash hash (so
|
141
|
+
# the flash message will be available to the current action instead of the
|
142
|
+
# next action).
|
134
143
|
# Example (i18n locale file):
|
135
144
|
#
|
136
145
|
# en:
|
@@ -144,7 +153,25 @@ MESSAGE
|
|
144
153
|
# available.
|
145
154
|
def set_flash_message(key, kind, options = {})
|
146
155
|
message = find_message(kind, options)
|
147
|
-
|
156
|
+
if options[:now]
|
157
|
+
flash.now[key] = message if message.present?
|
158
|
+
else
|
159
|
+
flash[key] = message if message.present?
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# Sets flash message if is_flashing_format? equals true
|
164
|
+
def set_flash_message!(key, kind, options = {})
|
165
|
+
if is_flashing_format?
|
166
|
+
set_flash_message(key, kind, options)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# Sets minimum password length to show to user
|
171
|
+
def set_minimum_password_length
|
172
|
+
if devise_mapping.validatable?
|
173
|
+
@minimum_password_length = resource_class.password_length.min
|
174
|
+
end
|
148
175
|
end
|
149
176
|
|
150
177
|
def devise_i18n_options(options)
|
@@ -153,13 +180,20 @@ MESSAGE
|
|
153
180
|
|
154
181
|
# Get message for given
|
155
182
|
def find_message(kind, options = {})
|
156
|
-
options[:scope]
|
183
|
+
options[:scope] ||= translation_scope
|
157
184
|
options[:default] = Array(options[:default]).unshift(kind.to_sym)
|
158
185
|
options[:resource_name] = resource_name
|
159
186
|
options = devise_i18n_options(options)
|
160
187
|
I18n.t("#{options[:resource_name]}.#{kind}", options)
|
161
188
|
end
|
162
189
|
|
190
|
+
# Controllers inheriting DeviseController are advised to override this
|
191
|
+
# method so that other controllers inheriting from them would use
|
192
|
+
# existing translations.
|
193
|
+
def translation_scope
|
194
|
+
"devise.#{controller_name}"
|
195
|
+
end
|
196
|
+
|
163
197
|
def clean_up_passwords(object)
|
164
198
|
object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
|
165
199
|
end
|
@@ -173,4 +207,6 @@ MESSAGE
|
|
173
207
|
def resource_params
|
174
208
|
params.fetch(resource_name, {})
|
175
209
|
end
|
210
|
+
|
211
|
+
ActiveSupport.run_load_hooks(:devise_controller, self)
|
176
212
|
end
|
@@ -1,25 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeviseHelper
|
2
|
-
#
|
3
|
-
#
|
4
|
-
# copy the views to your application.
|
5
|
-
#
|
6
|
-
# This method is intended to stay simple and it is unlikely that we are going to change
|
7
|
-
# it to add more behavior or options.
|
4
|
+
# Retain this method for backwards compatibility, deprecated in favour of modifying the
|
5
|
+
# devise/shared/error_messages partial
|
8
6
|
def devise_error_messages!
|
9
|
-
|
7
|
+
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
|
8
|
+
[Devise] `DeviseHelper.devise_error_messages!`
|
9
|
+
is deprecated and it will be removed in the next major version.
|
10
|
+
To customize the errors styles please run `rails g devise:views` and modify the
|
11
|
+
`devise/shared/error_messages` partial.
|
12
|
+
DEPRECATION
|
10
13
|
|
11
|
-
|
12
|
-
sentence = I18n.t("errors.messages.not_saved",
|
13
|
-
count: resource.errors.count,
|
14
|
-
resource: resource.class.model_name.human.downcase)
|
15
|
-
|
16
|
-
html = <<-HTML
|
17
|
-
<div id="error_explanation">
|
18
|
-
<h2>#{sentence}</h2>
|
19
|
-
<ul>#{messages}</ul>
|
20
|
-
</div>
|
21
|
-
HTML
|
14
|
+
return "" if resource.errors.empty?
|
22
15
|
|
23
|
-
|
16
|
+
render "devise/shared/error_messages", resource: resource
|
24
17
|
end
|
25
18
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
if defined?(ActionMailer)
|
2
4
|
class Devise::Mailer < Devise.parent_mailer.constantize
|
3
5
|
include Devise::Mailers::Helpers
|
@@ -16,5 +18,13 @@ if defined?(ActionMailer)
|
|
16
18
|
@token = token
|
17
19
|
devise_mail(record, :unlock_instructions, opts)
|
18
20
|
end
|
21
|
+
|
22
|
+
def email_changed(record, opts={})
|
23
|
+
devise_mail(record, :email_changed, opts)
|
24
|
+
end
|
25
|
+
|
26
|
+
def password_change(record, opts={})
|
27
|
+
devise_mail(record, :password_change, opts)
|
28
|
+
end
|
19
29
|
end
|
20
30
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
<h2>Resend confirmation instructions</h2>
|
2
2
|
|
3
3
|
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
|
4
|
-
<%=
|
4
|
+
<%= render "devise/shared/error_messages", resource: resource %>
|
5
5
|
|
6
|
-
<div
|
7
|
-
|
6
|
+
<div class="field">
|
7
|
+
<%= f.label :email %><br />
|
8
|
+
<%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
|
9
|
+
</div>
|
8
10
|
|
9
|
-
<div
|
11
|
+
<div class="actions">
|
12
|
+
<%= f.submit "Resend confirmation instructions" %>
|
13
|
+
</div>
|
10
14
|
<% end %>
|
11
15
|
|
12
16
|
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<p>Hello <%= @email %>!</p>
|
2
|
+
|
3
|
+
<% if @resource.try(:unconfirmed_email?) %>
|
4
|
+
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
|
5
|
+
<% else %>
|
6
|
+
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
|
7
|
+
<% end %>
|