devise 1.5.3 → 2.0.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.
Files changed (125) hide show
  1. data/CHANGELOG.rdoc +98 -71
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +4 -2
  4. data/app/controllers/devise/confirmations_controller.rb +3 -6
  5. data/app/controllers/devise/omniauth_callbacks_controller.rb +1 -3
  6. data/app/controllers/devise/passwords_controller.rb +3 -6
  7. data/app/controllers/devise/registrations_controller.rb +40 -42
  8. data/app/controllers/devise/sessions_controller.rb +2 -3
  9. data/app/controllers/devise/unlocks_controller.rb +4 -7
  10. data/app/controllers/devise_controller.rb +169 -0
  11. data/app/views/devise/_links.erb +25 -0
  12. data/app/views/devise/confirmations/new.html.erb +1 -1
  13. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  14. data/app/views/devise/passwords/edit.html.erb +1 -1
  15. data/app/views/devise/passwords/new.html.erb +1 -1
  16. data/app/views/devise/registrations/new.html.erb +1 -1
  17. data/app/views/devise/sessions/new.html.erb +1 -1
  18. data/app/views/devise/shared/_links.erb +3 -25
  19. data/app/views/devise/unlocks/new.html.erb +1 -1
  20. data/config/locales/en.yml +5 -6
  21. data/lib/devise/controllers/helpers.rb +8 -2
  22. data/lib/devise/controllers/scoped_views.rb +0 -16
  23. data/lib/devise/controllers/url_helpers.rb +16 -2
  24. data/lib/devise/failure_app.rb +43 -8
  25. data/lib/devise/models/authenticatable.rb +22 -1
  26. data/lib/devise/models/confirmable.rb +80 -22
  27. data/lib/devise/models/database_authenticatable.rb +0 -11
  28. data/lib/devise/models/lockable.rb +1 -1
  29. data/lib/devise/models/recoverable.rb +5 -5
  30. data/lib/devise/models/rememberable.rb +5 -20
  31. data/lib/devise/models/serializable.rb +5 -2
  32. data/lib/devise/models/timeoutable.rb +1 -3
  33. data/lib/devise/models/token_authenticatable.rb +1 -4
  34. data/lib/devise/models/validatable.rb +1 -1
  35. data/lib/devise/models.rb +1 -1
  36. data/lib/devise/modules.rb +2 -2
  37. data/lib/devise/orm/active_record.rb +6 -0
  38. data/lib/devise/param_filter.rb +1 -1
  39. data/lib/devise/path_checker.rb +5 -1
  40. data/lib/devise/rails/routes.rb +16 -10
  41. data/lib/devise/rails/warden_compat.rb +0 -83
  42. data/lib/devise/rails.rb +61 -0
  43. data/lib/devise/schema.rb +5 -0
  44. data/lib/devise/strategies/authenticatable.rb +14 -10
  45. data/lib/devise/strategies/token_authenticatable.rb +3 -3
  46. data/lib/devise/version.rb +1 -1
  47. data/lib/devise.rb +56 -33
  48. data/lib/generators/active_record/devise_generator.rb +40 -2
  49. data/lib/generators/active_record/templates/migration.rb +1 -19
  50. data/lib/generators/active_record/templates/migration_existing.rb +1 -9
  51. data/lib/generators/devise/views_generator.rb +6 -14
  52. data/lib/generators/mongoid/devise_generator.rb +43 -0
  53. data/lib/generators/templates/devise.rb +26 -12
  54. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +1 -1
  55. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
  56. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +1 -1
  57. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  58. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +1 -1
  59. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +1 -1
  60. data/test/controllers/internal_helpers_test.rb +5 -4
  61. data/test/devise_test.rb +2 -2
  62. data/test/failure_app_test.rb +24 -20
  63. data/test/generators/active_record_generator_test.rb +3 -13
  64. data/test/generators/views_generator_test.rb +1 -1
  65. data/test/integration/authenticatable_test.rb +4 -7
  66. data/test/integration/confirmable_test.rb +55 -3
  67. data/test/integration/http_authenticatable_test.rb +20 -5
  68. data/test/integration/lockable_test.rb +26 -14
  69. data/test/integration/registerable_test.rb +33 -2
  70. data/test/integration/rememberable_test.rb +0 -50
  71. data/test/integration/timeoutable_test.rb +18 -4
  72. data/test/integration/token_authenticatable_test.rb +5 -5
  73. data/test/integration/trackable_test.rb +6 -6
  74. data/test/mapping_test.rb +2 -3
  75. data/test/models/confirmable_test.rb +101 -8
  76. data/test/models/database_authenticatable_test.rb +6 -0
  77. data/test/models/encryptable_test.rb +1 -1
  78. data/test/models/lockable_test.rb +13 -0
  79. data/test/models/recoverable_test.rb +0 -27
  80. data/test/models/rememberable_test.rb +41 -160
  81. data/test/models/serializable_test.rb +1 -1
  82. data/test/models_test.rb +7 -7
  83. data/test/rails_app/app/mongoid/admin.rb +22 -1
  84. data/test/rails_app/app/mongoid/user.rb +35 -0
  85. data/test/rails_app/config/initializers/devise.rb +6 -7
  86. data/test/rails_app/config/routes.rb +3 -5
  87. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +58 -12
  88. data/test/rails_app/lib/shared_admin.rb +6 -2
  89. data/test/rails_app/log/development.log +13 -0
  90. data/test/rails_app/log/test.log +319550 -0
  91. data/test/support/assertions.rb +4 -1
  92. data/test/support/helpers.rb +0 -17
  93. data/test/support/integration.rb +3 -1
  94. data/test/test_helpers_test.rb +2 -2
  95. data/test/tmp/app/views/devise/_links.erb +25 -0
  96. data/test/tmp/app/views/devise/confirmations/new.html.erb +15 -0
  97. data/test/tmp/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  98. data/test/tmp/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  99. data/test/tmp/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  100. data/test/tmp/app/views/devise/passwords/edit.html.erb +19 -0
  101. data/test/tmp/app/views/devise/passwords/new.html.erb +15 -0
  102. data/test/tmp/app/views/devise/registrations/edit.html.erb +22 -0
  103. data/test/tmp/app/views/devise/registrations/new.html.erb +17 -0
  104. data/test/tmp/app/views/devise/sessions/new.html.erb +15 -0
  105. data/test/tmp/app/views/devise/unlocks/new.html.erb +15 -0
  106. data/test/tmp/app/views/users/_links.erb +25 -0
  107. data/test/tmp/app/views/users/confirmations/new.html.erb +15 -0
  108. data/test/tmp/app/views/users/mailer/confirmation_instructions.html.erb +5 -0
  109. data/test/tmp/app/views/users/mailer/reset_password_instructions.html.erb +8 -0
  110. data/test/tmp/app/views/users/mailer/unlock_instructions.html.erb +7 -0
  111. data/test/tmp/app/views/users/passwords/edit.html.erb +19 -0
  112. data/test/tmp/app/views/users/passwords/new.html.erb +15 -0
  113. data/test/tmp/app/views/users/registrations/edit.html.erb +22 -0
  114. data/test/tmp/app/views/users/registrations/new.html.erb +17 -0
  115. data/test/tmp/app/views/users/sessions/new.html.erb +15 -0
  116. data/test/tmp/app/views/users/unlocks/new.html.erb +15 -0
  117. metadata +78 -26
  118. data/.gitignore +0 -12
  119. data/.travis.yml +0 -13
  120. data/Gemfile +0 -35
  121. data/Rakefile +0 -34
  122. data/devise.gemspec +0 -25
  123. data/lib/devise/controllers/internal_helpers.rb +0 -154
  124. data/lib/devise/controllers/shared_helpers.rb +0 -26
  125. data/test/schema_test.rb +0 -33
@@ -0,0 +1,169 @@
1
+ # All Devise controllers are inherited from here.
2
+ class DeviseController < Devise.parent_controller.constantize
3
+ include Devise::Controllers::ScopedViews
4
+
5
+ helper DeviseHelper
6
+
7
+ helpers = %w(resource scope_name resource_name signed_in_resource
8
+ resource_class devise_mapping devise_controller?)
9
+ hide_action *helpers
10
+ helper_method *helpers
11
+
12
+ prepend_before_filter :assert_is_devise_resource!
13
+ respond_to *Mime::SET.map(&:to_sym) if mimes_for_respond_to.empty?
14
+
15
+ # Gets the actual resource stored in the instance variable
16
+ def resource
17
+ instance_variable_get(:"@#{resource_name}")
18
+ end
19
+
20
+ # Proxy to devise map name
21
+ def resource_name
22
+ devise_mapping.name
23
+ end
24
+ alias :scope_name :resource_name
25
+
26
+ # Proxy to devise map class
27
+ def resource_class
28
+ devise_mapping.to
29
+ end
30
+
31
+ # Returns a signed in resource from session (if one exists)
32
+ def signed_in_resource
33
+ warden.authenticate(:scope => resource_name)
34
+ end
35
+
36
+ # Attempt to find the mapped route for devise based on request path
37
+ def devise_mapping
38
+ @devise_mapping ||= request.env["devise.mapping"]
39
+ end
40
+
41
+ # Overwrites devise_controller? to return true
42
+ def devise_controller?
43
+ true
44
+ end
45
+
46
+ protected
47
+
48
+ # Checks whether it's a devise mapped resource or not.
49
+ def assert_is_devise_resource! #:nodoc:
50
+ unknown_action! <<-MESSAGE unless devise_mapping
51
+ Could not find devise mapping for path #{request.fullpath.inspect}.
52
+ Maybe you forgot to wrap your route inside the scope block? For example:
53
+
54
+ devise_scope :user do
55
+ match "/some/route" => "some_devise_controller"
56
+ end
57
+ MESSAGE
58
+ end
59
+
60
+ # Returns real navigational formats which are supported by Rails
61
+ def navigational_formats
62
+ @navigational_formats ||= Devise.navigational_formats.select { |format| Mime::EXTENSION_LOOKUP[format.to_s] }
63
+ end
64
+
65
+ def unknown_action!(msg)
66
+ logger.debug "[Devise] #{msg}" if logger
67
+ raise AbstractController::ActionNotFound, msg
68
+ end
69
+
70
+ # Sets the resource creating an instance variable
71
+ def resource=(new_resource)
72
+ instance_variable_set(:"@#{resource_name}", new_resource)
73
+ end
74
+
75
+ # Build a devise resource.
76
+ def build_resource(hash=nil)
77
+ hash ||= params[resource_name] || {}
78
+ self.resource = resource_class.new(hash)
79
+ end
80
+
81
+ # Helper for use in before_filters where no authentication is required.
82
+ #
83
+ # Example:
84
+ # before_filter :require_no_authentication, :only => :new
85
+ def require_no_authentication
86
+ assert_is_devise_resource!
87
+ return unless is_navigational_format?
88
+ no_input = devise_mapping.no_input_strategies
89
+
90
+ authenticated = if no_input.present?
91
+ args = no_input.dup.push :scope => resource_name
92
+ warden.authenticate?(*args)
93
+ else
94
+ warden.authenticated?(resource_name)
95
+ end
96
+
97
+ if authenticated
98
+ resource = warden.user(resource_name)
99
+ flash[:alert] = I18n.t("devise.failure.already_authenticated")
100
+ redirect_to after_sign_in_path_for(resource)
101
+ end
102
+ end
103
+
104
+ # Helper for use after calling send_*_instructions methods on a resource.
105
+ # If we are in paranoid mode, we always act as if the resource was valid
106
+ # and instructions were sent.
107
+ def successfully_sent?(resource)
108
+ notice = if Devise.paranoid
109
+ resource.errors.clear
110
+ :send_paranoid_instructions
111
+ elsif resource.errors.empty?
112
+ :send_instructions
113
+ end
114
+
115
+ if notice
116
+ set_flash_message :notice, notice if is_navigational_format?
117
+ true
118
+ end
119
+ end
120
+
121
+ # Sets the flash message with :key, using I18n. By default you are able
122
+ # to setup your messages using specific resource scope, and if no one is
123
+ # found we look to default scope.
124
+ # Example (i18n locale file):
125
+ #
126
+ # en:
127
+ # devise:
128
+ # passwords:
129
+ # #default_scope_messages - only if resource_scope is not found
130
+ # user:
131
+ # #resource_scope_messages
132
+ #
133
+ # Please refer to README or en.yml locale file to check what messages are
134
+ # available.
135
+ def set_flash_message(key, kind, options={})
136
+ options[:scope] = "devise.#{controller_name}"
137
+ options[:default] = Array(options[:default]).unshift(kind.to_sym)
138
+ options[:resource_name] = resource_name
139
+ message = I18n.t("#{resource_name}.#{kind}", options)
140
+ flash[key] = message if message.present?
141
+ end
142
+
143
+ def clean_up_passwords(object)
144
+ object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
145
+ end
146
+
147
+ def respond_with_navigational(*args, &block)
148
+ respond_with(*args) do |format|
149
+ format.any(*navigational_formats, &block)
150
+ end
151
+ end
152
+
153
+ def request_format
154
+ @request_format ||= request.format.try(:ref)
155
+ end
156
+
157
+ def is_navigational_format?
158
+ Devise.navigational_formats.include?(request.format.try(:ref))
159
+ end
160
+
161
+ # Override prefixes to consider the scoped view.
162
+ def _prefixes #:nodoc:
163
+ @_prefixes ||= if self.class.scoped_views?
164
+ super.unshift("#{devise_mapping.scoped_path}/#{controller_name}")
165
+ else
166
+ super
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,25 @@
1
+ <%- if controller_name != 'sessions' %>
2
+ <%= link_to "Sign in", new_session_path(resource_name) %><br />
3
+ <% end -%>
4
+
5
+ <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
+ <%= link_to "Sign up", new_registration_path(resource_name) %><br />
7
+ <% end -%>
8
+
9
+ <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11
+ <% end -%>
12
+
13
+ <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15
+ <% end -%>
16
+
17
+ <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19
+ <% end -%>
20
+
21
+ <%- if devise_mapping.omniauthable? %>
22
+ <%- resource_class.omniauth_providers.each do |provider| %>
23
+ <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
24
+ <% end -%>
25
+ <% end -%>
@@ -9,4 +9,4 @@
9
9
  <div><%= f.submit "Resend confirmation instructions" %></div>
10
10
  <% end %>
11
11
 
12
- <%= render :partial => "devise/shared/links" %>
12
+ <%= render "links" %>
@@ -1,5 +1,5 @@
1
1
  <p>Welcome <%= @resource.email %>!</p>
2
2
 
3
- <p>You can confirm your account through the link below:</p>
3
+ <p>You can confirm your account email through the link below:</p>
4
4
 
5
5
  <p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
@@ -13,4 +13,4 @@
13
13
  <div><%= f.submit "Change my password" %></div>
14
14
  <% end %>
15
15
 
16
- <%= render :partial => "devise/shared/links" %>
16
+ <%= render "links" %>
@@ -9,4 +9,4 @@
9
9
  <div><%= f.submit "Send me reset password instructions" %></div>
10
10
  <% end %>
11
11
 
12
- <%= render :partial => "devise/shared/links" %>
12
+ <%= render "links" %>
@@ -15,4 +15,4 @@
15
15
  <div><%= f.submit "Sign up" %></div>
16
16
  <% end %>
17
17
 
18
- <%= render :partial => "devise/shared/links" %>
18
+ <%= render "links" %>
@@ -14,4 +14,4 @@
14
14
  <div><%= f.submit "Sign in" %></div>
15
15
  <% end %>
16
16
 
17
- <%= render :partial => "devise/shared/links" %>
17
+ <%= render "links" %>
@@ -1,25 +1,3 @@
1
- <%- if controller_name != 'sessions' %>
2
- <%= link_to "Sign in", new_session_path(resource_name) %><br />
3
- <% end -%>
4
-
5
- <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
- <%= link_to "Sign up", new_registration_path(resource_name) %><br />
7
- <% end -%>
8
-
9
- <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10
- <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11
- <% end -%>
12
-
13
- <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
- <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15
- <% end -%>
16
-
17
- <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18
- <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19
- <% end -%>
20
-
21
- <%- if devise_mapping.omniauthable? %>
22
- <%- resource_class.omniauth_providers.each do |provider| %>
23
- <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
24
- <% end -%>
25
- <% end -%>
1
+ <% ActiveSupport::Deprecation.warn "Rendering partials devise/shared/_links.erb is deprecated" \
2
+ "please use devise/_links.erb instead." %>
3
+ <%= render "links" %>
@@ -9,4 +9,4 @@
9
9
  <div><%= f.submit "Resend unlock instructions" %></div>
10
10
  <% end %>
11
11
 
12
- <%= render :partial => "devise/shared/links" %>
12
+ <%= render "links" %>
@@ -35,16 +35,15 @@ en:
35
35
  confirmed: 'Your account was successfully confirmed. You are now signed in.'
36
36
  registrations:
37
37
  signed_up: 'Welcome! You have signed up successfully.'
38
- inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
38
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
39
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
40
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
39
41
  updated: 'You updated your account successfully.'
42
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
40
43
  destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
41
- reasons:
42
- inactive: 'inactive'
43
- unconfirmed: 'unconfirmed'
44
- locked: 'locked'
45
44
  unlocks:
46
45
  send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
47
- unlocked: 'Your account was successfully unlocked. You are now signed in.'
46
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
48
47
  send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
49
48
  omniauth_callbacks:
50
49
  success: 'Successfully authorized from %{kind} account.'
@@ -168,7 +168,13 @@ module Devise
168
168
  def signed_in_root_path(resource_or_scope)
169
169
  scope = Devise::Mapping.find_scope!(resource_or_scope)
170
170
  home_path = "#{scope}_root_path"
171
- respond_to?(home_path, true) ? send(home_path) : root_path
171
+ if respond_to?(home_path, true)
172
+ send(home_path)
173
+ elsif respond_to?(:root_path)
174
+ root_path
175
+ else
176
+ "/"
177
+ end
172
178
  end
173
179
 
174
180
  # The default url to be used after signing in. This is used by all Devise
@@ -209,7 +215,7 @@ module Devise
209
215
  #
210
216
  # By default it is the root_path.
211
217
  def after_sign_out_path_for(resource_or_scope)
212
- root_path
218
+ respond_to?(:root_path) ? root_path : "/"
213
219
  end
214
220
 
215
221
  # Sign in a user and tries to redirect first to the stored location and
@@ -12,22 +12,6 @@ module Devise
12
12
  @scoped_views = value
13
13
  end
14
14
  end
15
-
16
- protected
17
-
18
- # Render a view for the specified scope. Turned off by default.
19
- # Accepts just :controller as option.
20
- def render_with_scope(action, path=self.controller_path)
21
- if self.class.scoped_views?
22
- begin
23
- render :template => "#{devise_mapping.scoped_path}/#{path.split("/").last}/#{action}"
24
- rescue ActionView::MissingTemplate
25
- render :template => "#{path}/#{action}"
26
- end
27
- else
28
- render :template => "#{path}/#{action}"
29
- end
30
- end
31
15
  end
32
16
  end
33
17
  end
@@ -16,7 +16,15 @@ module Devise
16
16
  # new_confirmation_path(:user) => new_user_confirmation_path
17
17
  # confirmation_path(:user) => user_confirmation_path
18
18
  #
19
- # Those helpers are added to your ApplicationController.
19
+ # Those helpers are included by default to ActionController::Base.
20
+ #
21
+ # In case you want to add such helpers to another class, you can do
22
+ # that as long as this new class includes both url_helpers and
23
+ # mounted_helpers. Example:
24
+ #
25
+ # include Rails.application.routes.url_helpers
26
+ # include Rails.application.routes.mounted_helpers
27
+ #
20
28
  module UrlHelpers
21
29
  def self.remove_helpers!
22
30
  self.instance_methods.map(&:to_s).grep(/_(url|path)$/).each do |method|
@@ -39,7 +47,7 @@ module Devise
39
47
  class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
40
48
  def #{method}(resource_or_scope, *args)
41
49
  scope = Devise::Mapping.find_scope!(resource_or_scope)
42
- send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
50
+ _devise_route_context.send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
43
51
  end
44
52
  URL_HELPERS
45
53
  end
@@ -48,6 +56,12 @@ module Devise
48
56
  end
49
57
 
50
58
  generate_helpers!(Devise::URL_HELPERS)
59
+
60
+ private
61
+
62
+ def _devise_route_context
63
+ @_devise_route_context ||= send(Devise.router_name)
64
+ end
51
65
  end
52
66
  end
53
67
  end
@@ -9,8 +9,9 @@ module Devise
9
9
  include ActionController::RackDelegation
10
10
  include ActionController::UrlFor
11
11
  include ActionController::Redirecting
12
+
12
13
  include Rails.application.routes.url_helpers
13
- include Devise::Controllers::SharedHelpers
14
+ include Rails.application.routes.mounted_helpers
14
15
 
15
16
  delegate :flash, :to => :request
16
17
 
@@ -20,7 +21,11 @@ module Devise
20
21
  end
21
22
 
22
23
  def self.default_url_options(*args)
23
- ApplicationController.default_url_options(*args)
24
+ if defined?(ApplicationController)
25
+ ApplicationController.default_url_options(*args)
26
+ else
27
+ {}
28
+ end
24
29
  end
25
30
 
26
31
  def respond
@@ -48,32 +53,50 @@ module Devise
48
53
 
49
54
  def redirect
50
55
  store_location!
51
- flash[:alert] = i18n_message
56
+ if flash[:timedout] && flash[:alert]
57
+ flash.keep(:timedout)
58
+ flash.keep(:alert)
59
+ else
60
+ flash[:alert] = i18n_message
61
+ end
52
62
  redirect_to redirect_url
53
63
  end
54
64
 
55
65
  protected
56
66
 
57
67
  def i18n_message(default = nil)
58
- message = warden.message || warden_options[:message] || default || :unauthenticated
68
+ message = warden_message || default || :unauthenticated
59
69
 
60
70
  if message.is_a?(Symbol)
61
71
  I18n.t(:"#{scope}.#{message}", :resource_name => scope,
62
- :scope => "devise.failure", :default => [message, message.to_s])
72
+ :scope => "devise.failure", :default => [message])
63
73
  else
64
74
  message.to_s
65
75
  end
66
76
  end
67
77
 
68
78
  def redirect_url
79
+ if warden_message == :timeout
80
+ flash[:timedout] = true
81
+ attempted_path || scope_path
82
+ else
83
+ scope_path
84
+ end
85
+ end
86
+
87
+ def scope_path
69
88
  opts = {}
70
89
  route = :"new_#{scope}_session_path"
71
90
  opts[:format] = request_format unless skip_format?
72
91
 
73
- if respond_to?(route)
74
- send(route, opts)
75
- else
92
+ context = send(Devise.router_name)
93
+
94
+ if context.respond_to?(route)
95
+ context.send(route, opts)
96
+ elsif respond_to?(:root_path)
76
97
  root_path(opts)
98
+ else
99
+ "/"
77
100
  end
78
101
  end
79
102
 
@@ -130,6 +153,10 @@ module Devise
130
153
  env['warden.options']
131
154
  end
132
155
 
156
+ def warden_message
157
+ @message ||= warden.message || warden_options[:message]
158
+ end
159
+
133
160
  def scope
134
161
  @scope ||= warden_options[:scope] || Devise.default_scope
135
162
  end
@@ -145,5 +172,13 @@ module Devise
145
172
  def store_location!
146
173
  session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
147
174
  end
175
+
176
+ def is_navigational_format?
177
+ Devise.navigational_formats.include?(request_format)
178
+ end
179
+
180
+ def request_format
181
+ @request_format ||= request.format.try(:ref)
182
+ end
148
183
  end
149
184
  end
@@ -25,6 +25,11 @@ module Devise
25
25
  # * +params_authenticatable+: if this model allows authentication through request params. By default true.
26
26
  # It also accepts an array specifying the strategies that should allow params authentication.
27
27
  #
28
+ # * +skip_session_storage+: By default Devise will store the user in session.
29
+ # You can skip storage for http and token auth by appending values to array:
30
+ # :skip_session_storage => [:token_auth] or :skip_session_storage => [:http_auth, :token_auth],
31
+ # by default is set to :skip_session_storage => [:http_auth].
32
+ #
28
33
  # == active_for_authentication?
29
34
  #
30
35
  # After authenticating a user and in each request, Devise checks if your model is active by
@@ -52,6 +57,9 @@ module Devise
52
57
  included do
53
58
  class_attribute :devise_modules, :instance_writer => false
54
59
  self.devise_modules ||= []
60
+
61
+ before_validation :downcase_keys
62
+ before_validation :strip_whitespace
55
63
  end
56
64
 
57
65
  # Check if the current object is valid for authentication. This method and
@@ -79,8 +87,21 @@ module Devise
79
87
  Devise.mailer
80
88
  end
81
89
 
90
+ def headers_for(name)
91
+ {}
92
+ end
93
+
94
+ def downcase_keys
95
+ (self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
96
+ end
97
+
98
+ def strip_whitespace
99
+ (self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) }
100
+ end
101
+
82
102
  module ClassMethods
83
- Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
103
+ Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,
104
+ :case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage)
84
105
 
85
106
  def serialize_into_session(record)
86
107
  [record.to_key, record.authenticatable_salt]