devise 1.5.4 → 2.0.0.rc

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 (58) hide show
  1. data/.gitignore +0 -2
  2. data/CHANGELOG.rdoc +18 -7
  3. data/Gemfile.lock +168 -0
  4. data/README.rdoc +2 -0
  5. data/app/controllers/devise/registrations_controller.rb +6 -1
  6. data/app/controllers/devise/unlocks_controller.rb +1 -2
  7. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  8. data/config/locales/en.yml +1 -0
  9. data/lib/devise.rb +41 -22
  10. data/lib/devise/controllers/internal_helpers.rb +9 -2
  11. data/lib/devise/models/authenticatable.rb +30 -12
  12. data/lib/devise/models/confirmable.rb +73 -18
  13. data/lib/devise/models/database_authenticatable.rb +0 -11
  14. data/lib/devise/models/recoverable.rb +5 -5
  15. data/lib/devise/models/rememberable.rb +5 -20
  16. data/lib/devise/models/timeoutable.rb +1 -3
  17. data/lib/devise/models/token_authenticatable.rb +1 -4
  18. data/lib/devise/models/validatable.rb +1 -1
  19. data/lib/devise/orm/active_record.rb +6 -0
  20. data/lib/devise/param_filter.rb +2 -1
  21. data/lib/devise/rails.rb +31 -0
  22. data/lib/devise/schema.rb +5 -0
  23. data/lib/devise/strategies/authenticatable.rb +12 -8
  24. data/lib/devise/strategies/token_authenticatable.rb +3 -3
  25. data/lib/devise/version.rb +1 -1
  26. data/lib/generators/active_record/devise_generator.rb +40 -2
  27. data/lib/generators/active_record/templates/migration.rb +1 -9
  28. data/lib/generators/active_record/templates/migration_existing.rb +1 -9
  29. data/lib/generators/mongoid/devise_generator.rb +43 -0
  30. data/lib/generators/templates/devise.rb +15 -9
  31. data/test/controllers/internal_helpers_test.rb +4 -2
  32. data/test/devise_test.rb +2 -2
  33. data/test/integration/confirmable_test.rb +55 -3
  34. data/test/integration/http_authenticatable_test.rb +16 -1
  35. data/test/integration/lockable_test.rb +3 -3
  36. data/test/integration/registerable_test.rb +32 -1
  37. data/test/integration/rememberable_test.rb +0 -50
  38. data/test/integration/token_authenticatable_test.rb +2 -2
  39. data/test/integration/trackable_test.rb +1 -1
  40. data/test/mapping_test.rb +2 -3
  41. data/test/models/confirmable_test.rb +86 -8
  42. data/test/models/database_authenticatable_test.rb +6 -6
  43. data/test/models/encryptable_test.rb +1 -1
  44. data/test/models/recoverable_test.rb +0 -27
  45. data/test/models/rememberable_test.rb +41 -160
  46. data/test/models/serializable_test.rb +1 -1
  47. data/test/models_test.rb +7 -7
  48. data/test/rails_app/app/mongoid/admin.rb +22 -1
  49. data/test/rails_app/app/mongoid/user.rb +35 -0
  50. data/test/rails_app/config/initializers/devise.rb +6 -7
  51. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +58 -12
  52. data/test/rails_app/lib/shared_admin.rb +5 -2
  53. data/test/support/assertions.rb +4 -1
  54. data/test/support/integration.rb +3 -1
  55. data/test/test_helpers_test.rb +2 -2
  56. metadata +21 -39
  57. data/test/models/authenticatable_test.rb +0 -9
  58. data/test/schema_test.rb +0 -33
@@ -16,7 +16,7 @@ class SerializableTest < ActiveSupport::TestCase
16
16
  end
17
17
 
18
18
  test 'should include unsafe keys on XML if a force_except is provided' do
19
- assert_no_match /email/, @user.to_xml(:force_except => :email)
19
+ assert_no_match /<email/, @user.to_xml(:force_except => :email)
20
20
  assert_match /confirmation-token/, @user.to_xml(:force_except => :email)
21
21
  end
22
22
 
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  class Configurable < User
4
4
  devise :database_authenticatable, :encryptable, :confirmable, :rememberable, :timeoutable, :lockable,
5
- :stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days,
5
+ :stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
6
6
  :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
7
7
  end
8
8
 
@@ -39,7 +39,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
39
39
  end
40
40
 
41
41
  test 'can cherry pick modules' do
42
- assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
42
+ assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :encryptable, :confirmable
43
43
  end
44
44
 
45
45
  test 'validations options are not applied too late' do
@@ -55,12 +55,12 @@ class ActiveRecordTest < ActiveSupport::TestCase
55
55
  end
56
56
 
57
57
  test 'chosen modules are inheritable' do
58
- assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
58
+ assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :encryptable, :confirmable
59
59
  end
60
60
 
61
61
  test 'order of module inclusion' do
62
- correct_module_order = [:database_authenticatable, :rememberable, :encryptable, :recoverable, :registerable, :lockable, :timeoutable]
63
- incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :encryptable, :rememberable]
62
+ correct_module_order = [:database_authenticatable, :encryptable, :recoverable, :registerable, :confirmable, :lockable, :timeoutable]
63
+ incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :encryptable, :confirmable]
64
64
 
65
65
  assert_include_modules Admin, *incorrect_module_order
66
66
 
@@ -87,8 +87,8 @@ class ActiveRecordTest < ActiveSupport::TestCase
87
87
  assert_equal 'abcdef', Configurable.pepper
88
88
  end
89
89
 
90
- test 'set a default value for confirm_within' do
91
- assert_equal 5.days, Configurable.confirm_within
90
+ test 'set a default value for allow_unconfirmed_access_for' do
91
+ assert_equal 5.days, Configurable.allow_unconfirmed_access_for
92
92
  end
93
93
 
94
94
  test 'set a default value for remember_for' do
@@ -5,5 +5,26 @@ class Admin
5
5
  include Shim
6
6
  include SharedAdmin
7
7
 
8
- field :remember_token, :type => String
8
+ ## Database authenticatable
9
+ field :email, :type => String, :null => true
10
+ field :encrypted_password, :type => String, :null => true
11
+
12
+ ## Recoverable
13
+ field :reset_password_token, :type => String
14
+ field :reset_password_sent_at, :type => Time
15
+
16
+ ## Rememberable
17
+ field :remember_created_at, :type => Time
18
+
19
+ ## Confirmable
20
+ field :confirmation_token, :type => String
21
+ field :confirmed_at, :type => Time
22
+ field :confirmation_sent_at, :type => Time
23
+ field :unconfirmed_email, :type => String # Only if using reconfirmable
24
+
25
+ ## Encryptable
26
+ field :password_salt, :type => String
27
+
28
+ ## Lockable
29
+ field :locked_at, :type => Time
9
30
  end
@@ -7,4 +7,39 @@ class User
7
7
 
8
8
  field :username, :type => String
9
9
  field :facebook_token, :type => String
10
+
11
+ ## Database authenticatable
12
+ field :email, :type => String, :null => false, :default => ""
13
+ field :encrypted_password, :type => String, :null => false, :default => ""
14
+
15
+ ## Recoverable
16
+ field :reset_password_token, :type => String
17
+ field :reset_password_sent_at, :type => Time
18
+
19
+ ## Rememberable
20
+ field :remember_created_at, :type => Time
21
+
22
+ ## Trackable
23
+ field :sign_in_count, :type => Integer, :default => 0
24
+ field :current_sign_in_at, :type => Time
25
+ field :last_sign_in_at, :type => Time
26
+ field :current_sign_in_ip, :type => String
27
+ field :last_sign_in_ip, :type => String
28
+
29
+ ## Encryptable
30
+ # field :password_salt, :type => String
31
+
32
+ ## Confirmable
33
+ field :confirmation_token, :type => String
34
+ field :confirmed_at, :type => Time
35
+ field :confirmation_sent_at, :type => Time
36
+ # field :unconfirmed_email, :type => String # Only if using reconfirmable
37
+
38
+ ## Lockable
39
+ field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
40
+ field :unlock_token, :type => String # Only if unlock strategy is :email or :both
41
+ field :locked_at, :type => Time
42
+
43
+ # Token authenticatable
44
+ field :authentication_token, :type => String
10
45
  end
@@ -12,6 +12,9 @@ Devise.setup do |config|
12
12
  # Configure the class responsible to send e-mails.
13
13
  # config.mailer = "Devise::Mailer"
14
14
 
15
+ # Disable apply schema
16
+ config.apply_schema = false
17
+
15
18
  # ==> ORM configuration
16
19
  # Load and configure the ORM. Supports :active_record (default) and
17
20
  # :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -60,16 +63,16 @@ Devise.setup do |config|
60
63
  # ==> Configuration for :database_authenticatable
61
64
  # For bcrypt, this is the cost for hashing the password and defaults to 10. If
62
65
  # using other encryptors, it sets how many times you want the password re-encrypted.
63
- config.stretches = 10
66
+ config.stretches = Rails.env.test? ? 1 : 10
64
67
 
65
68
  # ==> Configuration for :confirmable
66
69
  # The time you want to give your user to confirm his account. During this time
67
70
  # he will be able to access your application without confirming. Default is nil.
68
- # When confirm_within is zero, the user won't be able to sign in without confirming.
71
+ # When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming.
69
72
  # You can use this to let your user access some features of your application
70
73
  # without confirming the account, but blocking it after a certain period
71
74
  # (ie 2 days).
72
- # config.confirm_within = 2.days
75
+ # config.allow_unconfirmed_access_for = 2.days
73
76
 
74
77
  # Defines which key will be used when confirming an account
75
78
  # config.confirmation_keys = [ :email ]
@@ -148,10 +151,6 @@ Devise.setup do |config|
148
151
  # Defines name of the authentication token params key
149
152
  # config.token_authentication_key = :auth_token
150
153
 
151
- # If true, authentication through token does not store user in session and needs
152
- # to be supplied on each request. Useful if you are using the token as API token.
153
- # config.stateless_token = false
154
-
155
154
  # ==> Scopes configuration
156
155
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
157
156
  # "users/sessions/new". It's turned off by default because it's slower if you
@@ -4,22 +4,68 @@ class CreateTables < ActiveRecord::Migration
4
4
  t.string :username
5
5
  t.string :facebook_token
6
6
 
7
- t.database_authenticatable :null => false
8
- t.confirmable
9
- t.recoverable
10
- t.rememberable
11
- t.trackable
12
- t.lockable
13
- t.token_authenticatable
7
+ ## Database authenticatable
8
+ t.string :email, :null => false, :default => ""
9
+ t.string :encrypted_password, :null => false, :default => ""
10
+
11
+ ## Recoverable
12
+ t.string :reset_password_token
13
+ t.datetime :reset_password_sent_at
14
+
15
+ ## Rememberable
16
+ t.datetime :remember_created_at
17
+
18
+ ## Trackable
19
+ t.integer :sign_in_count, :default => 0
20
+ t.datetime :current_sign_in_at
21
+ t.datetime :last_sign_in_at
22
+ t.string :current_sign_in_ip
23
+ t.string :last_sign_in_ip
24
+
25
+ ## Encryptable
26
+ # t.string :password_salt
27
+
28
+ ## Confirmable
29
+ t.string :confirmation_token
30
+ t.datetime :confirmed_at
31
+ t.datetime :confirmation_sent_at
32
+ # t.string :unconfirmed_email # Only if using reconfirmable
33
+
34
+ ## Lockable
35
+ t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
36
+ t.string :unlock_token # Only if unlock strategy is :email or :both
37
+ t.datetime :locked_at
38
+
39
+ # Token authenticatable
40
+ t.string :authentication_token
41
+
14
42
  t.timestamps
15
43
  end
16
44
 
17
45
  create_table :admins do |t|
18
- t.database_authenticatable :null => true
19
- t.encryptable
20
- t.rememberable :use_salt => false
21
- t.recoverable
22
- t.lockable
46
+ ## Database authenticatable
47
+ t.string :email, :null => true
48
+ t.string :encrypted_password, :null => true
49
+
50
+ ## Recoverable
51
+ t.string :reset_password_token
52
+ t.datetime :reset_password_sent_at
53
+
54
+ ## Rememberable
55
+ t.datetime :remember_created_at
56
+
57
+ ## Confirmable
58
+ t.string :confirmation_token
59
+ t.datetime :confirmed_at
60
+ t.datetime :confirmation_sent_at
61
+ t.string :unconfirmed_email # Only if using reconfirmable
62
+
63
+ ## Encryptable
64
+ t.string :password_salt
65
+
66
+ ## Lockable
67
+ t.datetime :locked_at
68
+
23
69
  t.timestamps
24
70
  end
25
71
  end
@@ -3,8 +3,11 @@ module SharedAdmin
3
3
 
4
4
  included do
5
5
  devise :database_authenticatable, :encryptable, :registerable,
6
- :timeoutable, :recoverable, :rememberable, :lockable,
7
- :unlock_strategy => :time
6
+ :timeoutable, :recoverable, :lockable, :confirmable,
7
+ :unlock_strategy => :time, :lock_strategy => :none,
8
+ :allow_unconfirmed_access_for => 2.weeks, :reconfirmable => true
9
+
10
+ validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
8
11
  end
9
12
 
10
13
  end
@@ -14,8 +14,11 @@ class ActiveSupport::TestCase
14
14
  end
15
15
  alias :assert_present :assert_not_blank
16
16
 
17
- def assert_email_sent(&block)
17
+ def assert_email_sent(address = nil, &block)
18
18
  assert_difference('ActionMailer::Base.deliveries.size') { yield }
19
+ if address.present?
20
+ assert_equal address, ActionMailer::Base.deliveries.last['to'].to_s
21
+ end
19
22
  end
20
23
 
21
24
  def assert_email_not_sent(&block)
@@ -23,8 +23,10 @@ class ActionDispatch::IntegrationTest
23
23
  def create_admin(options={})
24
24
  @admin ||= begin
25
25
  admin = Admin.create!(
26
- :email => 'admin@test.com', :password => '123456', :password_confirmation => '123456'
26
+ :email => options[:email] || 'admin@test.com',
27
+ :password => '123456', :password_confirmation => '123456'
27
28
  )
29
+ admin.confirm! unless options[:confirm] == false
28
30
  admin
29
31
  end
30
32
  end
@@ -17,7 +17,7 @@ class TestHelpersTest < ActionController::TestCase
17
17
  end
18
18
 
19
19
  test "redirects if attempting to access a page with an unconfirmed account" do
20
- swap Devise, :confirm_within => 0 do
20
+ swap Devise, :allow_unconfirmed_access_for => 0 do
21
21
  user = create_user
22
22
  assert !user.active_for_authentication?
23
23
 
@@ -28,7 +28,7 @@ class TestHelpersTest < ActionController::TestCase
28
28
  end
29
29
 
30
30
  test "returns nil if accessing current_user with an unconfirmed account" do
31
- swap Devise, :confirm_within => 0 do
31
+ swap Devise, :allow_unconfirmed_access_for => 0 do
32
32
  user = create_user
33
33
  assert !user.active_for_authentication?
34
34
 
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.5.4
4
+ version: 2.0.0.rc
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - José Valim
@@ -10,56 +10,41 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-26 00:00:00.000000000 Z
13
+ date: 2011-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- version_requirements: !ruby/object:Gem::Requirement
16
+ name: warden
17
+ requirement: &2156231200 !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ~>
19
21
  - !ruby/object:Gem::Version
20
22
  version: '1.1'
21
- none: false
22
- name: warden
23
23
  type: :runtime
24
24
  prerelease: false
25
- requirement: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '1.1'
30
- none: false
25
+ version_requirements: *2156231200
31
26
  - !ruby/object:Gem::Dependency
32
- version_requirements: !ruby/object:Gem::Requirement
27
+ name: orm_adapter
28
+ requirement: &2156216840 !ruby/object:Gem::Requirement
29
+ none: false
33
30
  requirements:
34
31
  - - ~>
35
32
  - !ruby/object:Gem::Version
36
33
  version: 0.0.3
37
- none: false
38
- name: orm_adapter
39
34
  type: :runtime
40
35
  prerelease: false
41
- requirement: !ruby/object:Gem::Requirement
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: 0.0.3
46
- none: false
36
+ version_requirements: *2156216840
47
37
  - !ruby/object:Gem::Dependency
48
- version_requirements: !ruby/object:Gem::Requirement
38
+ name: bcrypt-ruby
39
+ requirement: &2156215340 !ruby/object:Gem::Requirement
40
+ none: false
49
41
  requirements:
50
42
  - - ~>
51
43
  - !ruby/object:Gem::Version
52
44
  version: '3.0'
53
- none: false
54
- name: bcrypt-ruby
55
45
  type: :runtime
56
46
  prerelease: false
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- none: false
47
+ version_requirements: *2156215340
63
48
  description: Flexible authentication solution for Rails with Warden
64
49
  email: contact@plataformatec.com.br
65
50
  executables: []
@@ -70,6 +55,7 @@ files:
70
55
  - .travis.yml
71
56
  - CHANGELOG.rdoc
72
57
  - Gemfile
58
+ - Gemfile.lock
73
59
  - MIT-LICENSE
74
60
  - README.rdoc
75
61
  - Rakefile
@@ -201,7 +187,6 @@ files:
201
187
  - test/mailers/reset_password_instructions_test.rb
202
188
  - test/mailers/unlock_instructions_test.rb
203
189
  - test/mapping_test.rb
204
- - test/models/authenticatable_test.rb
205
190
  - test/models/confirmable_test.rb
206
191
  - test/models/database_authenticatable_test.rb
207
192
  - test/models/encryptable_test.rb
@@ -270,7 +255,6 @@ files:
270
255
  - test/rails_app/public/favicon.ico
271
256
  - test/rails_app/script/rails
272
257
  - test/routes_test.rb
273
- - test/schema_test.rb
274
258
  - test/support/assertions.rb
275
259
  - test/support/helpers.rb
276
260
  - test/support/integration.rb
@@ -285,20 +269,20 @@ rdoc_options: []
285
269
  require_paths:
286
270
  - lib
287
271
  required_ruby_version: !ruby/object:Gem::Requirement
272
+ none: false
288
273
  requirements:
289
274
  - - ! '>='
290
275
  - !ruby/object:Gem::Version
291
276
  version: '0'
292
- none: false
293
277
  required_rubygems_version: !ruby/object:Gem::Requirement
278
+ none: false
294
279
  requirements:
295
- - - ! '>='
280
+ - - ! '>'
296
281
  - !ruby/object:Gem::Version
297
- version: '0'
298
- none: false
282
+ version: 1.3.1
299
283
  requirements: []
300
284
  rubyforge_project: devise
301
- rubygems_version: 1.8.23
285
+ rubygems_version: 1.8.10
302
286
  signing_key:
303
287
  specification_version: 3
304
288
  summary: Flexible authentication solution for Rails with Warden
@@ -334,7 +318,6 @@ test_files:
334
318
  - test/mailers/reset_password_instructions_test.rb
335
319
  - test/mailers/unlock_instructions_test.rb
336
320
  - test/mapping_test.rb
337
- - test/models/authenticatable_test.rb
338
321
  - test/models/confirmable_test.rb
339
322
  - test/models/database_authenticatable_test.rb
340
323
  - test/models/encryptable_test.rb
@@ -403,7 +386,6 @@ test_files:
403
386
  - test/rails_app/public/favicon.ico
404
387
  - test/rails_app/script/rails
405
388
  - test/routes_test.rb
406
- - test/schema_test.rb
407
389
  - test/support/assertions.rb
408
390
  - test/support/helpers.rb
409
391
  - test/support/integration.rb
@@ -1,9 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AuthenticatableTest < ActiveSupport::TestCase
4
- test 'find_first_by_auth_conditions allows custom filtering parameters' do
5
- user = User.create!(email: "example@example.com", password: "123456")
6
- assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user
7
- assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id + 1), nil
8
- end
9
- end