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.
- data/CHANGELOG.rdoc +98 -71
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -2
- data/app/controllers/devise/confirmations_controller.rb +3 -6
- data/app/controllers/devise/omniauth_callbacks_controller.rb +1 -3
- data/app/controllers/devise/passwords_controller.rb +3 -6
- data/app/controllers/devise/registrations_controller.rb +40 -42
- data/app/controllers/devise/sessions_controller.rb +2 -3
- data/app/controllers/devise/unlocks_controller.rb +4 -7
- data/app/controllers/devise_controller.rb +169 -0
- data/app/views/devise/_links.erb +25 -0
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +1 -1
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +1 -1
- data/app/views/devise/shared/_links.erb +3 -25
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +5 -6
- data/lib/devise/controllers/helpers.rb +8 -2
- data/lib/devise/controllers/scoped_views.rb +0 -16
- data/lib/devise/controllers/url_helpers.rb +16 -2
- data/lib/devise/failure_app.rb +43 -8
- data/lib/devise/models/authenticatable.rb +22 -1
- data/lib/devise/models/confirmable.rb +80 -22
- data/lib/devise/models/database_authenticatable.rb +0 -11
- data/lib/devise/models/lockable.rb +1 -1
- data/lib/devise/models/recoverable.rb +5 -5
- data/lib/devise/models/rememberable.rb +5 -20
- data/lib/devise/models/serializable.rb +5 -2
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +1 -4
- data/lib/devise/models/validatable.rb +1 -1
- data/lib/devise/models.rb +1 -1
- data/lib/devise/modules.rb +2 -2
- data/lib/devise/orm/active_record.rb +6 -0
- data/lib/devise/param_filter.rb +1 -1
- data/lib/devise/path_checker.rb +5 -1
- data/lib/devise/rails/routes.rb +16 -10
- data/lib/devise/rails/warden_compat.rb +0 -83
- data/lib/devise/rails.rb +61 -0
- data/lib/devise/schema.rb +5 -0
- data/lib/devise/strategies/authenticatable.rb +14 -10
- data/lib/devise/strategies/token_authenticatable.rb +3 -3
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +56 -33
- data/lib/generators/active_record/devise_generator.rb +40 -2
- data/lib/generators/active_record/templates/migration.rb +1 -19
- data/lib/generators/active_record/templates/migration_existing.rb +1 -9
- data/lib/generators/devise/views_generator.rb +6 -14
- data/lib/generators/mongoid/devise_generator.rb +43 -0
- data/lib/generators/templates/devise.rb +26 -12
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +1 -1
- data/test/controllers/internal_helpers_test.rb +5 -4
- data/test/devise_test.rb +2 -2
- data/test/failure_app_test.rb +24 -20
- data/test/generators/active_record_generator_test.rb +3 -13
- data/test/generators/views_generator_test.rb +1 -1
- data/test/integration/authenticatable_test.rb +4 -7
- data/test/integration/confirmable_test.rb +55 -3
- data/test/integration/http_authenticatable_test.rb +20 -5
- data/test/integration/lockable_test.rb +26 -14
- data/test/integration/registerable_test.rb +33 -2
- data/test/integration/rememberable_test.rb +0 -50
- data/test/integration/timeoutable_test.rb +18 -4
- data/test/integration/token_authenticatable_test.rb +5 -5
- data/test/integration/trackable_test.rb +6 -6
- data/test/mapping_test.rb +2 -3
- data/test/models/confirmable_test.rb +101 -8
- data/test/models/database_authenticatable_test.rb +6 -0
- data/test/models/encryptable_test.rb +1 -1
- data/test/models/lockable_test.rb +13 -0
- data/test/models/recoverable_test.rb +0 -27
- data/test/models/rememberable_test.rb +41 -160
- data/test/models/serializable_test.rb +1 -1
- data/test/models_test.rb +7 -7
- data/test/rails_app/app/mongoid/admin.rb +22 -1
- data/test/rails_app/app/mongoid/user.rb +35 -0
- data/test/rails_app/config/initializers/devise.rb +6 -7
- data/test/rails_app/config/routes.rb +3 -5
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +58 -12
- data/test/rails_app/lib/shared_admin.rb +6 -2
- data/test/rails_app/log/development.log +13 -0
- data/test/rails_app/log/test.log +319550 -0
- data/test/support/assertions.rb +4 -1
- data/test/support/helpers.rb +0 -17
- data/test/support/integration.rb +3 -1
- data/test/test_helpers_test.rb +2 -2
- data/test/tmp/app/views/devise/_links.erb +25 -0
- data/test/tmp/app/views/devise/confirmations/new.html.erb +15 -0
- data/test/tmp/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/test/tmp/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/test/tmp/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/test/tmp/app/views/devise/passwords/edit.html.erb +19 -0
- data/test/tmp/app/views/devise/passwords/new.html.erb +15 -0
- data/test/tmp/app/views/devise/registrations/edit.html.erb +22 -0
- data/test/tmp/app/views/devise/registrations/new.html.erb +17 -0
- data/test/tmp/app/views/devise/sessions/new.html.erb +15 -0
- data/test/tmp/app/views/devise/unlocks/new.html.erb +15 -0
- data/test/tmp/app/views/users/_links.erb +25 -0
- data/test/tmp/app/views/users/confirmations/new.html.erb +15 -0
- data/test/tmp/app/views/users/mailer/confirmation_instructions.html.erb +5 -0
- data/test/tmp/app/views/users/mailer/reset_password_instructions.html.erb +8 -0
- data/test/tmp/app/views/users/mailer/unlock_instructions.html.erb +7 -0
- data/test/tmp/app/views/users/passwords/edit.html.erb +19 -0
- data/test/tmp/app/views/users/passwords/new.html.erb +15 -0
- data/test/tmp/app/views/users/registrations/edit.html.erb +22 -0
- data/test/tmp/app/views/users/registrations/new.html.erb +17 -0
- data/test/tmp/app/views/users/sessions/new.html.erb +15 -0
- data/test/tmp/app/views/users/unlocks/new.html.erb +15 -0
- metadata +78 -26
- data/.gitignore +0 -12
- data/.travis.yml +0 -13
- data/Gemfile +0 -35
- data/Rakefile +0 -34
- data/devise.gemspec +0 -25
- data/lib/devise/controllers/internal_helpers.rb +0 -154
- data/lib/devise/controllers/shared_helpers.rb +0 -26
- 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 -%>
|
|
@@ -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>
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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" %>
|
data/config/locales/en.yml
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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)
|
|
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
|
|
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
|
data/lib/devise/failure_app.rb
CHANGED
|
@@ -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
|
|
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
|
|
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[:
|
|
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 =
|
|
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
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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,
|
|
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]
|