devise 3.3.0 → 3.4.0

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +23 -1
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +81 -55
  6. data/README.md +28 -5
  7. data/app/controllers/devise/confirmations_controller.rb +1 -1
  8. data/app/views/devise/shared/{_links.erb → _links.html.erb} +0 -0
  9. data/config/locales/en.yml +2 -2
  10. data/devise.gemspec +1 -0
  11. data/gemfiles/Gemfile.rails-3.2-stable.lock +5 -2
  12. data/gemfiles/Gemfile.rails-4.0-stable.lock +25 -22
  13. data/gemfiles/{Gemfile.rails-head → Gemfile.rails-4.1-stable} +2 -5
  14. data/gemfiles/{Gemfile.rails-head.lock → Gemfile.rails-4.1-stable.lock} +45 -65
  15. data/lib/devise.rb +2 -1
  16. data/lib/devise/failure_app.rb +6 -1
  17. data/lib/devise/mapping.rb +1 -1
  18. data/lib/devise/models/authenticatable.rb +8 -2
  19. data/lib/devise/models/lockable.rb +2 -2
  20. data/lib/devise/rails/routes.rb +6 -9
  21. data/lib/devise/strategies/authenticatable.rb +1 -2
  22. data/lib/devise/strategies/database_authenticatable.rb +1 -0
  23. data/lib/devise/strategies/rememberable.rb +6 -3
  24. data/lib/devise/version.rb +1 -1
  25. data/lib/generators/active_record/devise_generator.rb +2 -1
  26. data/lib/generators/devise/controllers_generator.rb +44 -0
  27. data/lib/generators/templates/controllers/README +14 -0
  28. data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
  29. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
  30. data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
  31. data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
  32. data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
  33. data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
  34. data/lib/generators/templates/devise.rb +2 -2
  35. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  36. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +2 -2
  37. data/test/controllers/url_helpers_test.rb +6 -0
  38. data/test/generators/controllers_generator_test.rb +48 -0
  39. data/test/generators/views_generator_test.rb +1 -1
  40. data/test/helpers/devise_helper_test.rb +9 -12
  41. data/test/integration/authenticatable_test.rb +1 -1
  42. data/test/integration/http_authenticatable_test.rb +1 -1
  43. data/test/mapping_test.rb +1 -0
  44. data/test/models/authenticatable_test.rb +10 -0
  45. data/test/models/confirmable_test.rb +5 -4
  46. data/test/models/lockable_test.rb +16 -10
  47. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
  48. data/test/rails_app/app/mailers/users/mailer.rb +0 -9
  49. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
  50. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +2 -2
  51. data/test/support/helpers.rb +9 -6
  52. data/test/test_helper.rb +5 -0
  53. metadata +33 -5
@@ -2,10 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem "rails", github: "rails/rails"
6
- gem "arel", github: "rails/arel"
7
- gem "rack", github: "rack/rack"
8
- gem "i18n", github: "svenfuchs/i18n"
5
+ gem "rails", github: 'rails/rails', branch: '4-1-stable'
9
6
  gem "omniauth", "~> 1.2.0"
10
7
  gem "omniauth-oauth2", "~> 1.1.0"
11
8
  gem "rdoc"
@@ -28,5 +25,5 @@ platforms :ruby do
28
25
  end
29
26
 
30
27
  group :mongoid do
31
- gem "mongoid", github: "mongoid/mongoid", branch: "master"
28
+ gem "mongoid", "~> 4.0.0"
32
29
  end
@@ -1,91 +1,65 @@
1
- GIT
2
- remote: git://github.com/mongoid/mongoid.git
3
- revision: 8cb17e9839973b76295cf87189e91a5ffcc03ab0
4
- branch: master
5
- specs:
6
- mongoid (4.0.0)
7
- activemodel (~> 4.0)
8
- moped (~> 2.0.0)
9
- origin (~> 2.1)
10
- tzinfo (>= 0.3.37)
11
-
12
- GIT
13
- remote: git://github.com/rack/rack.git
14
- revision: 92811eec6e86cb4dba52b3969c4dd66e639df158
15
- specs:
16
- rack (1.6.0.alpha)
17
-
18
- GIT
19
- remote: git://github.com/rails/arel.git
20
- revision: 66cee768bc163537087037a583f60639eae49fc3
21
- specs:
22
- arel (6.0.0.20140505020427)
23
-
24
1
  GIT
25
2
  remote: git://github.com/rails/rails.git
26
- revision: d5be08347fb7ff758572775ec93247a3ca886004
3
+ revision: 90b70cd453e6b88b2ad484861ad9913f70bd15c9
4
+ branch: 4-1-stable
27
5
  specs:
28
- actionmailer (4.2.0.alpha)
29
- actionpack (= 4.2.0.alpha)
30
- actionview (= 4.2.0.alpha)
6
+ actionmailer (4.1.5)
7
+ actionpack (= 4.1.5)
8
+ actionview (= 4.1.5)
31
9
  mail (~> 2.5, >= 2.5.4)
32
- actionpack (4.2.0.alpha)
33
- actionview (= 4.2.0.alpha)
34
- activesupport (= 4.2.0.alpha)
35
- rack (~> 1.6.0.alpha)
10
+ actionpack (4.1.5)
11
+ actionview (= 4.1.5)
12
+ activesupport (= 4.1.5)
13
+ rack (~> 1.5.2)
36
14
  rack-test (~> 0.6.2)
37
- actionview (4.2.0.alpha)
38
- activesupport (= 4.2.0.alpha)
15
+ actionview (4.1.5)
16
+ activesupport (= 4.1.5)
39
17
  builder (~> 3.1)
40
18
  erubis (~> 2.7.0)
41
- activemodel (4.2.0.alpha)
42
- activesupport (= 4.2.0.alpha)
19
+ activemodel (4.1.5)
20
+ activesupport (= 4.1.5)
43
21
  builder (~> 3.1)
44
- activerecord (4.2.0.alpha)
45
- activemodel (= 4.2.0.alpha)
46
- activesupport (= 4.2.0.alpha)
47
- arel (~> 6.0.0)
48
- activesupport (4.2.0.alpha)
49
- i18n (>= 0.7.0.dev, < 0.8)
22
+ activerecord (4.1.5)
23
+ activemodel (= 4.1.5)
24
+ activesupport (= 4.1.5)
25
+ arel (~> 5.0.0)
26
+ activesupport (4.1.5)
27
+ i18n (~> 0.6, >= 0.6.9)
50
28
  json (~> 1.7, >= 1.7.7)
51
29
  minitest (~> 5.1)
52
30
  thread_safe (~> 0.1)
53
31
  tzinfo (~> 1.1)
54
- rails (4.2.0.alpha)
55
- actionmailer (= 4.2.0.alpha)
56
- actionpack (= 4.2.0.alpha)
57
- actionview (= 4.2.0.alpha)
58
- activemodel (= 4.2.0.alpha)
59
- activerecord (= 4.2.0.alpha)
60
- activesupport (= 4.2.0.alpha)
32
+ rails (4.1.5)
33
+ actionmailer (= 4.1.5)
34
+ actionpack (= 4.1.5)
35
+ actionview (= 4.1.5)
36
+ activemodel (= 4.1.5)
37
+ activerecord (= 4.1.5)
38
+ activesupport (= 4.1.5)
61
39
  bundler (>= 1.3.0, < 2.0)
62
- railties (= 4.2.0.alpha)
63
- sprockets-rails (~> 2.1)
64
- railties (4.2.0.alpha)
65
- actionpack (= 4.2.0.alpha)
66
- activesupport (= 4.2.0.alpha)
40
+ railties (= 4.1.5)
41
+ sprockets-rails (~> 2.0)
42
+ railties (4.1.5)
43
+ actionpack (= 4.1.5)
44
+ activesupport (= 4.1.5)
67
45
  rake (>= 0.8.7)
68
46
  thor (>= 0.18.1, < 2.0)
69
47
 
70
- GIT
71
- remote: git://github.com/svenfuchs/i18n.git
72
- revision: cb679b8cdbab675703a3f88de4d48a48f7b50e06
73
- specs:
74
- i18n (0.7.0.dev)
75
-
76
48
  PATH
77
49
  remote: ..
78
50
  specs:
79
- devise (3.3.0)
51
+ devise (3.4.0)
80
52
  bcrypt (~> 3.0)
81
53
  orm_adapter (~> 0.1)
82
54
  railties (>= 3.2.6, < 5)
55
+ responders
83
56
  thread_safe (~> 0.1)
84
57
  warden (~> 1.2.3)
85
58
 
86
59
  GEM
87
60
  remote: https://rubygems.org/
88
61
  specs:
62
+ arel (5.0.1.20140414130214)
89
63
  bcrypt (3.1.7)
90
64
  bson (2.3.0)
91
65
  builder (3.2.2)
@@ -95,6 +69,7 @@ GEM
95
69
  multipart-post (>= 1.2, < 3)
96
70
  hashie (3.2.0)
97
71
  hike (1.2.3)
72
+ i18n (0.6.11)
98
73
  json (1.8.1)
99
74
  jwt (1.0.0)
100
75
  mail (2.6.1)
@@ -105,6 +80,11 @@ GEM
105
80
  minitest (5.4.0)
106
81
  mocha (1.1.0)
107
82
  metaclass (~> 0.0.1)
83
+ mongoid (4.0.0)
84
+ activemodel (~> 4.0)
85
+ moped (~> 2.0.0)
86
+ origin (~> 2.1)
87
+ tzinfo (>= 0.3.37)
108
88
  moped (2.0.0)
109
89
  bson (~> 2.2)
110
90
  connection_pool (~> 2.0)
@@ -136,6 +116,7 @@ GEM
136
116
  optionable (0.2.0)
137
117
  origin (2.1.1)
138
118
  orm_adapter (0.5.0)
119
+ rack (1.5.2)
139
120
  rack-openid (1.3.1)
140
121
  rack (>= 1.1.0)
141
122
  ruby-openid (>= 2.1.8)
@@ -144,6 +125,8 @@ GEM
144
125
  rake (10.3.2)
145
126
  rdoc (4.1.1)
146
127
  json (~> 1.4)
128
+ responders (1.1.1)
129
+ railties (>= 3.2, < 4.2)
147
130
  ruby-openid (2.5.0)
148
131
  sprockets (2.12.1)
149
132
  hike (~> 1.2)
@@ -158,7 +141,7 @@ GEM
158
141
  thor (0.19.1)
159
142
  thread_safe (0.3.4)
160
143
  tilt (1.4.1)
161
- tzinfo (1.2.1)
144
+ tzinfo (1.2.2)
162
145
  thread_safe (~> 0.1)
163
146
  warden (1.2.3)
164
147
  rack (>= 1.0)
@@ -173,17 +156,14 @@ PLATFORMS
173
156
  DEPENDENCIES
174
157
  activerecord-jdbc-adapter
175
158
  activerecord-jdbcsqlite3-adapter
176
- arel!
177
159
  devise!
178
- i18n!
179
160
  jruby-openssl
180
161
  mocha (~> 1.1)
181
- mongoid!
162
+ mongoid (~> 4.0.0)
182
163
  omniauth (~> 1.2.0)
183
164
  omniauth-facebook
184
165
  omniauth-oauth2 (~> 1.1.0)
185
166
  omniauth-openid (~> 1.0.1)
186
- rack!
187
167
  rails!
188
168
  rdoc
189
169
  sqlite3
@@ -4,6 +4,7 @@ require 'active_support/dependencies'
4
4
  require 'orm_adapter'
5
5
  require 'set'
6
6
  require 'securerandom'
7
+ require 'responders'
7
8
 
8
9
  module Devise
9
10
  autoload :Delegator, 'devise/delegator'
@@ -280,7 +281,7 @@ module Devise
280
281
 
281
282
  # When true, warn user if they just used next-to-last attempt of authentication
282
283
  mattr_accessor :last_attempt_warning
283
- @@last_attempt_warning = false
284
+ @@last_attempt_warning = true
284
285
 
285
286
  # Stores the token generator
286
287
  mattr_accessor :token_generator
@@ -78,6 +78,7 @@ module Devise
78
78
  options[:resource_name] = scope
79
79
  options[:scope] = "devise.failure"
80
80
  options[:default] = [message]
81
+ options[:authentication_keys] = scope_class.authentication_keys.join(I18n.translate(:"support.array.words_connector"))
81
82
  options = i18n_options(options)
82
83
 
83
84
  I18n.t(:"#{scope}.#{message}", options)
@@ -144,7 +145,7 @@ module Devise
144
145
  # It does not make sense to send authenticate headers in ajax requests
145
146
  # or if the user disabled them.
146
147
  def http_auth_header?
147
- Devise.mappings[scope].to.http_authenticatable && !request.xhr?
148
+ scope_class.http_authenticatable && !request.xhr?
148
149
  end
149
150
 
150
151
  def http_auth_body
@@ -182,6 +183,10 @@ module Devise
182
183
  @scope ||= warden_options[:scope] || Devise.default_scope
183
184
  end
184
185
 
186
+ def scope_class
187
+ @scope_class ||= Devise.mappings[scope].to
188
+ end
189
+
185
190
  def attempted_path
186
191
  warden_options[:attempted_path]
187
192
  end
@@ -33,7 +33,7 @@ module Devise
33
33
  def self.find_scope!(obj)
34
34
  case obj
35
35
  when String, Symbol
36
- return obj
36
+ return obj.to_sym
37
37
  when Class
38
38
  Devise.mappings.each_value { |m| return m.name if obj <= m.to }
39
39
  else
@@ -170,7 +170,13 @@ module Devise
170
170
  # end
171
171
  #
172
172
  def send_devise_notification(notification, *args)
173
- devise_mailer.send(notification, self, *args).deliver
173
+ message = devise_mailer.send(notification, self, *args)
174
+ # Remove once we move to Rails 4.2+ only.
175
+ if message.respond_to?(:deliver_now)
176
+ message.deliver_now
177
+ else
178
+ message.deliver
179
+ end
174
180
  end
175
181
 
176
182
  def downcase_keys
@@ -253,7 +259,7 @@ module Devise
253
259
 
254
260
  # Find an initialize a group of attributes based on a list of required attributes.
255
261
  def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
256
- attributes = attributes.slice(*required_attributes)
262
+ attributes = attributes.slice(*required_attributes).with_indifferent_access
257
263
  attributes.delete_if { |key, value| value.blank? }
258
264
 
259
265
  if attributes.size == required_attributes.size
@@ -117,7 +117,7 @@ module Devise
117
117
  super
118
118
  elsif access_locked? || (lock_strategy_enabled?(:failed_attempts) && attempts_exceeded?)
119
119
  :locked
120
- elsif lock_strategy_enabled?(:failed_attempts) && last_attempt?
120
+ elsif lock_strategy_enabled?(:failed_attempts) && last_attempt? && self.class.last_attempt_warning
121
121
  :last_attempt
122
122
  else
123
123
  super
@@ -189,7 +189,7 @@ module Devise
189
189
  self.lock_strategy == strategy
190
190
  end
191
191
 
192
- Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in, :unlock_keys)
192
+ Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in, :unlock_keys, :last_attempt_warning)
193
193
  end
194
194
  end
195
195
  end
@@ -435,26 +435,23 @@ ERROR
435
435
 
436
436
  match "#{path_prefix}/:action/callback",
437
437
  constraints: { action: providers },
438
- to: controllers[:omniauth_callbacks],
438
+ to: "#{controllers[:omniauth_callbacks]}#:action",
439
439
  as: :omniauth_callback,
440
440
  via: [:get, :post]
441
441
  ensure
442
442
  @scope[:path] = path
443
443
  end
444
444
 
445
- DEVISE_SCOPE_KEYS = [:as, :path, :module, :constraints, :defaults, :options]
446
-
447
445
  def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
448
- old = {}
449
- DEVISE_SCOPE_KEYS.each { |k| old[k] = @scope[k] }
446
+ current_scope = @scope.dup
450
447
 
451
- new = { as: new_as, path: new_path, module: nil }
452
- new.merge!(options.slice(:constraints, :defaults, :options))
448
+ exclusive = { as: new_as, path: new_path, module: nil }
449
+ exclusive.merge!(options.slice(:constraints, :defaults, :options))
453
450
 
454
- @scope.merge!(new)
451
+ exclusive.each_pair { |key, value| @scope[key] = value }
455
452
  yield
456
453
  ensure
457
- @scope.merge!(old)
454
+ @scope = current_scope
458
455
  end
459
456
 
460
457
  def constraints_for(method_to_apply, scope=nil, block=nil)
@@ -36,7 +36,6 @@ module Devise
36
36
  result = resource && resource.valid_for_authentication?(&block)
37
37
 
38
38
  if result
39
- decorate(resource)
40
39
  true
41
40
  else
42
41
  if resource
@@ -47,7 +46,7 @@ module Devise
47
46
  end
48
47
 
49
48
  # Get values from params and set in the resource.
50
- def decorate(resource)
49
+ def remember_me(resource)
51
50
  resource.remember_me = remember_me? if resource.respond_to?(:remember_me=)
52
51
  end
53
52
 
@@ -9,6 +9,7 @@ module Devise
9
9
  encrypted = false
10
10
 
11
11
  if validate(resource){ encrypted = true; resource.valid_password?(password) }
12
+ remember_me(resource)
12
13
  resource.after_database_authentication
13
14
  success!(resource)
14
15
  end
@@ -25,15 +25,18 @@ module Devise
25
25
  end
26
26
 
27
27
  if validate(resource)
28
+ remember_me(resource)
29
+ extend_remember_me_period(resource)
28
30
  success!(resource)
29
31
  end
30
32
  end
31
33
 
32
34
  private
33
35
 
34
- def decorate(resource)
35
- super
36
- resource.extend_remember_period = mapping.to.extend_remember_period if resource.respond_to?(:extend_remember_period=)
36
+ def extend_remember_me_period(resource)
37
+ if resource.respond_to?(:extend_remember_period=)
38
+ resource.extend_remember_period = mapping.to.extend_remember_period
39
+ end
37
40
  end
38
41
 
39
42
  def remember_me?
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "3.3.0".freeze
2
+ VERSION = "3.4.0".freeze
3
3
  end
@@ -83,7 +83,8 @@ RUBY
83
83
  end
84
84
 
85
85
  def postgresql?
86
- ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
86
+ config = ActiveRecord::Base.configurations[Rails.env]
87
+ config && config['adapter'] == 'postgresql'
87
88
  end
88
89
  end
89
90
  end
@@ -0,0 +1,44 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Devise
4
+ module Generators
5
+ class ControllersGenerator < Rails::Generators::Base
6
+ CONTROLLERS = %w(confirmations passwords registrations sessions unlocks omniauth_callbacks).freeze
7
+
8
+ desc <<-DESC.strip_heredoc
9
+ Create inherited Devise controllers in your app/controllers folder.
10
+
11
+ User -c to specify which controller you want to overwrite.
12
+ If you do no specify a controller, all controllers will be created.
13
+ For example:
14
+
15
+ rails generate devise:controllers users -c=sessions
16
+
17
+ This will create a controller class at app/controllers/users/sessions_controller.rb like this:
18
+
19
+ class Users::ConfirmationsController < Devise::ConfirmationsController
20
+ content...
21
+ end
22
+ DESC
23
+
24
+ source_root File.expand_path("../../templates/controllers", __FILE__)
25
+ argument :scope, required: true,
26
+ desc: "The scope to create controllers in, e.g. users, admins"
27
+ class_option :controllers, aliases: "-c", type: :array,
28
+ desc: "Select specific controllers to generate (#{CONTROLLERS.join(', ')})"
29
+
30
+ def create_controllers
31
+ @scope_prefix = scope.blank? ? '' : (scope.camelize + '::')
32
+ controllers = options[:controllers] || CONTROLLERS
33
+ controllers.each do |name|
34
+ template "#{name}_controller.rb",
35
+ "app/controllers/#{scope}/#{name}_controller.rb"
36
+ end
37
+ end
38
+
39
+ def show_readme
40
+ readme "README" if behavior == :invoke
41
+ end
42
+ end
43
+ end
44
+ end