devise 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +23 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +81 -55
- data/README.md +28 -5
- data/app/controllers/devise/confirmations_controller.rb +1 -1
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +0 -0
- data/config/locales/en.yml +2 -2
- data/devise.gemspec +1 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +5 -2
- data/gemfiles/Gemfile.rails-4.0-stable.lock +25 -22
- data/gemfiles/{Gemfile.rails-head → Gemfile.rails-4.1-stable} +2 -5
- data/gemfiles/{Gemfile.rails-head.lock → Gemfile.rails-4.1-stable.lock} +45 -65
- data/lib/devise.rb +2 -1
- data/lib/devise/failure_app.rb +6 -1
- data/lib/devise/mapping.rb +1 -1
- data/lib/devise/models/authenticatable.rb +8 -2
- data/lib/devise/models/lockable.rb +2 -2
- data/lib/devise/rails/routes.rb +6 -9
- data/lib/devise/strategies/authenticatable.rb +1 -2
- data/lib/devise/strategies/database_authenticatable.rb +1 -0
- data/lib/devise/strategies/rememberable.rb +6 -3
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +2 -1
- data/lib/generators/devise/controllers_generator.rb +44 -0
- 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 +2 -2
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +2 -2
- data/test/controllers/url_helpers_test.rb +6 -0
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/views_generator_test.rb +1 -1
- data/test/helpers/devise_helper_test.rb +9 -12
- data/test/integration/authenticatable_test.rb +1 -1
- data/test/integration/http_authenticatable_test.rb +1 -1
- data/test/mapping_test.rb +1 -0
- data/test/models/authenticatable_test.rb +10 -0
- data/test/models/confirmable_test.rb +5 -4
- data/test/models/lockable_test.rb +16 -10
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +0 -9
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -2
- data/test/support/helpers.rb +9 -6
- data/test/test_helper.rb +5 -0
- metadata +33 -5
@@ -0,0 +1,14 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
Ensure you have overridden routes for generated controllers in your route.rb.
|
6
|
+
For example:
|
7
|
+
|
8
|
+
Rails.application.routes.draw do
|
9
|
+
devise_for :users, controllers: {
|
10
|
+
sessions: 'sessions'
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
===============================================================================
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class <%= @scope_prefix %>ConfirmationsController < Devise::ConfirmationsController
|
2
|
+
# GET /resource/confirmation/new
|
3
|
+
# def new
|
4
|
+
# super
|
5
|
+
# end
|
6
|
+
|
7
|
+
# POST /resource/confirmation
|
8
|
+
# def create
|
9
|
+
# super
|
10
|
+
# end
|
11
|
+
|
12
|
+
# GET /resource/confirmation?confirmation_token=abcdef
|
13
|
+
# def show
|
14
|
+
# super
|
15
|
+
# end
|
16
|
+
|
17
|
+
# protected
|
18
|
+
|
19
|
+
# The path used after resending confirmation instructions.
|
20
|
+
# def after_resending_confirmation_instructions_path_for(resource_name)
|
21
|
+
# super(resource_name)
|
22
|
+
# end
|
23
|
+
|
24
|
+
# The path used after confirmation.
|
25
|
+
# def after_confirmation_path_for(resource_name, resource)
|
26
|
+
# super(resource_name, resource)
|
27
|
+
# end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class <%= @scope_prefix %>OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
2
|
+
# You should configure your model like this:
|
3
|
+
# devise :omniauthable, omniauth_providers: [:twitter]
|
4
|
+
|
5
|
+
# You should also create an action method in this controller like this:
|
6
|
+
# def twitter
|
7
|
+
# end
|
8
|
+
|
9
|
+
# More info at:
|
10
|
+
# https://github.com/plataformatec/devise#omniauth
|
11
|
+
|
12
|
+
# GET|POST /resource/auth/twitter
|
13
|
+
# def passthru
|
14
|
+
# super
|
15
|
+
# end
|
16
|
+
|
17
|
+
# GET|POST /users/auth/twitter/callback
|
18
|
+
# def failure
|
19
|
+
# super
|
20
|
+
# end
|
21
|
+
|
22
|
+
# protected
|
23
|
+
|
24
|
+
# The path used when omniauth fails
|
25
|
+
# def after_omniauth_failure_path_for(scope)
|
26
|
+
# super(scope)
|
27
|
+
# end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class <%= @scope_prefix %>PasswordsController < Devise::PasswordsController
|
2
|
+
# GET /resource/password/new
|
3
|
+
# def new
|
4
|
+
# super
|
5
|
+
# end
|
6
|
+
|
7
|
+
# POST /resource/password
|
8
|
+
# def create
|
9
|
+
# super
|
10
|
+
# end
|
11
|
+
|
12
|
+
# GET /resource/password/edit?reset_password_token=abcdef
|
13
|
+
# def edit
|
14
|
+
# super
|
15
|
+
# end
|
16
|
+
|
17
|
+
# PUT /resource/password
|
18
|
+
# def update
|
19
|
+
# super
|
20
|
+
# end
|
21
|
+
|
22
|
+
# protected
|
23
|
+
|
24
|
+
# def after_resetting_password_path_for(resource)
|
25
|
+
# super(resource)
|
26
|
+
# end
|
27
|
+
|
28
|
+
# The path used after sending reset password instructions
|
29
|
+
# def after_sending_reset_password_instructions_path_for(resource_name)
|
30
|
+
# super(resource_name)
|
31
|
+
# end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsController
|
2
|
+
# before_filter :configure_sign_up_params, only: [:create]
|
3
|
+
# before_filter :configure_account_update_params, only: [:update]
|
4
|
+
|
5
|
+
# GET /resource/sign_up
|
6
|
+
# def new
|
7
|
+
# super
|
8
|
+
# end
|
9
|
+
|
10
|
+
# POST /resource
|
11
|
+
# def create
|
12
|
+
# super
|
13
|
+
# end
|
14
|
+
|
15
|
+
# GET /resource/edit
|
16
|
+
# def edit
|
17
|
+
# super
|
18
|
+
# end
|
19
|
+
|
20
|
+
# PUT /resource
|
21
|
+
# def update
|
22
|
+
# super
|
23
|
+
# end
|
24
|
+
|
25
|
+
# DELETE /resource
|
26
|
+
# def destroy
|
27
|
+
# super
|
28
|
+
# end
|
29
|
+
|
30
|
+
# GET /resource/cancel
|
31
|
+
# Forces the session data which is usually expired after sign
|
32
|
+
# in to be expired now. This is useful if the user wants to
|
33
|
+
# cancel oauth signing in/up in the middle of the process,
|
34
|
+
# removing all OAuth session data.
|
35
|
+
# def cancel
|
36
|
+
# super
|
37
|
+
# end
|
38
|
+
|
39
|
+
# protected
|
40
|
+
|
41
|
+
# You can put the params you want to permit in the empty array.
|
42
|
+
# def configure_sign_up_params
|
43
|
+
# devise_parameter_sanitizer.for(:sign_up) << :attribute
|
44
|
+
# end
|
45
|
+
|
46
|
+
# You can put the params you want to permit in the empty array.
|
47
|
+
# def configure_account_update_params
|
48
|
+
# devise_parameter_sanitizer.for(:account_update) << :attribute
|
49
|
+
# end
|
50
|
+
|
51
|
+
# The path used after sign up.
|
52
|
+
# def after_sign_up_path_for(resource)
|
53
|
+
# super(resource)
|
54
|
+
# end
|
55
|
+
|
56
|
+
# The path used after sign up for inactive accounts.
|
57
|
+
# def after_inactive_sign_up_path_for(resource)
|
58
|
+
# super(resource)
|
59
|
+
# end
|
60
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class <%= @scope_prefix %>SessionsController < Devise::SessionsController
|
2
|
+
# before_filter :configure_sign_in_params, only: [:create]
|
3
|
+
|
4
|
+
# GET /resource/sign_in
|
5
|
+
# def new
|
6
|
+
# super
|
7
|
+
# end
|
8
|
+
|
9
|
+
# POST /resource/sign_in
|
10
|
+
# def create
|
11
|
+
# super
|
12
|
+
# end
|
13
|
+
|
14
|
+
# DELETE /resource/sign_out
|
15
|
+
# def destroy
|
16
|
+
# super
|
17
|
+
# end
|
18
|
+
|
19
|
+
# protected
|
20
|
+
|
21
|
+
# You can put the params you want to permit in the empty array.
|
22
|
+
# def configure_sign_in_params
|
23
|
+
# devise_parameter_sanitizer.for(:sign_in) << :attribute
|
24
|
+
# end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class <%= @scope_prefix %>UnlocksController < Devise::UnlocksController
|
2
|
+
# GET /resource/unlock/new
|
3
|
+
# def new
|
4
|
+
# super
|
5
|
+
# end
|
6
|
+
|
7
|
+
# POST /resource/unlock
|
8
|
+
# def create
|
9
|
+
# super
|
10
|
+
# end
|
11
|
+
|
12
|
+
# GET /resource/unlock?unlock_token=abcdef
|
13
|
+
# def show
|
14
|
+
# super
|
15
|
+
# end
|
16
|
+
|
17
|
+
# protected
|
18
|
+
|
19
|
+
# The path used after sending unlock password instructions
|
20
|
+
# def after_sending_unlock_instructions_path_for(resource)
|
21
|
+
# super(resource)
|
22
|
+
# end
|
23
|
+
|
24
|
+
# The path used after unlocking the resource
|
25
|
+
# def after_unlock_path_for(resource)
|
26
|
+
# super(resource)
|
27
|
+
# end
|
28
|
+
end
|
@@ -65,7 +65,7 @@ Devise.setup do |config|
|
|
65
65
|
# :database = Support basic authentication with authentication key + password
|
66
66
|
# config.http_authenticatable = false
|
67
67
|
|
68
|
-
# If
|
68
|
+
# If 401 status code should be returned for AJAX requests. True by default.
|
69
69
|
# config.http_authenticatable_on_xhr = true
|
70
70
|
|
71
71
|
# The realm used in Http Basic Authentication. 'Application' by default.
|
@@ -183,7 +183,7 @@ Devise.setup do |config|
|
|
183
183
|
# config.unlock_in = 1.hour
|
184
184
|
|
185
185
|
# Warn on the last attempt before the account is locked.
|
186
|
-
# config.last_attempt_warning =
|
186
|
+
# config.last_attempt_warning = true
|
187
187
|
|
188
188
|
# ==> Configuration for :recoverable
|
189
189
|
#
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
<div class="form-inputs">
|
7
7
|
<%= f.input :email, required: true, autofocus: true %>
|
8
|
-
<%= f.input :password, required: true %>
|
8
|
+
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @validatable) %>
|
9
9
|
<%= f.input :password_confirmation, required: true %>
|
10
10
|
</div>
|
11
11
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<h2>
|
1
|
+
<h2>Log in</h2>
|
2
2
|
|
3
3
|
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
4
4
|
<div class="form-inputs">
|
@@ -8,7 +8,7 @@
|
|
8
8
|
</div>
|
9
9
|
|
10
10
|
<div class="form-actions">
|
11
|
-
<%= f.button :submit, "
|
11
|
+
<%= f.button :submit, "Log in" %>
|
12
12
|
</div>
|
13
13
|
<% end %>
|
14
14
|
|
@@ -13,6 +13,12 @@ class RoutesTest < ActionController::TestCase
|
|
13
13
|
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
14
14
|
send(:"#{prepend_path}user_#{name}_url")
|
15
15
|
|
16
|
+
# With string
|
17
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", "user"),
|
18
|
+
send(:"#{prepend_path}user_#{name}_path")
|
19
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", "user"),
|
20
|
+
send(:"#{prepend_path}user_#{name}_url")
|
21
|
+
|
16
22
|
# Default url params
|
17
23
|
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
|
18
24
|
send(:"#{prepend_path}user_#{name}_path", param: 123)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ControllersGeneratorTest < Rails::Generators::TestCase
|
4
|
+
tests Devise::Generators::ControllersGenerator
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
6
|
+
setup :prepare_destination
|
7
|
+
|
8
|
+
test "Assert no controllers are created with no params" do
|
9
|
+
capture(:stderr) { run_generator }
|
10
|
+
assert_no_file "app/controllers/sessions_controller.rb"
|
11
|
+
assert_no_file "app/controllers/registrations_controller.rb"
|
12
|
+
assert_no_file "app/controllers/confirmations_controller.rb"
|
13
|
+
assert_no_file "app/controllers/passwords_controller.rb"
|
14
|
+
assert_no_file "app/controllers/unlocks_controller.rb"
|
15
|
+
assert_no_file "app/controllers/omniauth_callbacks_controller.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
test "Assert all controllers are properly created with scope param" do
|
19
|
+
run_generator %w(users)
|
20
|
+
assert_class_names 'users'
|
21
|
+
|
22
|
+
run_generator %w(admins)
|
23
|
+
assert_class_names 'admins'
|
24
|
+
end
|
25
|
+
|
26
|
+
test "Assert specified controllers with scope" do
|
27
|
+
run_generator %w(users -c sessions)
|
28
|
+
assert_file "app/controllers/users/sessions_controller.rb"
|
29
|
+
assert_no_file "app/controllers/users/registrations_controller.rb"
|
30
|
+
assert_no_file "app/controllers/users/confirmations_controller.rb"
|
31
|
+
assert_no_file "app/controllers/users/passwords_controller.rb"
|
32
|
+
assert_no_file "app/controllers/users/unlocks_controller.rb"
|
33
|
+
assert_no_file "app/controllers/users/omniauth_callbacks_controller.rb"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def assert_class_names(scope, options = {})
|
39
|
+
base_dir = "app/controllers#{scope.blank? ? '' : ('/' + scope)}"
|
40
|
+
scope_prefix = scope.blank? ? '' : (scope.camelize + '::')
|
41
|
+
controllers = options[:controllers] ||
|
42
|
+
%w(confirmations passwords registrations sessions unlocks omniauth_callbacks)
|
43
|
+
|
44
|
+
controllers.each do |c|
|
45
|
+
assert_file "#{base_dir}/#{c}_controller.rb", /#{scope_prefix + c.camelize}/
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -78,7 +78,7 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
|
|
78
78
|
assert_file "app/views/#{scope}/registrations/new.html.erb"
|
79
79
|
assert_file "app/views/#{scope}/registrations/edit.html.erb"
|
80
80
|
assert_file "app/views/#{scope}/sessions/new.html.erb"
|
81
|
-
assert_file "app/views/#{scope}/shared/_links.erb"
|
81
|
+
assert_file "app/views/#{scope}/shared/_links.html.erb"
|
82
82
|
assert_file "app/views/#{scope}/unlocks/new.html.erb"
|
83
83
|
end
|
84
84
|
|
@@ -2,25 +2,22 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class DeviseHelperTest < ActionDispatch::IntegrationTest
|
4
4
|
setup do
|
5
|
-
model_labels = { models: { user: "
|
6
|
-
|
7
|
-
# breaks the custom locale.
|
8
|
-
I18n.available_locales += [:fr]
|
9
|
-
I18n.backend.store_translations :fr,
|
10
|
-
{
|
5
|
+
model_labels = { models: { user: "the user" } }
|
6
|
+
translations = {
|
11
7
|
errors: { messages: { not_saved: {
|
12
|
-
one: "
|
13
|
-
other: "
|
8
|
+
one: "Can't save %{resource} because of 1 error",
|
9
|
+
other: "Can't save %{resource} because of %{count} errors",
|
14
10
|
} } },
|
15
11
|
activerecord: model_labels,
|
16
12
|
mongoid: model_labels
|
17
13
|
}
|
18
14
|
|
19
|
-
I18n.
|
15
|
+
I18n.available_locales
|
16
|
+
I18n.backend.store_translations(:en, translations)
|
20
17
|
end
|
21
18
|
|
22
19
|
teardown do
|
23
|
-
I18n.
|
20
|
+
I18n.reload!
|
24
21
|
end
|
25
22
|
|
26
23
|
test 'test errors.messages.not_saved with single error from i18n' do
|
@@ -31,7 +28,7 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest
|
|
31
28
|
click_button 'Sign up'
|
32
29
|
|
33
30
|
assert_have_selector '#error_explanation'
|
34
|
-
assert_contain "
|
31
|
+
assert_contain "Can't save the user because of 1 error"
|
35
32
|
end
|
36
33
|
|
37
34
|
test 'test errors.messages.not_saved with multiple errors from i18n' do
|
@@ -47,6 +44,6 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest
|
|
47
44
|
click_button 'Sign up'
|
48
45
|
|
49
46
|
assert_have_selector '#error_explanation'
|
50
|
-
assert_contain "
|
47
|
+
assert_contain "Can't save the user because of 2 errors"
|
51
48
|
end
|
52
49
|
end
|
@@ -580,7 +580,7 @@ class AuthenticationKeysTest < ActionDispatch::IntegrationTest
|
|
580
580
|
test 'missing authentication keys cause authentication to abort' do
|
581
581
|
swap Devise, authentication_keys: [:subdomain] do
|
582
582
|
sign_in_as_user
|
583
|
-
assert_contain "Invalid
|
583
|
+
assert_contain "Invalid subdomain or password."
|
584
584
|
assert_not warden.authenticated?(:user)
|
585
585
|
end
|
586
586
|
end
|
@@ -42,7 +42,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
|
42
42
|
sign_in_as_new_user_with_http("unknown")
|
43
43
|
assert_equal 401, status
|
44
44
|
assert_equal "application/xml; charset=utf-8", headers["Content-Type"]
|
45
|
-
assert_match "<error>Invalid email
|
45
|
+
assert_match "<error>Invalid email or password.</error>", response.body
|
46
46
|
end
|
47
47
|
|
48
48
|
test 'returns a custom response with www-authenticate and chosen realm' do
|
data/test/mapping_test.rb
CHANGED
@@ -62,6 +62,7 @@ class MappingTest < ActiveSupport::TestCase
|
|
62
62
|
test 'find scope for a given object' do
|
63
63
|
assert_equal :user, Devise::Mapping.find_scope!(User)
|
64
64
|
assert_equal :user, Devise::Mapping.find_scope!(:user)
|
65
|
+
assert_equal :user, Devise::Mapping.find_scope!("user")
|
65
66
|
assert_equal :user, Devise::Mapping.find_scope!(User.new)
|
66
67
|
end
|
67
68
|
|
@@ -10,4 +10,14 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
|
10
10
|
assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user
|
11
11
|
assert_nil User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id.to_s.next)
|
12
12
|
end
|
13
|
+
|
14
|
+
if defined?(ActionController::Parameters)
|
15
|
+
test 'does not passes an ActionController::Parameters to find_first_by_auth_conditions through find_or_initialize_with_errors' do
|
16
|
+
user = create_user(email: 'example@example.com')
|
17
|
+
attributes = ActionController::Parameters.new(email: 'example@example.com')
|
18
|
+
|
19
|
+
User.expects(:find_first_by_auth_conditions).with('email' => 'example@example.com').returns(user)
|
20
|
+
User.find_or_initialize_with_errors([:email], attributes)
|
21
|
+
end
|
22
|
+
end
|
13
23
|
end
|
@@ -224,10 +224,11 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
224
224
|
end
|
225
225
|
|
226
226
|
test 'should be active when we set allow_unconfirmed_access_for to nil' do
|
227
|
-
Devise
|
228
|
-
|
229
|
-
|
230
|
-
|
227
|
+
swap Devise, allow_unconfirmed_access_for: nil do
|
228
|
+
user = create_user
|
229
|
+
user.confirmation_sent_at = Date.today
|
230
|
+
assert user.active_for_authentication?
|
231
|
+
end
|
231
232
|
end
|
232
233
|
|
233
234
|
test 'should not be active without confirmation' do
|