devise 3.2.2 → 3.2.3

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.

Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -1
  4. data/CHANGELOG.md +20 -9
  5. data/CONTRIBUTING.md +2 -2
  6. data/Gemfile +2 -4
  7. data/Gemfile.lock +2 -2
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +69 -30
  10. data/config/locales/en.yml +1 -1
  11. data/devise.gemspec +1 -1
  12. data/gemfiles/{Gemfile.rails-3.2.x → Gemfile.rails-3.2-stable} +3 -5
  13. data/gemfiles/Gemfile.rails-4.0-stable +29 -0
  14. data/gemfiles/Gemfile.rails-head +29 -0
  15. data/lib/devise.rb +3 -3
  16. data/lib/devise/controllers/helpers.rb +1 -1
  17. data/lib/devise/controllers/scoped_views.rb +1 -1
  18. data/lib/devise/controllers/sign_in_out.rb +1 -1
  19. data/lib/devise/hooks/activatable.rb +3 -3
  20. data/lib/devise/hooks/proxy.rb +1 -1
  21. data/lib/devise/hooks/rememberable.rb +1 -1
  22. data/lib/devise/models/authenticatable.rb +2 -2
  23. data/lib/devise/models/confirmable.rb +2 -2
  24. data/lib/devise/models/lockable.rb +7 -4
  25. data/lib/devise/models/rememberable.rb +1 -1
  26. data/lib/devise/models/timeoutable.rb +2 -2
  27. data/lib/devise/modules.rb +1 -1
  28. data/lib/devise/orm/active_record.rb +1 -1
  29. data/lib/devise/orm/mongoid.rb +1 -1
  30. data/lib/devise/rails.rb +7 -1
  31. data/lib/devise/rails/routes.rb +16 -4
  32. data/lib/devise/strategies/authenticatable.rb +4 -4
  33. data/lib/devise/strategies/base.rb +1 -1
  34. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  35. data/lib/devise/time_inflector.rb +1 -1
  36. data/lib/devise/version.rb +1 -1
  37. data/lib/generators/active_record/devise_generator.rb +2 -2
  38. data/lib/generators/devise/install_generator.rb +4 -0
  39. data/lib/generators/templates/README +2 -2
  40. data/lib/generators/templates/devise.rb +8 -4
  41. data/test/controllers/internal_helpers_test.rb +5 -2
  42. data/test/controllers/sessions_controller_test.rb +14 -10
  43. data/test/generators/mongoid_generator_test.rb +2 -2
  44. data/test/integration/recoverable_test.rb +7 -7
  45. data/test/integration/registerable_test.rb +9 -9
  46. data/test/integration/rememberable_test.rb +2 -2
  47. data/test/integration/trackable_test.rb +1 -1
  48. data/test/mapping_test.rb +3 -3
  49. data/test/models/confirmable_test.rb +1 -1
  50. data/test/models/database_authenticatable_test.rb +1 -1
  51. data/test/models/lockable_test.rb +24 -6
  52. data/test/models/recoverable_test.rb +3 -3
  53. data/test/omniauth/config_test.rb +1 -1
  54. data/test/orm/mongoid.rb +1 -1
  55. data/test/rails_app/app/active_record/shim.rb +1 -1
  56. data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
  57. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
  58. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
  59. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +1 -1
  60. data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
  61. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
  62. data/test/rails_app/app/views/home/index.html.erb +1 -1
  63. data/test/rails_app/app/views/home/join.html.erb +1 -1
  64. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
  65. data/test/rails_app/config/initializers/devise.rb +2 -2
  66. data/test/rails_app/config/routes.rb +2 -1
  67. data/test/routes_test.rb +12 -0
  68. data/test/support/action_controller/record_identifier.rb +10 -0
  69. data/test/support/mongoid.yml +6 -0
  70. data/test/test_helpers_test.rb +2 -2
  71. metadata +30 -37
  72. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
@@ -0,0 +1,29 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '..'
4
+
5
+ gem "rails", github: 'rails/rails'
6
+ gem "omniauth", "~> 1.0.0"
7
+ gem "omniauth-oauth2", "~> 1.0.0"
8
+ gem "rdoc"
9
+
10
+ group :test do
11
+ gem "omniauth-facebook"
12
+ gem "omniauth-openid", "~> 1.0.1"
13
+ gem "webrat", "0.7.3", :require => false
14
+ gem "mocha", "~> 0.14", :require => false
15
+ end
16
+
17
+ platforms :jruby do
18
+ gem "activerecord-jdbc-adapter"
19
+ gem "activerecord-jdbcsqlite3-adapter"
20
+ gem "jruby-openssl"
21
+ end
22
+
23
+ platforms :ruby do
24
+ gem "sqlite3"
25
+ end
26
+
27
+ group :mongoid do
28
+ gem "mongoid", github: "mongoid/mongoid", branch: "master"
29
+ end
@@ -236,12 +236,12 @@ module Devise
236
236
  @@parent_mailer = "ActionMailer::Base"
237
237
 
238
238
  # The router Devise should use to generate routes. Defaults
239
- # to :main_app. Should be overriden by engines in order
239
+ # to :main_app. Should be overridden by engines in order
240
240
  # to provide custom routes.
241
241
  mattr_accessor :router_name
242
242
  @@router_name = nil
243
243
 
244
- # Set the omniauth path prefix so it can be overriden when
244
+ # Set the omniauth path prefix so it can be overridden when
245
245
  # Devise is used in a mountable engine
246
246
  mattr_accessor :omniauth_path_prefix
247
247
  @@omniauth_path_prefix = nil
@@ -274,7 +274,7 @@ module Devise
274
274
  mattr_accessor :paranoid
275
275
  @@paranoid = false
276
276
 
277
- # When true, warn user if he just used next-to-last attempt of authentication
277
+ # When true, warn user if they just used next-to-last attempt of authentication
278
278
  mattr_accessor :last_attempt_warning
279
279
  @@last_attempt_warning = false
280
280
 
@@ -98,7 +98,7 @@ module Devise
98
98
  request.env["devise.allow_params_authentication"] = true
99
99
  end
100
100
 
101
- # The scope root url to be used when he's signed in. By default, it first
101
+ # The scope root url to be used when they're signed in. By default, it first
102
102
  # tries to find a resource_root_path, otherwise it uses the root_path.
103
103
  def signed_in_root_path(resource_or_scope)
104
104
  scope = Devise::Mapping.find_scope!(resource_or_scope)
@@ -14,4 +14,4 @@ module Devise
14
14
  end
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -100,4 +100,4 @@ module Devise
100
100
  end
101
101
  end
102
102
  end
103
- end
103
+ end
@@ -1,6 +1,6 @@
1
- # Deny user access whenever his account is not active yet. All strategies that inherits from
1
+ # Deny user access whenever their account is not active yet. All strategies that inherits from
2
2
  # Devise::Strategies::Authenticatable and uses the validate already check if the user is active_for_authentication?
3
- # before actively signing him in. However, we need this as hook to validate the user activity
3
+ # before actively signing them in. However, we need this as hook to validate the user activity
4
4
  # in each request and in case the user is using other strategies beside Devise ones.
5
5
  Warden::Manager.after_set_user do |record, warden, options|
6
6
  if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication?
@@ -8,4 +8,4 @@ Warden::Manager.after_set_user do |record, warden, options|
8
8
  warden.logout(scope)
9
9
  throw :warden, :scope => scope, :message => record.inactive_message
10
10
  end
11
- end
11
+ end
@@ -18,4 +18,4 @@ module Devise
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -4,4 +4,4 @@ Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
4
4
  record.remember_me && warden.authenticated?(scope)
5
5
  Devise::Hooks::Proxy.new(warden).remember_me(record)
6
6
  end
7
- end
7
+ end
@@ -56,7 +56,7 @@ module Devise
56
56
  BLACKLIST_FOR_SERIALIZATION = [:encrypted_password, :reset_password_token, :reset_password_sent_at,
57
57
  :remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip,
58
58
  :last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,
59
- :remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at, :authentication_token]
59
+ :remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]
60
60
 
61
61
  included do
62
62
  class_attribute :devise_modules, :instance_writer => false
@@ -127,7 +127,7 @@ module Devise
127
127
  end
128
128
 
129
129
  # This is an internal method called every time Devise needs
130
- # to send a notification/mail. This can be overriden if you
130
+ # to send a notification/mail. This can be overridden if you
131
131
  # need to customize the e-mail delivery logic. For instance,
132
132
  # if you are using a queue to deliver e-mails (delayed job,
133
133
  # sidekiq, resque, etc), you must add the delivery to the queue
@@ -9,7 +9,7 @@ module Devise
9
9
  #
10
10
  # Confirmable adds the following options to +devise+:
11
11
  #
12
- # * +allow_unconfirmed_access_for+: the time you want to allow the user to access his account
12
+ # * +allow_unconfirmed_access_for+: the time you want to allow the user to access their account
13
13
  # before confirming it. After this period, the user access is denied. You can
14
14
  # use this to let your user access some features of your application without
15
15
  # confirming the account, but blocking it after a certain period (ie 7 days).
@@ -152,7 +152,7 @@ module Devise
152
152
  protected
153
153
 
154
154
  # A callback method used to deliver confirmation
155
- # instructions on creation. This can be overriden
155
+ # instructions on creation. This can be overridden
156
156
  # in models to map to a nice sign up e-mail.
157
157
  def send_on_create_confirmation_instructions
158
158
  send_confirmation_instructions
@@ -34,10 +34,13 @@ module Devise
34
34
  end
35
35
 
36
36
  # Lock a user setting its locked_at to actual time.
37
- def lock_access!
37
+ # * +opts+: Hash options if you don't want to send email
38
+ # when you lock access, you could pass the next hash
39
+ # `{ :send_instructions => false } as option`.
40
+ def lock_access!(opts = { })
38
41
  self.locked_at = Time.now.utc
39
42
 
40
- if unlock_strategy_enabled?(:email)
43
+ if unlock_strategy_enabled?(:email) && opts.fetch(:send_instructions, true)
41
44
  send_unlock_instructions
42
45
  else
43
46
  save(:validate => false)
@@ -124,11 +127,11 @@ module Devise
124
127
  protected
125
128
 
126
129
  def attempts_exceeded?
127
- self.failed_attempts > self.class.maximum_attempts
130
+ self.failed_attempts >= self.class.maximum_attempts
128
131
  end
129
132
 
130
133
  def last_attempt?
131
- self.failed_attempts == self.class.maximum_attempts
134
+ self.failed_attempts == self.class.maximum_attempts - 1
132
135
  end
133
136
 
134
137
  # Tells if the lock is expired if :time unlock strategy is active
@@ -17,7 +17,7 @@ module Devise
17
17
  #
18
18
  # * +remember_for+: the time you want the user will be remembered without
19
19
  # asking for credentials. After this time the user will be blocked and
20
- # will have to enter his credentials again. This configuration is also
20
+ # will have to enter their credentials again. This configuration is also
21
21
  # used to calculate the expires time for the cookie created to remember
22
22
  # the user. By default remember_for is 2.weeks.
23
23
  #
@@ -2,9 +2,9 @@ require 'devise/hooks/timeoutable'
2
2
 
3
3
  module Devise
4
4
  module Models
5
- # Timeoutable takes care of verifyng whether a user session has already
5
+ # Timeoutable takes care of verifying whether a user session has already
6
6
  # expired or not. When a session expires after the configured time, the user
7
- # will be asked for credentials again, it means, he/she will be redirected
7
+ # will be asked for credentials again, it means, they will be redirected
8
8
  # to the sign in page.
9
9
  #
10
10
  # == Options
@@ -25,4 +25,4 @@ Devise.with_options :model => true do |d|
25
25
 
26
26
  # Stats for last, so we make sure the user is really signed in
27
27
  d.add_module :trackable
28
- end
28
+ end
@@ -1,3 +1,3 @@
1
1
  require 'orm_adapter/adapters/active_record'
2
2
 
3
- ActiveRecord::Base.extend Devise::Models
3
+ ActiveRecord::Base.extend Devise::Models
@@ -1,3 +1,3 @@
1
1
  require 'orm_adapter/adapters/mongoid'
2
2
 
3
- Mongoid::Document::ClassMethods.send :include, Devise::Models
3
+ Mongoid::Document::ClassMethods.send :include, Devise::Models
@@ -29,7 +29,13 @@ module Devise
29
29
  end
30
30
  end
31
31
 
32
- initializer "devise.secret_key" do
32
+ config.after_initialize do |app|
33
+ if app.respond_to?(:secrets)
34
+ Devise.secret_key ||= app.secrets.secret_key_base
35
+ elsif app.config.respond_to?(:secret_key_base)
36
+ Devise.secret_key ||= app.config.secret_key_base
37
+ end
38
+
33
39
  Devise.token_generator ||=
34
40
  if secret_key = Devise.secret_key
35
41
  Devise::TokenGenerator.new(
@@ -102,8 +102,11 @@ module ActionDispatch::Routing
102
102
  # * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
103
103
  # :password, :confirmation, :unlock.
104
104
  #
105
- # devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout',
106
- # :password => 'secret', :confirmation => 'verification', registration: 'register }
105
+ # devise_for :users, path_names: {
106
+ # sign_in: 'login', sign_out: 'logout',
107
+ # password: 'secret', confirmation: 'verification',
108
+ # registration: 'register', edit: 'edit/profile'
109
+ # }
107
110
  #
108
111
  # * :controllers => the controller which should be used. All routes by default points to Devise controllers.
109
112
  # However, if you want them to point to custom controller, you should do:
@@ -229,6 +232,14 @@ module ActionDispatch::Routing
229
232
  raise_no_devise_method_error!(mapping.class_name)
230
233
  end
231
234
 
235
+ if options[:controllers] && options[:controllers][:omniauth_callbacks]
236
+ unless mapping.omniauthable?
237
+ msg = "Mapping omniauth_callbacks on a resource that is not omniauthable\n"
238
+ msg << "Please add `devise :omniauthable` to the `#{mapping.class_name}` model"
239
+ raise msg
240
+ end
241
+ end
242
+
232
243
  routes = mapping.used_routes
233
244
 
234
245
  devise_scope mapping.name do
@@ -370,6 +381,7 @@ module ActionDispatch::Routing
370
381
  def devise_registration(mapping, controllers) #:nodoc:
371
382
  path_names = {
372
383
  :new => mapping.path_names[:sign_up],
384
+ :edit => mapping.path_names[:edit],
373
385
  :cancel => mapping.path_names[:cancel]
374
386
  }
375
387
 
@@ -393,13 +405,13 @@ and you have set #{mapping.fullpath.inspect}. You can work around by passing
393
405
  `skip: :omniauth_callbacks` and manually defining the routes. Here is an example:
394
406
 
395
407
  match "/users/auth/:provider",
396
- :constraints => { :provider => /\A(google|facebook)\z/ },
408
+ :constraints => { :provider => /google|facebook/ },
397
409
  :to => "devise/omniauth_callbacks#passthru",
398
410
  :as => :omniauth_authorize,
399
411
  :via => [:get, :post]
400
412
 
401
413
  match "/users/auth/:action/callback",
402
- :constraints => { :action => /\A(google|facebook)\z/ },
414
+ :constraints => { :action => /google|facebook/ },
403
415
  :to => "devise/omniauth_callbacks",
404
416
  :as => :omniauth_callback,
405
417
  :via => [:get, :post]
@@ -49,7 +49,7 @@ module Devise
49
49
  valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
50
50
  end
51
51
 
52
- # Check if this is strategy is valid for http authentication by:
52
+ # Check if this is a valid strategy for http authentication by:
53
53
  #
54
54
  # * Validating if the model allows params authentication;
55
55
  # * If any of the authorization headers were sent;
@@ -59,7 +59,7 @@ module Devise
59
59
  http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)
60
60
  end
61
61
 
62
- # Check if this is strategy is valid for params authentication by:
62
+ # Check if this is a valid strategy for params authentication by:
63
63
  #
64
64
  # * Validating if the model allows params authentication;
65
65
  # * If the request hits the sessions controller through POST;
@@ -102,9 +102,9 @@ module Devise
102
102
  params_auth_hash.is_a?(Hash)
103
103
  end
104
104
 
105
- # Check if password is present and is not equal to "X" (default value for token).
105
+ # Check if password is present.
106
106
  def valid_password?
107
- password.present? && password != "X"
107
+ password.present?
108
108
  end
109
109
 
110
110
  # Helper to decode credentials from HTTP.
@@ -17,4 +17,4 @@ module Devise
17
17
  end
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -2,7 +2,7 @@ require 'devise/strategies/authenticatable'
2
2
 
3
3
  module Devise
4
4
  module Strategies
5
- # Default strategy for signing in a user, based on his email and password in the database.
5
+ # Default strategy for signing in a user, based on their email and password in the database.
6
6
  class DatabaseAuthenticatable < Authenticatable
7
7
  def authenticate!
8
8
  resource = valid_password? && mapping.to.find_for_database_authentication(authentication_hash)
@@ -11,4 +11,4 @@ module Devise
11
11
 
12
12
  @instance = new
13
13
  end
14
- end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "3.2.2".freeze
2
+ VERSION = "3.2.3".freeze
3
3
  end
@@ -11,9 +11,9 @@ module ActiveRecord
11
11
 
12
12
  def copy_devise_migration
13
13
  if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
14
- migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
14
+ migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb"
15
15
  else
16
- migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
16
+ migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb"
17
17
  end
18
18
  end
19
19
 
@@ -20,6 +20,10 @@ module Devise
20
20
  def show_readme
21
21
  readme "README" if behavior == :invoke
22
22
  end
23
+
24
+ def rails_4?
25
+ Rails::VERSION::MAJOR == 4
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  Some setup you must do manually if you haven't yet:
4
4
 
5
- 1. Ensure you have defined default url options in your environments files. Here
6
- is an example of default_url_options appropriate for a development environment
5
+ 1. Ensure you have defined default url options in your environments files. Here
6
+ is an example of default_url_options appropriate for a development environment
7
7
  in config/environments/development.rb:
8
8
 
9
9
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
@@ -4,7 +4,11 @@ Devise.setup do |config|
4
4
  # The secret key used by Devise. Devise uses this key to generate
5
5
  # random tokens. Changing this key will render invalid all existing
6
6
  # confirmation, reset password and unlock tokens in the database.
7
+ <% if rails_4? -%>
8
+ # config.secret_key = '<%= SecureRandom.hex(64) %>'
9
+ <% else -%>
7
10
  config.secret_key = '<%= SecureRandom.hex(64) %>'
11
+ <% end -%>
8
12
 
9
13
  # ==> Mailer Configuration
10
14
  # Configure the e-mail address which will be shown in Devise::Mailer,
@@ -99,10 +103,10 @@ Devise.setup do |config|
99
103
 
100
104
  # ==> Configuration for :confirmable
101
105
  # A period that the user is allowed to access the website even without
102
- # confirming his account. For instance, if set to 2.days, the user will be
103
- # able to access the website for two days without confirming his account,
106
+ # confirming their account. For instance, if set to 2.days, the user will be
107
+ # able to access the website for two days without confirming their account,
104
108
  # access will be blocked just in the third day. Default is 0.days, meaning
105
- # the user cannot access the website without confirming his account.
109
+ # the user cannot access the website without confirming their account.
106
110
  # config.allow_unconfirmed_access_for = 2.days
107
111
 
108
112
  # A period that the user is allowed to confirm their account before their
@@ -134,7 +138,7 @@ Devise.setup do |config|
134
138
  # config.rememberable_options = {}
135
139
 
136
140
  # ==> Configuration for :validatable
137
- # Range for password length. Default is 8..128.
141
+ # Range for password length.
138
142
  config.password_length = 8..128
139
143
 
140
144
  # Email regex used to validate email formats. It simply asserts that
@@ -113,8 +113,11 @@ class HelpersTest < ActionController::TestCase
113
113
 
114
114
  test 'navigational_formats not returning a wild card' do
115
115
  MyController.send(:public, :navigational_formats)
116
- Devise.navigational_formats = [:"*/*", :html]
117
- assert_not @controller.navigational_formats.include?(:"*/*")
116
+
117
+ swap Devise, :navigational_formats => ['*/*', :html] do
118
+ assert_not @controller.navigational_formats.include?("*/*")
119
+ end
120
+
118
121
  MyController.send(:protected, :navigational_formats)
119
122
  end
120
123
  end
@@ -5,17 +5,21 @@ class SessionsControllerTest < ActionController::TestCase
5
5
  include Devise::TestHelpers
6
6
 
7
7
  test "#create doesn't raise unpermitted params when sign in fails" do
8
- ActiveSupport::Notifications.subscribe /unpermitted_parameters/ do |name, start, finish, id, payload|
9
- flunk "Unpermitted params: #{payload}"
8
+ begin
9
+ subscriber = ActiveSupport::Notifications.subscribe /unpermitted_parameters/ do |name, start, finish, id, payload|
10
+ flunk "Unpermitted params: #{payload}"
11
+ end
12
+ request.env["devise.mapping"] = Devise.mappings[:user]
13
+ request.session["user_return_to"] = 'foo.bar'
14
+ create_user
15
+ post :create, :user => {
16
+ :email => "wrong@email.com",
17
+ :password => "wrongpassword"
18
+ }
19
+ assert_equal 200, @response.status
20
+ ensure
21
+ ActiveSupport::Notifications.unsubscribe(subscriber)
10
22
  end
11
- request.env["devise.mapping"] = Devise.mappings[:user]
12
- request.session["user_return_to"] = 'foo.bar'
13
- create_user
14
- post :create, :user => {
15
- :email => "wrong@email.com",
16
- :password => "wrongpassword"
17
- }
18
- assert_equal 200, @response.status
19
23
  end
20
24
 
21
25
  test "#create works even with scoped views" do