devise 1.3.4 → 1.4.1

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 (74) hide show
  1. data/.travis.yml +3 -2
  2. data/CHANGELOG.rdoc +29 -0
  3. data/Gemfile +10 -7
  4. data/Gemfile.lock +47 -47
  5. data/README.rdoc +2 -2
  6. data/Rakefile +1 -1
  7. data/app/controllers/devise/confirmations_controller.rb +2 -2
  8. data/app/controllers/devise/passwords_controller.rb +10 -2
  9. data/app/controllers/devise/registrations_controller.rb +6 -4
  10. data/app/controllers/devise/unlocks_controller.rb +2 -2
  11. data/app/helpers/devise_helper.rb +1 -1
  12. data/app/mailers/devise/mailer.rb +4 -77
  13. data/config/locales/en.yml +3 -0
  14. data/lib/devise.rb +45 -13
  15. data/lib/devise/controllers/helpers.rb +5 -2
  16. data/lib/devise/controllers/internal_helpers.rb +15 -1
  17. data/lib/devise/controllers/rememberable.rb +1 -1
  18. data/lib/devise/email.rb +23 -0
  19. data/lib/devise/hooks/forgetable.rb +1 -1
  20. data/lib/devise/hooks/trackable.rb +1 -1
  21. data/lib/devise/mailers/helpers.rb +84 -0
  22. data/lib/devise/mapping.rb +23 -7
  23. data/lib/devise/models/authenticatable.rb +14 -6
  24. data/lib/devise/models/database_authenticatable.rb +18 -1
  25. data/lib/devise/models/recoverable.rb +1 -1
  26. data/lib/devise/models/rememberable.rb +7 -5
  27. data/lib/devise/models/validatable.rb +5 -7
  28. data/lib/devise/modules.rb +1 -1
  29. data/lib/devise/omniauth.rb +0 -5
  30. data/lib/devise/omniauth/config.rb +6 -0
  31. data/lib/devise/rails/routes.rb +65 -10
  32. data/lib/devise/strategies/rememberable.rb +2 -7
  33. data/lib/devise/version.rb +1 -1
  34. data/lib/generators/devise/install_generator.rb +2 -2
  35. data/lib/generators/devise/simple_form_for/confirmations/new.html.erb +15 -0
  36. data/lib/generators/devise/simple_form_for/passwords/edit.html.erb +19 -0
  37. data/lib/generators/devise/simple_form_for/passwords/new.html.erb +15 -0
  38. data/lib/generators/devise/simple_form_for/registrations/edit.html.erb +22 -0
  39. data/lib/generators/devise/simple_form_for/registrations/new.html.erb +17 -0
  40. data/lib/generators/devise/simple_form_for/sessions/new.html.erb +15 -0
  41. data/lib/generators/devise/simple_form_for/unlocks/new.html.erb +15 -0
  42. data/lib/generators/devise/views_generator.rb +61 -9
  43. data/lib/generators/templates/devise.rb +13 -3
  44. data/test/controllers/internal_helpers_test.rb +9 -2
  45. data/test/generators/views_generator_test.rb +10 -0
  46. data/test/helpers/devise_helper_test.rb +43 -0
  47. data/test/integration/authenticatable_test.rb +74 -5
  48. data/test/integration/confirmable_test.rb +39 -1
  49. data/test/integration/database_authenticatable_test.rb +22 -0
  50. data/test/integration/http_authenticatable_test.rb +8 -0
  51. data/test/integration/lockable_test.rb +62 -4
  52. data/test/integration/omniauthable_test.rb +1 -3
  53. data/test/integration/recoverable_test.rb +66 -6
  54. data/test/integration/registerable_test.rb +1 -1
  55. data/test/integration/rememberable_test.rb +20 -1
  56. data/test/integration/trackable_test.rb +17 -0
  57. data/test/mapping_test.rb +5 -0
  58. data/test/models/database_authenticatable_test.rb +56 -1
  59. data/test/models/encryptable_test.rb +1 -1
  60. data/test/models/recoverable_test.rb +14 -3
  61. data/test/models/rememberable_test.rb +8 -0
  62. data/test/models/token_authenticatable_test.rb +0 -6
  63. data/test/models/validatable_test.rb +17 -4
  64. data/test/models_test.rb +4 -0
  65. data/test/omniauth/url_helpers_test.rb +4 -0
  66. data/test/rails_app/app/controllers/home_controller.rb +9 -0
  67. data/test/rails_app/app/controllers/users_controller.rb +6 -1
  68. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  69. data/test/rails_app/app/views/home/join.html.erb +1 -0
  70. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  71. data/test/rails_app/config/initializers/devise.rb +6 -0
  72. data/test/rails_app/config/routes.rb +30 -2
  73. data/test/routes_test.rb +54 -0
  74. metadata +21 -4
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
- script: "rake test"
1
+ script: "bundle exec rake test"
2
2
  rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - ree
6
- - jruby
6
+ - jruby
7
+ - rubinius
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,32 @@
1
+ == 1.4.1
2
+
3
+ * enhancements
4
+ * Add :defaults and :format support on router
5
+ * Add simple form generators
6
+ * Better localization for devise_error_messages! (by github.com/zedtux)
7
+
8
+ * bug fix
9
+ * Ensure to_xml is properly white listened
10
+ * Ensure handle_unverified_request clean up any cached signed-in user
11
+
12
+ == 1.4.0
13
+
14
+ * enhancements
15
+ * Added authenticated and unauthenticated to the router to route the used based on his status (by github.com/sj26)
16
+ * Improve e-mail regexp (by github.com/rodrigoflores)
17
+ * Add strip_whitespace_keys and default to e-mail (by github.com/swrobel)
18
+ * Do not run format and uniqueness validations on e-mail if it hasn't changed (by github.com/Thibaut)
19
+ * Added update_without_password to update models but not allowing the password to change (by github.com/fschwahn)
20
+ * Added config.paranoid, check the generator for more information (by github.com/rodrigoflores)
21
+
22
+ * bug fix
23
+ * password_required? should not affect length validation
24
+ * User cannot access sign up and similar pages if he is already signed in through a cookie or token
25
+ * Do not convert booleans to strings on finders (by github.com/xavier)
26
+ * Run validations even if current_password fails (by github.com/crx)
27
+ * Devise now honors routes constraints (by github.com/macmartine)
28
+ * Do not return the user resource when requesting instructions (by github.com/rodrigoflores)
29
+
1
30
  == 1.3.4
2
31
 
3
32
  * bug fix
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rails", "~> 3.0.4"
5
+ gem "rails", "~> 3.0.7"
6
6
  gem "oa-oauth", '~> 0.2.0', :require => "omniauth/oauth"
7
7
  gem "oa-openid", '~> 0.2.0', :require => "omniauth/openid"
8
8
 
@@ -15,15 +15,18 @@ platforms :jruby do
15
15
  gem 'activerecord-jdbcsqlite3-adapter'
16
16
  end
17
17
 
18
- platforms :ruby do
18
+ platforms :mri_18 do
19
19
  group :test do
20
- gem "sqlite3-ruby"
21
- gem "ruby-debug", ">= 0.10.3" if RUBY_VERSION < '1.9'
20
+ gem "ruby-debug", ">= 0.10.3"
22
21
  end
22
+ end
23
+
24
+ platforms :ruby do
25
+ gem "sqlite3-ruby"
23
26
 
24
27
  group :mongoid do
25
- gem "mongo", "1.1.2"
26
- gem "mongoid", "2.0.0.beta.20"
27
- gem "bson_ext", "1.2.1"
28
+ gem "mongo", "~> 1.3.0"
29
+ gem "mongoid", "2.0.1"
30
+ gem "bson_ext", "~> 1.3.0"
28
31
  end
29
32
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devise (1.3.4)
4
+ devise (1.4.0)
5
5
  bcrypt-ruby (~> 2.1.2)
6
6
  orm_adapter (~> 0.0.3)
7
7
  warden (~> 1.0.3)
@@ -10,41 +10,41 @@ GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
12
  abstract (1.0.0)
13
- actionmailer (3.0.4)
14
- actionpack (= 3.0.4)
13
+ actionmailer (3.0.7)
14
+ actionpack (= 3.0.7)
15
15
  mail (~> 2.2.15)
16
- actionpack (3.0.4)
17
- activemodel (= 3.0.4)
18
- activesupport (= 3.0.4)
16
+ actionpack (3.0.7)
17
+ activemodel (= 3.0.7)
18
+ activesupport (= 3.0.7)
19
19
  builder (~> 2.1.2)
20
20
  erubis (~> 2.6.6)
21
- i18n (~> 0.4)
21
+ i18n (~> 0.5.0)
22
22
  rack (~> 1.2.1)
23
- rack-mount (~> 0.6.13)
23
+ rack-mount (~> 0.6.14)
24
24
  rack-test (~> 0.5.7)
25
25
  tzinfo (~> 0.3.23)
26
- activemodel (3.0.4)
27
- activesupport (= 3.0.4)
26
+ activemodel (3.0.7)
27
+ activesupport (= 3.0.7)
28
28
  builder (~> 2.1.2)
29
- i18n (~> 0.4)
30
- activerecord (3.0.4)
31
- activemodel (= 3.0.4)
32
- activesupport (= 3.0.4)
29
+ i18n (~> 0.5.0)
30
+ activerecord (3.0.7)
31
+ activemodel (= 3.0.7)
32
+ activesupport (= 3.0.7)
33
33
  arel (~> 2.0.2)
34
34
  tzinfo (~> 0.3.23)
35
35
  activerecord-jdbc-adapter (1.1.1)
36
36
  activerecord-jdbcsqlite3-adapter (1.1.1)
37
37
  activerecord-jdbc-adapter (= 1.1.1)
38
38
  jdbc-sqlite3 (~> 3.6.0)
39
- activeresource (3.0.4)
40
- activemodel (= 3.0.4)
41
- activesupport (= 3.0.4)
42
- activesupport (3.0.4)
39
+ activeresource (3.0.7)
40
+ activemodel (= 3.0.7)
41
+ activesupport (= 3.0.7)
42
+ activesupport (3.0.7)
43
43
  addressable (2.2.4)
44
- arel (2.0.8)
44
+ arel (2.0.9)
45
45
  bcrypt-ruby (2.1.4)
46
- bson (1.2.1)
47
- bson_ext (1.2.1)
46
+ bson (1.3.0)
47
+ bson_ext (1.3.0)
48
48
  builder (2.1.2)
49
49
  columnize (0.3.2)
50
50
  erubis (2.6.6)
@@ -56,24 +56,24 @@ GEM
56
56
  i18n (0.5.0)
57
57
  jdbc-sqlite3 (3.6.14.2.056-java)
58
58
  linecache (0.43)
59
- mail (2.2.15)
59
+ mail (2.2.19)
60
60
  activesupport (>= 2.3.6)
61
61
  i18n (>= 0.4.0)
62
62
  mime-types (~> 1.16)
63
63
  treetop (~> 1.4.8)
64
64
  mime-types (1.16)
65
65
  mocha (0.9.12)
66
- mongo (1.1.2)
67
- bson (>= 1.1.1)
68
- mongoid (2.0.0.beta.20)
66
+ mongo (1.3.0)
67
+ bson (>= 1.3.0)
68
+ mongoid (2.0.1)
69
69
  activemodel (~> 3.0)
70
- mongo (~> 1.1)
70
+ mongo (~> 1.3)
71
71
  tzinfo (~> 0.3.22)
72
72
  will_paginate (~> 3.0.pre)
73
73
  multi_json (0.0.5)
74
74
  multipart-post (1.1.0)
75
- nokogiri (1.4.4)
76
- nokogiri (1.4.4-java)
75
+ nokogiri (1.4.3.1)
76
+ nokogiri (1.4.3.1-java)
77
77
  weakling (>= 0.0.3)
78
78
  oa-core (0.2.0)
79
79
  rack (~> 1.1)
@@ -93,25 +93,25 @@ GEM
93
93
  multi_json (~> 0.0.4)
94
94
  orm_adapter (0.0.4)
95
95
  polyglot (0.3.1)
96
- rack (1.2.1)
97
- rack-mount (0.6.13)
96
+ rack (1.2.2)
97
+ rack-mount (0.6.14)
98
98
  rack (>= 1.0.0)
99
99
  rack-openid (1.2.0)
100
100
  rack (>= 1.1.0)
101
101
  ruby-openid (>= 2.1.8)
102
102
  rack-test (0.5.7)
103
103
  rack (>= 1.0)
104
- rails (3.0.4)
105
- actionmailer (= 3.0.4)
106
- actionpack (= 3.0.4)
107
- activerecord (= 3.0.4)
108
- activeresource (= 3.0.4)
109
- activesupport (= 3.0.4)
104
+ rails (3.0.7)
105
+ actionmailer (= 3.0.7)
106
+ actionpack (= 3.0.7)
107
+ activerecord (= 3.0.7)
108
+ activeresource (= 3.0.7)
109
+ activesupport (= 3.0.7)
110
110
  bundler (~> 1.0)
111
- railties (= 3.0.4)
112
- railties (3.0.4)
113
- actionpack (= 3.0.4)
114
- activesupport (= 3.0.4)
111
+ railties (= 3.0.7)
112
+ railties (3.0.7)
113
+ actionpack (= 3.0.7)
114
+ activesupport (= 3.0.7)
115
115
  rake (>= 0.8.7)
116
116
  thor (~> 0.14.4)
117
117
  rake (0.8.7)
@@ -129,9 +129,9 @@ GEM
129
129
  thor (0.14.6)
130
130
  treetop (1.4.9)
131
131
  polyglot (>= 0.3.1)
132
- tzinfo (0.3.24)
133
- warden (1.0.3)
134
- rack (>= 1.0.0)
132
+ tzinfo (0.3.27)
133
+ warden (1.0.4)
134
+ rack (>= 1.0)
135
135
  weakling (0.0.4-java)
136
136
  webrat (0.7.2)
137
137
  nokogiri (>= 1.2.0)
@@ -145,14 +145,14 @@ PLATFORMS
145
145
 
146
146
  DEPENDENCIES
147
147
  activerecord-jdbcsqlite3-adapter
148
- bson_ext (= 1.2.1)
148
+ bson_ext (~> 1.3.0)
149
149
  devise!
150
150
  mocha
151
- mongo (= 1.1.2)
152
- mongoid (= 2.0.0.beta.20)
151
+ mongo (~> 1.3.0)
152
+ mongoid (= 2.0.1)
153
153
  oa-oauth (~> 0.2.0)
154
154
  oa-openid (~> 0.2.0)
155
- rails (~> 3.0.4)
155
+ rails (~> 3.0.7)
156
156
  ruby-debug (>= 0.10.3)
157
157
  sqlite3-ruby
158
158
  webrat (= 0.7.2)
data/README.rdoc CHANGED
@@ -108,7 +108,7 @@ Devise must be set up within the model (or models) you want to use. Devise route
108
108
  We're assuming here you want a User model with some Devise modules, as outlined below:
109
109
 
110
110
  class User < ActiveRecord::Base
111
- devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
111
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
112
112
  end
113
113
 
114
114
  After you choose which modules to use, you need to set up your migrations. Luckily, Devise has some helpers to save you from this boring work:
@@ -174,7 +174,7 @@ Notice that if your devise model is not called "user" but "member", then the hel
174
174
 
175
175
  The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
176
176
 
177
- devise :database_authenticatable, :confirmable, :recoverable, :stretches => 20
177
+ devise :database_authenticatable, :registerable, :confirmable, :recoverable, :stretches => 20
178
178
 
179
179
  Besides :stretches, you can define :pepper, :encryptor, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
180
180
 
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/testtask'
4
4
  require 'rake/rdoctask'
5
5
 
6
6
  desc 'Default: run tests for all ORMs.'
7
- task :default => :pre_commit
7
+ task :default => :test
8
8
 
9
9
  desc 'Run Devise tests for all ORMs.'
10
10
  task :pre_commit do
@@ -11,9 +11,9 @@ class Devise::ConfirmationsController < ApplicationController
11
11
  def create
12
12
  self.resource = resource_class.send_confirmation_instructions(params[resource_name])
13
13
 
14
- if resource.errors.empty?
14
+ if successful_and_sane?(resource)
15
15
  set_flash_message(:notice, :send_instructions) if is_navigational_format?
16
- respond_with resource, :location => after_resending_confirmation_instructions_path_for(resource_name)
16
+ respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
17
17
  else
18
18
  respond_with_navigational(resource){ render_with_scope :new }
19
19
  end
@@ -12,9 +12,9 @@ class Devise::PasswordsController < ApplicationController
12
12
  def create
13
13
  self.resource = resource_class.send_reset_password_instructions(params[resource_name])
14
14
 
15
- if resource.errors.empty?
15
+ if successful_and_sane?(resource)
16
16
  set_flash_message(:notice, :send_instructions) if is_navigational_format?
17
- respond_with resource, :location => new_session_path(resource_name)
17
+ respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
18
18
  else
19
19
  respond_with_navigational(resource){ render_with_scope :new }
20
20
  end
@@ -39,4 +39,12 @@ class Devise::PasswordsController < ApplicationController
39
39
  respond_with_navigational(resource){ render_with_scope :edit }
40
40
  end
41
41
  end
42
+
43
+ protected
44
+
45
+ # The path used after sending reset password instructions
46
+ def after_sending_reset_password_instructions_path_for(resource_name)
47
+ new_session_path(resource_name)
48
+ end
49
+
42
50
  end
@@ -35,7 +35,11 @@ class Devise::RegistrationsController < ApplicationController
35
35
  end
36
36
 
37
37
  # PUT /resource
38
+ # We need to use a copy of the resource because we don't want to change
39
+ # the current user in place.
38
40
  def update
41
+ self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
42
+
39
43
  if resource.update_with_password(params[resource_name])
40
44
  set_flash_message :notice, :updated if is_navigational_format?
41
45
  sign_in resource_name, resource, :bypass => true
@@ -102,11 +106,9 @@ class Devise::RegistrationsController < ApplicationController
102
106
  end
103
107
  end
104
108
 
105
- # Authenticates the current scope and gets a copy of the current resource.
106
- # We need to use a copy because we don't want actions like update changing
107
- # the current user in place.
109
+ # Authenticates the current scope and gets the current resource from the session.
108
110
  def authenticate_scope!
109
111
  send(:"authenticate_#{resource_name}!", true)
110
- self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
112
+ self.resource = send(:"current_#{resource_name}")
111
113
  end
112
114
  end
@@ -12,9 +12,9 @@ class Devise::UnlocksController < ApplicationController
12
12
  def create
13
13
  self.resource = resource_class.send_unlock_instructions(params[resource_name])
14
14
 
15
- if resource.errors.empty?
15
+ if successful_and_sane?(resource)
16
16
  set_flash_message :notice, :send_instructions if is_navigational_format?
17
- respond_with resource, :location => new_session_path(resource_name)
17
+ respond_with({}, :location => new_session_path(resource_name))
18
18
  else
19
19
  respond_with_navigational(resource){ render_with_scope :new }
20
20
  end
@@ -11,7 +11,7 @@ module DeviseHelper
11
11
  messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
12
12
  sentence = I18n.t("errors.messages.not_saved",
13
13
  :count => resource.errors.count,
14
- :resource => resource_name)
14
+ :resource => resource.class.model_name.human.downcase)
15
15
 
16
16
  html = <<-HTML
17
17
  <div id="error_explanation">
@@ -1,88 +1,15 @@
1
1
  class Devise::Mailer < ::ActionMailer::Base
2
- include Devise::Controllers::ScopedViews
3
- attr_reader :scope_name, :resource
2
+ include Devise::Mailers::Helpers
4
3
 
5
4
  def confirmation_instructions(record)
6
- setup_mail(record, :confirmation_instructions)
5
+ devise_mail(record, :confirmation_instructions)
7
6
  end
8
7
 
9
8
  def reset_password_instructions(record)
10
- setup_mail(record, :reset_password_instructions)
9
+ devise_mail(record, :reset_password_instructions)
11
10
  end
12
11
 
13
12
  def unlock_instructions(record)
14
- setup_mail(record, :unlock_instructions)
15
- end
16
-
17
- private
18
-
19
- # Configure default email options
20
- def setup_mail(record, action)
21
- initialize_from_record(record)
22
- mail headers_for(action)
23
- end
24
-
25
- def initialize_from_record(record)
26
- @scope_name = Devise::Mapping.find_scope!(record)
27
- @resource = instance_variable_set("@#{devise_mapping.name}", record)
28
- end
29
-
30
- def devise_mapping
31
- @devise_mapping ||= Devise.mappings[scope_name]
32
- end
33
-
34
- def headers_for(action)
35
- headers = {
36
- :subject => translate(devise_mapping, action),
37
- :from => mailer_sender(devise_mapping),
38
- :to => resource.email,
39
- :template_path => template_paths
40
- }
41
-
42
- if resource.respond_to?(:headers_for)
43
- headers.merge!(resource.headers_for(action))
44
- end
45
-
46
- unless headers.key?(:reply_to)
47
- headers[:reply_to] = headers[:from]
48
- end
49
-
50
- headers
51
- end
52
-
53
- def mailer_sender(mapping)
54
- if Devise.mailer_sender.is_a?(Proc)
55
- Devise.mailer_sender.call(mapping.name)
56
- else
57
- Devise.mailer_sender
58
- end
59
- end
60
-
61
- def template_paths
62
- template_path = [self.class.mailer_name]
63
- template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views?
64
- template_path
65
- end
66
-
67
- # Setup a subject doing an I18n lookup. At first, it attemps to set a subject
68
- # based on the current mapping:
69
- #
70
- # en:
71
- # devise:
72
- # mailer:
73
- # confirmation_instructions:
74
- # user_subject: '...'
75
- #
76
- # If one does not exist, it fallbacks to ActionMailer default:
77
- #
78
- # en:
79
- # devise:
80
- # mailer:
81
- # confirmation_instructions:
82
- # subject: '...'
83
- #
84
- def translate(mapping, key)
85
- I18n.t(:"#{mapping.name}_subject", :scope => [:devise, :mailer, key],
86
- :default => [:subject, key.to_s.humanize])
13
+ devise_mail(record, :unlock_instructions)
87
14
  end
88
15
  end