devise 2.1.2 → 3.5.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +39 -10
- data/.yardopts +9 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +10 -15
- data/Gemfile.lock +151 -129
- data/MIT-LICENSE +1 -1
- data/README.md +256 -96
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +15 -7
- data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
- data/app/controllers/devise/passwords_controller.rb +33 -9
- data/app/controllers/devise/registrations_controller.rb +66 -26
- data/app/controllers/devise/sessions_controller.rb +52 -21
- data/app/controllers/devise/unlocks_controller.rb +11 -6
- data/app/controllers/devise_controller.rb +65 -58
- data/app/helpers/devise_helper.rb +2 -2
- data/app/mailers/devise/mailer.rb +19 -10
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
- 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 +29 -15
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +17 -8
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +51 -47
- data/devise.gemspec +8 -6
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
- data/gemfiles/Gemfile.rails-4.0-stable +30 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.1-stable +30 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +126 -108
- data/lib/devise/controllers/rememberable.rb +19 -17
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +96 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +85 -25
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +1 -1
- data/lib/devise/hooks/lockable.rb +2 -2
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +5 -4
- data/lib/devise/hooks/timeoutable.rb +16 -8
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +27 -23
- data/lib/devise/mapping.rb +11 -7
- data/lib/devise/models/authenticatable.rb +82 -66
- data/lib/devise/models/confirmable.rb +142 -55
- data/lib/devise/models/database_authenticatable.rb +59 -15
- data/lib/devise/models/lockable.rb +41 -30
- data/lib/devise/models/omniauthable.rb +3 -3
- data/lib/devise/models/recoverable.rb +56 -41
- data/lib/devise/models/rememberable.rb +65 -27
- data/lib/devise/models/timeoutable.rb +2 -8
- data/lib/devise/models/trackable.rb +6 -4
- data/lib/devise/models/validatable.rb +9 -9
- data/lib/devise/models.rb +4 -13
- data/lib/devise/modules.rb +10 -11
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails/routes.rb +173 -115
- data/lib/devise/rails/warden_compat.rb +10 -31
- data/lib/devise/rails.rb +14 -12
- data/lib/devise/strategies/authenticatable.rb +26 -26
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -4
- data/lib/devise/strategies/rememberable.rb +15 -5
- data/lib/devise/test_helpers.rb +7 -5
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +110 -52
- data/lib/generators/active_record/devise_generator.rb +34 -18
- data/lib/generators/active_record/templates/migration.rb +5 -6
- data/lib/generators/active_record/templates/migration_existing.rb +5 -6
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/orm_helpers.rb +25 -6
- data/lib/generators/devise/views_generator.rb +52 -22
- data/lib/generators/mongoid/devise_generator.rb +21 -26
- data/lib/generators/templates/README +9 -5
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +80 -43
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
- 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 +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +95 -32
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +39 -14
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +66 -6
- data/test/controllers/url_helpers_test.rb +10 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +45 -10
- data/test/failure_app_test.rb +121 -27
- data/test/generators/active_record_generator_test.rb +48 -8
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +54 -3
- data/test/helpers/devise_helper_test.rb +18 -20
- data/test/integration/authenticatable_test.rb +161 -65
- data/test/integration/confirmable_test.rb +146 -77
- data/test/integration/database_authenticatable_test.rb +43 -30
- data/test/integration/http_authenticatable_test.rb +30 -22
- data/test/integration/lockable_test.rb +64 -49
- data/test/integration/omniauthable_test.rb +17 -15
- data/test/integration/recoverable_test.rb +111 -70
- data/test/integration/registerable_test.rb +114 -79
- data/test/integration/rememberable_test.rb +87 -31
- data/test/integration/timeoutable_test.rb +77 -33
- data/test/integration/trackable_test.rb +5 -5
- data/test/mailers/confirmation_instructions_test.rb +28 -8
- data/test/mailers/reset_password_instructions_test.rb +21 -8
- data/test/mailers/unlock_instructions_test.rb +20 -6
- data/test/mapping_test.rb +12 -5
- data/test/models/authenticatable_test.rb +17 -1
- data/test/models/confirmable_test.rb +216 -62
- data/test/models/database_authenticatable_test.rb +129 -49
- data/test/models/lockable_test.rb +132 -45
- data/test/models/recoverable_test.rb +100 -54
- data/test/models/rememberable_test.rb +89 -94
- data/test/models/serializable_test.rb +12 -11
- data/test/models/timeoutable_test.rb +6 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +31 -21
- data/test/models_test.rb +22 -48
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +7 -4
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongoid.rb +2 -3
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/application_controller.rb +6 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +12 -4
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +1 -1
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +12 -10
- data/test/rails_app/app/mongoid/shim.rb +4 -5
- data/test/rails_app/app/mongoid/user.rb +19 -22
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +4 -5
- data/test/rails_app/config/boot.rb +9 -3
- data/test/rails_app/config/environment.rb +2 -2
- data/test/rails_app/config/environments/development.rb +19 -7
- data/test/rails_app/config/environments/production.rb +68 -17
- data/test/rails_app/config/environments/test.rb +24 -16
- data/test/rails_app/config/initializers/devise.rb +22 -20
- data/test/rails_app/config/initializers/secret_token.rb +8 -2
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +71 -46
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
- data/test/rails_app/db/schema.rb +21 -18
- data/test/rails_app/lib/shared_admin.rb +7 -4
- data/test/rails_app/lib/shared_user.rb +6 -3
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_test.rb +9 -0
- data/test/routes_test.rb +94 -78
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +18 -32
- data/test/support/integration.rb +17 -16
- data/test/support/locale/en.yml +4 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +8 -1
- data/test/test_helpers_test.rb +64 -20
- data/test/test_models.rb +33 -0
- data/test/time_helpers.rb +137 -0
- metadata +172 -51
- data/app/views/devise/_links.erb +0 -3
- data/gemfiles/Gemfile.rails-3.1.x +0 -35
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/lib/devise/models/token_authenticatable.rb +0 -77
- data/lib/devise/strategies/token_authenticatable.rb +0 -56
- data/test/indifferent_hash.rb +0 -33
- data/test/integration/token_authenticatable_test.rb +0 -161
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/rails_app/script/rails +0 -10
data/Rakefile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
3
4
|
require 'rake/testtask'
|
4
5
|
require 'rdoc/task'
|
5
6
|
|
6
7
|
desc 'Default: run tests for all ORMs.'
|
7
|
-
task :
|
8
|
+
task default: :test
|
8
9
|
|
9
10
|
desc 'Run Devise tests for all ORMs.'
|
10
11
|
task :pre_commit do
|
@@ -22,6 +23,7 @@ Rake::TestTask.new(:test) do |t|
|
|
22
23
|
t.libs << 'test'
|
23
24
|
t.pattern = 'test/**/*_test.rb'
|
24
25
|
t.verbose = true
|
26
|
+
t.warning = false
|
25
27
|
end
|
26
28
|
|
27
29
|
desc 'Generate documentation for Devise.'
|
@@ -1,15 +1,16 @@
|
|
1
1
|
class Devise::ConfirmationsController < DeviseController
|
2
2
|
# GET /resource/confirmation/new
|
3
3
|
def new
|
4
|
-
|
4
|
+
self.resource = resource_class.new
|
5
5
|
end
|
6
6
|
|
7
7
|
# POST /resource/confirmation
|
8
8
|
def create
|
9
9
|
self.resource = resource_class.send_confirmation_instructions(resource_params)
|
10
|
+
yield resource if block_given?
|
10
11
|
|
11
12
|
if successfully_sent?(resource)
|
12
|
-
respond_with({}, :
|
13
|
+
respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
|
13
14
|
else
|
14
15
|
respond_with(resource)
|
15
16
|
end
|
@@ -18,13 +19,13 @@ class Devise::ConfirmationsController < DeviseController
|
|
18
19
|
# GET /resource/confirmation?confirmation_token=abcdef
|
19
20
|
def show
|
20
21
|
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
|
22
|
+
yield resource if block_given?
|
21
23
|
|
22
24
|
if resource.errors.empty?
|
23
|
-
set_flash_message(:notice, :confirmed) if
|
24
|
-
sign_in(resource_name, resource)
|
25
|
+
set_flash_message(:notice, :confirmed) if is_flashing_format?
|
25
26
|
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
26
27
|
else
|
27
|
-
respond_with_navigational(resource.errors, :
|
28
|
+
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
@@ -32,12 +33,19 @@ class Devise::ConfirmationsController < DeviseController
|
|
32
33
|
|
33
34
|
# The path used after resending confirmation instructions.
|
34
35
|
def after_resending_confirmation_instructions_path_for(resource_name)
|
35
|
-
new_session_path(resource_name)
|
36
|
+
is_navigational_format? ? new_session_path(resource_name) : '/'
|
36
37
|
end
|
37
38
|
|
38
39
|
# The path used after confirmation.
|
39
40
|
def after_confirmation_path_for(resource_name, resource)
|
40
|
-
|
41
|
+
if signed_in?(resource_name)
|
42
|
+
signed_in_root_path(resource)
|
43
|
+
else
|
44
|
+
new_session_path(resource_name)
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
48
|
+
def translation_scope
|
49
|
+
'devise.confirmations'
|
50
|
+
end
|
43
51
|
end
|
@@ -2,11 +2,11 @@ class Devise::OmniauthCallbacksController < DeviseController
|
|
2
2
|
prepend_before_filter { request.env["devise.skip_timeout"] = true }
|
3
3
|
|
4
4
|
def passthru
|
5
|
-
render :
|
5
|
+
render status: 404, text: "Not found. Authentication passthru."
|
6
6
|
end
|
7
7
|
|
8
8
|
def failure
|
9
|
-
set_flash_message :alert, :failure, :
|
9
|
+
set_flash_message :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
|
10
10
|
redirect_to after_omniauth_failure_path_for(resource_name)
|
11
11
|
end
|
12
12
|
|
@@ -27,4 +27,8 @@ class Devise::OmniauthCallbacksController < DeviseController
|
|
27
27
|
def after_omniauth_failure_path_for(scope)
|
28
28
|
new_session_path(scope)
|
29
29
|
end
|
30
|
+
|
31
|
+
def translation_scope
|
32
|
+
'devise.omniauth_callbacks'
|
33
|
+
end
|
30
34
|
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
class Devise::PasswordsController < DeviseController
|
2
2
|
prepend_before_filter :require_no_authentication
|
3
3
|
# Render the #edit only if coming from a reset password email link
|
4
|
-
append_before_filter :assert_reset_token_passed, :
|
4
|
+
append_before_filter :assert_reset_token_passed, only: :edit
|
5
5
|
|
6
6
|
# GET /resource/password/new
|
7
7
|
def new
|
8
|
-
|
8
|
+
self.resource = resource_class.new
|
9
9
|
end
|
10
10
|
|
11
11
|
# POST /resource/password
|
12
12
|
def create
|
13
13
|
self.resource = resource_class.send_reset_password_instructions(resource_params)
|
14
|
+
yield resource if block_given?
|
14
15
|
|
15
16
|
if successfully_sent?(resource)
|
16
|
-
respond_with({}, :
|
17
|
+
respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
|
17
18
|
else
|
18
19
|
respond_with(resource)
|
19
20
|
end
|
@@ -22,35 +23,58 @@ class Devise::PasswordsController < DeviseController
|
|
22
23
|
# GET /resource/password/edit?reset_password_token=abcdef
|
23
24
|
def edit
|
24
25
|
self.resource = resource_class.new
|
26
|
+
set_minimum_password_length
|
25
27
|
resource.reset_password_token = params[:reset_password_token]
|
26
28
|
end
|
27
29
|
|
28
30
|
# PUT /resource/password
|
29
31
|
def update
|
30
32
|
self.resource = resource_class.reset_password_by_token(resource_params)
|
33
|
+
yield resource if block_given?
|
31
34
|
|
32
35
|
if resource.errors.empty?
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
resource.unlock_access! if unlockable?(resource)
|
37
|
+
if Devise.sign_in_after_reset_password
|
38
|
+
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
39
|
+
set_flash_message(:notice, flash_message) if is_flashing_format?
|
40
|
+
sign_in(resource_name, resource)
|
41
|
+
else
|
42
|
+
set_flash_message(:notice, :updated_not_active) if is_flashing_format?
|
43
|
+
end
|
44
|
+
respond_with resource, location: after_resetting_password_path_for(resource)
|
37
45
|
else
|
46
|
+
set_minimum_password_length
|
38
47
|
respond_with resource
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
42
51
|
protected
|
52
|
+
def after_resetting_password_path_for(resource)
|
53
|
+
Devise.sign_in_after_reset_password ? after_sign_in_path_for(resource) : new_session_path(resource_name)
|
54
|
+
end
|
43
55
|
|
44
56
|
# The path used after sending reset password instructions
|
45
57
|
def after_sending_reset_password_instructions_path_for(resource_name)
|
46
|
-
new_session_path(resource_name)
|
58
|
+
new_session_path(resource_name) if is_navigational_format?
|
47
59
|
end
|
48
60
|
|
49
61
|
# Check if a reset_password_token is provided in the request
|
50
62
|
def assert_reset_token_passed
|
51
63
|
if params[:reset_password_token].blank?
|
52
|
-
set_flash_message(:
|
64
|
+
set_flash_message(:alert, :no_token)
|
53
65
|
redirect_to new_session_path(resource_name)
|
54
66
|
end
|
55
67
|
end
|
68
|
+
|
69
|
+
# Check if proper Lockable module methods are present & unlock strategy
|
70
|
+
# allows to unlock resource on password reset
|
71
|
+
def unlockable?(resource)
|
72
|
+
resource.respond_to?(:unlock_access!) &&
|
73
|
+
resource.respond_to?(:unlock_strategy_enabled?) &&
|
74
|
+
resource.unlock_strategy_enabled?(:email)
|
75
|
+
end
|
76
|
+
|
77
|
+
def translation_scope
|
78
|
+
'devise.passwords'
|
79
|
+
end
|
56
80
|
end
|
@@ -1,29 +1,34 @@
|
|
1
1
|
class Devise::RegistrationsController < DeviseController
|
2
|
-
prepend_before_filter :require_no_authentication, :
|
3
|
-
prepend_before_filter :authenticate_scope!, :
|
2
|
+
prepend_before_filter :require_no_authentication, only: [:new, :create, :cancel]
|
3
|
+
prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy]
|
4
4
|
|
5
5
|
# GET /resource/sign_up
|
6
6
|
def new
|
7
|
-
|
8
|
-
|
7
|
+
build_resource({})
|
8
|
+
set_minimum_password_length
|
9
|
+
yield resource if block_given?
|
10
|
+
respond_with self.resource
|
9
11
|
end
|
10
12
|
|
11
13
|
# POST /resource
|
12
14
|
def create
|
13
|
-
build_resource
|
15
|
+
build_resource(sign_up_params)
|
14
16
|
|
15
|
-
|
17
|
+
resource.save
|
18
|
+
yield resource if block_given?
|
19
|
+
if resource.persisted?
|
16
20
|
if resource.active_for_authentication?
|
17
|
-
set_flash_message :notice, :signed_up if
|
18
|
-
|
19
|
-
respond_with resource, :
|
21
|
+
set_flash_message :notice, :signed_up if is_flashing_format?
|
22
|
+
sign_up(resource_name, resource)
|
23
|
+
respond_with resource, location: after_sign_up_path_for(resource)
|
20
24
|
else
|
21
|
-
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if
|
22
|
-
|
23
|
-
respond_with resource, :
|
25
|
+
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
|
26
|
+
expire_data_after_sign_in!
|
27
|
+
respond_with resource, location: after_inactive_sign_up_path_for(resource)
|
24
28
|
end
|
25
29
|
else
|
26
30
|
clean_up_passwords resource
|
31
|
+
set_minimum_password_length
|
27
32
|
respond_with resource
|
28
33
|
end
|
29
34
|
end
|
@@ -38,16 +43,18 @@ class Devise::RegistrationsController < DeviseController
|
|
38
43
|
# the current user in place.
|
39
44
|
def update
|
40
45
|
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
|
46
|
+
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
resource_updated = update_resource(resource, account_update_params)
|
49
|
+
yield resource if block_given?
|
50
|
+
if resource_updated
|
51
|
+
if is_flashing_format?
|
52
|
+
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
|
53
|
+
:update_needs_confirmation : :updated
|
54
|
+
set_flash_message :notice, flash_key
|
48
55
|
end
|
49
|
-
sign_in resource_name, resource, :
|
50
|
-
respond_with resource, :
|
56
|
+
sign_in resource_name, resource, bypass: true
|
57
|
+
respond_with resource, location: after_update_path_for(resource)
|
51
58
|
else
|
52
59
|
clean_up_passwords resource
|
53
60
|
respond_with resource
|
@@ -58,7 +65,8 @@ class Devise::RegistrationsController < DeviseController
|
|
58
65
|
def destroy
|
59
66
|
resource.destroy
|
60
67
|
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
|
61
|
-
set_flash_message :notice, :destroyed if
|
68
|
+
set_flash_message :notice, :destroyed if is_flashing_format?
|
69
|
+
yield resource if block_given?
|
62
70
|
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
|
63
71
|
end
|
64
72
|
|
@@ -68,17 +76,34 @@ class Devise::RegistrationsController < DeviseController
|
|
68
76
|
# cancel oauth signing in/up in the middle of the process,
|
69
77
|
# removing all OAuth session data.
|
70
78
|
def cancel
|
71
|
-
|
79
|
+
expire_data_after_sign_in!
|
72
80
|
redirect_to new_registration_path(resource_name)
|
73
81
|
end
|
74
82
|
|
75
83
|
protected
|
76
84
|
|
85
|
+
def update_needs_confirmation?(resource, previous)
|
86
|
+
resource.respond_to?(:pending_reconfirmation?) &&
|
87
|
+
resource.pending_reconfirmation? &&
|
88
|
+
previous != resource.unconfirmed_email
|
89
|
+
end
|
90
|
+
|
91
|
+
# By default we want to require a password checks on update.
|
92
|
+
# You can overwrite this method in your own RegistrationsController.
|
93
|
+
def update_resource(resource, params)
|
94
|
+
resource.update_with_password(params)
|
95
|
+
end
|
96
|
+
|
77
97
|
# Build a devise resource passing in the session. Useful to move
|
78
98
|
# temporary session data to the newly created user.
|
79
99
|
def build_resource(hash=nil)
|
80
|
-
|
81
|
-
|
100
|
+
self.resource = resource_class.new_with_session(hash || {}, session)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Signs in a user on sign up. You can overwrite this method in your own
|
104
|
+
# RegistrationsController.
|
105
|
+
def sign_up(resource_name, resource)
|
106
|
+
sign_in(resource_name, resource)
|
82
107
|
end
|
83
108
|
|
84
109
|
# The path used after sign up. You need to overwrite this method
|
@@ -90,7 +115,10 @@ class Devise::RegistrationsController < DeviseController
|
|
90
115
|
# The path used after sign up for inactive accounts. You need to overwrite
|
91
116
|
# this method in your own RegistrationsController.
|
92
117
|
def after_inactive_sign_up_path_for(resource)
|
93
|
-
|
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 : "/"
|
94
122
|
end
|
95
123
|
|
96
124
|
# The default url to be used after updating a resource. You need to overwrite
|
@@ -101,7 +129,19 @@ class Devise::RegistrationsController < DeviseController
|
|
101
129
|
|
102
130
|
# Authenticates the current scope and gets the current resource from the session.
|
103
131
|
def authenticate_scope!
|
104
|
-
send(:"authenticate_#{resource_name}!", :
|
132
|
+
send(:"authenticate_#{resource_name}!", force: true)
|
105
133
|
self.resource = send(:"current_#{resource_name}")
|
106
134
|
end
|
135
|
+
|
136
|
+
def sign_up_params
|
137
|
+
devise_parameter_sanitizer.sanitize(:sign_up)
|
138
|
+
end
|
139
|
+
|
140
|
+
def account_update_params
|
141
|
+
devise_parameter_sanitizer.sanitize(:account_update)
|
142
|
+
end
|
143
|
+
|
144
|
+
def translation_scope
|
145
|
+
'devise.registrations'
|
146
|
+
end
|
107
147
|
end
|
@@ -1,50 +1,81 @@
|
|
1
1
|
class Devise::SessionsController < DeviseController
|
2
|
-
prepend_before_filter :require_no_authentication, :
|
3
|
-
prepend_before_filter :allow_params_authentication!, :
|
4
|
-
prepend_before_filter
|
2
|
+
prepend_before_filter :require_no_authentication, only: [:new, :create]
|
3
|
+
prepend_before_filter :allow_params_authentication!, only: :create
|
4
|
+
prepend_before_filter :verify_signed_out_user, only: :destroy
|
5
|
+
prepend_before_filter only: [:create, :destroy] { request.env["devise.skip_timeout"] = true }
|
5
6
|
|
6
7
|
# GET /resource/sign_in
|
7
8
|
def new
|
8
|
-
resource =
|
9
|
+
self.resource = resource_class.new(sign_in_params)
|
9
10
|
clean_up_passwords(resource)
|
11
|
+
yield resource if block_given?
|
10
12
|
respond_with(resource, serialize_options(resource))
|
11
13
|
end
|
12
14
|
|
13
15
|
# POST /resource/sign_in
|
14
16
|
def create
|
15
|
-
resource = warden.authenticate!(auth_options)
|
16
|
-
set_flash_message(:notice, :signed_in) if
|
17
|
+
self.resource = warden.authenticate!(auth_options)
|
18
|
+
set_flash_message(:notice, :signed_in) if is_flashing_format?
|
17
19
|
sign_in(resource_name, resource)
|
18
|
-
|
20
|
+
yield resource if block_given?
|
21
|
+
respond_with resource, location: after_sign_in_path_for(resource)
|
19
22
|
end
|
20
23
|
|
21
24
|
# DELETE /resource/sign_out
|
22
25
|
def destroy
|
23
|
-
redirect_path = after_sign_out_path_for(resource_name)
|
24
26
|
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
|
25
|
-
set_flash_message :notice, :signed_out if signed_out
|
26
|
-
|
27
|
-
|
28
|
-
# support returning empty response on GET request
|
29
|
-
respond_to do |format|
|
30
|
-
format.any(*navigational_formats) { redirect_to redirect_path }
|
31
|
-
format.all do
|
32
|
-
head :no_content
|
33
|
-
end
|
34
|
-
end
|
27
|
+
set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
|
28
|
+
yield if block_given?
|
29
|
+
respond_to_on_destroy
|
35
30
|
end
|
36
31
|
|
37
32
|
protected
|
38
33
|
|
34
|
+
def sign_in_params
|
35
|
+
devise_parameter_sanitizer.sanitize(:sign_in)
|
36
|
+
end
|
37
|
+
|
39
38
|
def serialize_options(resource)
|
40
39
|
methods = resource_class.authentication_keys.dup
|
41
40
|
methods = methods.keys if methods.is_a?(Hash)
|
42
41
|
methods << :password if resource.respond_to?(:password)
|
43
|
-
{ :
|
42
|
+
{ methods: methods, only: [:password] }
|
44
43
|
end
|
45
44
|
|
46
45
|
def auth_options
|
47
|
-
{ :
|
46
|
+
{ scope: resource_name, recall: "#{controller_path}#new" }
|
48
47
|
end
|
49
|
-
end
|
50
48
|
|
49
|
+
def translation_scope
|
50
|
+
'devise.sessions'
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# Check if there is no signed in user before doing the sign out.
|
56
|
+
#
|
57
|
+
# If there is no signed in user, it will set the flash message and redirect
|
58
|
+
# to the after_sign_out path.
|
59
|
+
def verify_signed_out_user
|
60
|
+
if all_signed_out?
|
61
|
+
set_flash_message :notice, :already_signed_out if is_flashing_format?
|
62
|
+
|
63
|
+
respond_to_on_destroy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def all_signed_out?
|
68
|
+
users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
|
69
|
+
|
70
|
+
users.all?(&:blank?)
|
71
|
+
end
|
72
|
+
|
73
|
+
def respond_to_on_destroy
|
74
|
+
# We actually need to hardcode this as Rails default responder doesn't
|
75
|
+
# support returning empty response on GET request
|
76
|
+
respond_to do |format|
|
77
|
+
format.all { head :no_content }
|
78
|
+
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -3,15 +3,16 @@ class Devise::UnlocksController < DeviseController
|
|
3
3
|
|
4
4
|
# GET /resource/unlock/new
|
5
5
|
def new
|
6
|
-
|
6
|
+
self.resource = resource_class.new
|
7
7
|
end
|
8
8
|
|
9
9
|
# POST /resource/unlock
|
10
10
|
def create
|
11
11
|
self.resource = resource_class.send_unlock_instructions(resource_params)
|
12
|
+
yield resource if block_given?
|
12
13
|
|
13
14
|
if successfully_sent?(resource)
|
14
|
-
respond_with({}, :
|
15
|
+
respond_with({}, location: after_sending_unlock_instructions_path_for(resource))
|
15
16
|
else
|
16
17
|
respond_with(resource)
|
17
18
|
end
|
@@ -20,12 +21,13 @@ class Devise::UnlocksController < DeviseController
|
|
20
21
|
# GET /resource/unlock?unlock_token=abcdef
|
21
22
|
def show
|
22
23
|
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
|
24
|
+
yield resource if block_given?
|
23
25
|
|
24
26
|
if resource.errors.empty?
|
25
|
-
set_flash_message :notice, :unlocked if
|
27
|
+
set_flash_message :notice, :unlocked if is_flashing_format?
|
26
28
|
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
|
27
29
|
else
|
28
|
-
respond_with_navigational(resource.errors, :
|
30
|
+
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -33,12 +35,15 @@ class Devise::UnlocksController < DeviseController
|
|
33
35
|
|
34
36
|
# The path used after sending unlock password instructions
|
35
37
|
def after_sending_unlock_instructions_path_for(resource)
|
36
|
-
new_session_path(resource)
|
38
|
+
new_session_path(resource) if is_navigational_format?
|
37
39
|
end
|
38
40
|
|
39
41
|
# The path used after unlocking the resource
|
40
42
|
def after_unlock_path_for(resource)
|
41
|
-
new_session_path(resource)
|
43
|
+
new_session_path(resource) if is_navigational_format?
|
42
44
|
end
|
43
45
|
|
46
|
+
def translation_scope
|
47
|
+
'devise.unlocks'
|
48
|
+
end
|
44
49
|
end
|