devise 1.0.11 → 1.1.pre
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.
- data/CHANGELOG.rdoc +6 -72
- data/Gemfile +18 -0
- data/README.rdoc +51 -46
- data/Rakefile +5 -4
- data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +2 -2
- data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +4 -3
- data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +11 -7
- data/app/controllers/{sessions_controller.rb → devise/sessions_controller.rb} +11 -8
- data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +2 -10
- data/app/models/devise/mailer.rb +55 -0
- data/app/views/{confirmations → devise/confirmations}/new.html.erb +1 -1
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/{passwords → devise/passwords}/edit.html.erb +1 -1
- data/app/views/{passwords → devise/passwords}/new.html.erb +1 -1
- data/app/views/{registrations → devise/registrations}/edit.html.erb +1 -1
- data/app/views/{registrations → devise/registrations}/new.html.erb +1 -1
- data/app/views/{sessions → devise/sessions}/new.html.erb +1 -1
- data/app/views/{shared/_devise_links.erb → devise/shared/_links.erb} +0 -0
- data/app/views/{unlocks → devise/unlocks}/new.html.erb +1 -1
- data/{lib/devise → config}/locales/en.yml +7 -1
- data/lib/devise.rb +6 -29
- data/lib/devise/controllers/helpers.rb +16 -43
- data/lib/devise/controllers/internal_helpers.rb +10 -36
- data/lib/devise/controllers/scoped_views.rb +35 -0
- data/lib/devise/failure_app.rb +7 -14
- data/lib/devise/hooks/rememberable.rb +3 -6
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mapping.rb +17 -18
- data/lib/devise/models.rb +4 -20
- data/lib/devise/models/{database_authenticatable.rb → authenticatable.rb} +16 -28
- data/lib/devise/models/confirmable.rb +25 -23
- data/lib/devise/models/http_authenticatable.rb +3 -7
- data/lib/devise/models/lockable.rb +40 -35
- data/lib/devise/models/recoverable.rb +4 -8
- data/lib/devise/models/rememberable.rb +6 -9
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +4 -5
- data/lib/devise/models/validatable.rb +10 -1
- data/lib/devise/orm/mongo_mapper.rb +10 -23
- data/lib/devise/rails.rb +11 -9
- data/lib/devise/rails/routes.rb +113 -107
- data/lib/devise/rails/warden_compat.rb +3 -41
- data/lib/devise/schema.rb +13 -21
- data/lib/devise/strategies/{database_authenticatable.rb → authenticatable.rb} +3 -3
- data/lib/devise/strategies/http_authenticatable.rb +4 -22
- data/lib/devise/test_helpers.rb +1 -8
- data/lib/devise/version.rb +1 -1
- data/lib/generators/devise/devise_generator.rb +57 -0
- data/{generators → lib/generators}/devise/templates/migration.rb +1 -1
- data/lib/generators/devise_install/devise_install_generator.rb +25 -0
- data/{generators → lib/generators}/devise_install/templates/README +4 -8
- data/{generators → lib/generators}/devise_install/templates/devise.rb +0 -3
- data/lib/generators/devise_views/devise_views_generator.rb +11 -0
- data/test/controllers/helpers_test.rb +15 -9
- data/test/devise_test.rb +1 -6
- data/test/encryptors_test.rb +0 -3
- data/test/failure_app_test.rb +6 -1
- data/test/integration/authenticatable_test.rb +25 -85
- data/test/integration/http_authenticatable_test.rb +2 -10
- data/test/integration/lockable_test.rb +3 -22
- data/test/integration/recoverable_test.rb +1 -1
- data/test/integration/registerable_test.rb +31 -36
- data/test/integration/rememberable_test.rb +6 -24
- data/test/integration/token_authenticatable_test.rb +2 -4
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +4 -10
- data/test/mailers/unlock_instructions_test.rb +1 -1
- data/test/mapping_test.rb +12 -24
- data/test/models/authenticatable_test.rb +3 -3
- data/test/models/confirmable_test.rb +29 -29
- data/test/models/http_authenticatable_test.rb +19 -0
- data/test/models/lockable_test.rb +45 -44
- data/test/models/recoverable_test.rb +7 -7
- data/test/models/rememberable_test.rb +7 -10
- data/test/models/validatable_test.rb +19 -24
- data/test/models_test.rb +2 -16
- data/test/orm/active_record.rb +3 -4
- data/test/orm/mongo_mapper.rb +2 -10
- data/test/rails_app/app/active_record/admin.rb +1 -1
- data/test/rails_app/app/active_record/user.rb +3 -3
- data/test/rails_app/app/controllers/application_controller.rb +1 -7
- data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/users_controller.rb +0 -4
- data/test/rails_app/app/mongo_mapper/admin.rb +4 -7
- data/test/rails_app/app/mongo_mapper/user.rb +5 -8
- data/test/rails_app/config/application.rb +32 -0
- data/test/rails_app/config/boot.rb +7 -108
- data/test/rails_app/config/environment.rb +4 -41
- data/test/rails_app/config/environments/development.rb +15 -13
- data/test/rails_app/config/environments/production.rb +25 -20
- data/test/rails_app/config/environments/test.rb +23 -22
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +0 -3
- data/test/rails_app/config/initializers/session_store.rb +2 -2
- data/test/rails_app/config/routes.rb +17 -21
- data/test/routes_test.rb +30 -47
- data/test/support/{assertions_helper.rb → assertions.rb} +0 -15
- data/test/support/{tests_helper.rb → helpers.rb} +16 -3
- data/test/support/{integration_tests_helper.rb → integration.rb} +8 -4
- data/test/support/webrat/integrations/rails.rb +31 -0
- data/test/test_helper.rb +8 -7
- data/test/test_helpers_test.rb +9 -9
- metadata +53 -128
- data/app/models/devise_mailer.rb +0 -68
- data/app/views/devise_mailer/confirmation_instructions.html.erb +0 -5
- data/app/views/devise_mailer/reset_password_instructions.html.erb +0 -8
- data/app/views/devise_mailer/unlock_instructions.html.erb +0 -7
- data/generators/devise/USAGE +0 -5
- data/generators/devise/devise_generator.rb +0 -15
- data/generators/devise/lib/route_devise.rb +0 -32
- data/generators/devise/templates/model.rb +0 -9
- data/generators/devise_install/USAGE +0 -3
- data/generators/devise_install/devise_install_generator.rb +0 -15
- data/generators/devise_views/USAGE +0 -3
- data/generators/devise_views/devise_views_generator.rb +0 -21
- data/rails/init.rb +0 -2
- data/test/integration/rack_middleware_test.rb +0 -47
- data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
@@ -1,6 +1,4 @@
|
|
1
|
-
class UnlocksController < ApplicationController
|
2
|
-
prepend_before_filter :ensure_email_as_unlock_strategy
|
3
|
-
prepend_before_filter :require_no_authentication
|
1
|
+
class Devise::UnlocksController < ApplicationController
|
4
2
|
include Devise::Controllers::InternalHelpers
|
5
3
|
|
6
4
|
# GET /resource/unlock/new
|
@@ -23,7 +21,7 @@ class UnlocksController < ApplicationController
|
|
23
21
|
|
24
22
|
# GET /resource/unlock?unlock_token=abcdef
|
25
23
|
def show
|
26
|
-
self.resource = resource_class.
|
24
|
+
self.resource = resource_class.unlock!(:unlock_token => params[:unlock_token])
|
27
25
|
|
28
26
|
if resource.errors.empty?
|
29
27
|
set_flash_message :notice, :unlocked
|
@@ -32,10 +30,4 @@ class UnlocksController < ApplicationController
|
|
32
30
|
render_with_scope :new
|
33
31
|
end
|
34
32
|
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
|
38
|
-
def ensure_email_as_unlock_strategy
|
39
|
-
raise ActionController::UnknownAction unless resource_class.unlock_strategy_enabled?(:email)
|
40
|
-
end
|
41
33
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Devise::Mailer < ::ActionMailer::Base
|
2
|
+
include Devise::Controllers::ScopedViews
|
3
|
+
|
4
|
+
attr_reader :devise_mapping, :resource
|
5
|
+
|
6
|
+
def confirmation_instructions(record)
|
7
|
+
setup_mail(record, :confirmation_instructions)
|
8
|
+
end
|
9
|
+
|
10
|
+
def reset_password_instructions(record)
|
11
|
+
setup_mail(record, :reset_password_instructions)
|
12
|
+
end
|
13
|
+
|
14
|
+
def unlock_instructions(record)
|
15
|
+
setup_mail(record, :unlock_instructions)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
# Configure default email options
|
21
|
+
def setup_mail(record, action)
|
22
|
+
@devise_mapping = Devise::Mapping.find_by_class(record.class)
|
23
|
+
|
24
|
+
raise "Invalid devise resource #{record}" unless @devise_mapping
|
25
|
+
@resource = instance_variable_set("@#{@devise_mapping.name}", record)
|
26
|
+
|
27
|
+
mail(:subject => translate(@devise_mapping, action),
|
28
|
+
:from => mailer_sender(@devise_mapping), :to => record.email) do |format|
|
29
|
+
format.html { render_with_scope(action, :controller => "mailer") }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def mailer_sender(mapping)
|
34
|
+
if Devise.mailer_sender.is_a?(Proc)
|
35
|
+
block_args = mapping.name if Devise.mailer_sender.arity > 0
|
36
|
+
Devise.mailer_sender.call(block_args)
|
37
|
+
else
|
38
|
+
Devise.mailer_sender
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Setup subject namespaced by model. It means you're able to setup your
|
43
|
+
# messages using specific resource scope, or provide a default one.
|
44
|
+
# Example (i18n locale file):
|
45
|
+
#
|
46
|
+
# en:
|
47
|
+
# devise:
|
48
|
+
# mailer:
|
49
|
+
# confirmation_instructions: '...'
|
50
|
+
# user:
|
51
|
+
# confirmation_instructions: '...'
|
52
|
+
def translate(mapping, key)
|
53
|
+
I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :mailer], :default => key)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Hello <%= @resource.email %>!
|
2
|
+
|
3
|
+
Someone has requested a link to change your password, and you can do this through the link below.
|
4
|
+
|
5
|
+
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
|
6
|
+
|
7
|
+
If you didn't request this, please ignore this email.
|
8
|
+
Your password won't change until you access the link above and create a new one.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Hello <%= @resource.email %>!
|
2
|
+
|
3
|
+
Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
|
4
|
+
|
5
|
+
Click the link below to unlock your account:
|
6
|
+
|
7
|
+
<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>
|
File without changes
|
@@ -1,4 +1,10 @@
|
|
1
1
|
en:
|
2
|
+
errors:
|
3
|
+
messages:
|
4
|
+
not_found: "not found"
|
5
|
+
already_confirmed: "was already confirmed"
|
6
|
+
not_locked: "was not locked"
|
7
|
+
|
2
8
|
devise:
|
3
9
|
sessions:
|
4
10
|
link: 'Sign in'
|
@@ -21,7 +27,7 @@ en:
|
|
21
27
|
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
22
28
|
registrations:
|
23
29
|
link: 'Sign up'
|
24
|
-
signed_up: 'You have signed up successfully.
|
30
|
+
signed_up: 'You have signed up successfully.'
|
25
31
|
updated: 'You updated your account successfully.'
|
26
32
|
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
27
33
|
unlocks:
|
data/lib/devise.rb
CHANGED
@@ -7,6 +7,7 @@ module Devise
|
|
7
7
|
module Controllers
|
8
8
|
autoload :Helpers, 'devise/controllers/helpers'
|
9
9
|
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
10
|
+
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
10
11
|
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
11
12
|
end
|
12
13
|
|
@@ -29,7 +30,7 @@ module Devise
|
|
29
30
|
ALL = []
|
30
31
|
|
31
32
|
# Authentication ones first
|
32
|
-
ALL.push :
|
33
|
+
ALL.push :authenticatable, :http_authenticatable, :token_authenticatable, :rememberable
|
33
34
|
|
34
35
|
# Misc after
|
35
36
|
ALL.push :recoverable, :registerable, :validatable
|
@@ -42,7 +43,7 @@ module Devise
|
|
42
43
|
|
43
44
|
# Maps controller names to devise modules.
|
44
45
|
CONTROLLERS = {
|
45
|
-
:sessions => [:
|
46
|
+
:sessions => [:authenticatable, :token_authenticatable],
|
46
47
|
:passwords => [:recoverable],
|
47
48
|
:confirmations => [:confirmable],
|
48
49
|
:registrations => [:registerable],
|
@@ -52,7 +53,7 @@ module Devise
|
|
52
53
|
# Routes for generating url helpers.
|
53
54
|
ROUTES = [:session, :password, :confirmation, :registration, :unlock]
|
54
55
|
|
55
|
-
STRATEGIES = [:rememberable, :http_authenticatable, :token_authenticatable, :
|
56
|
+
STRATEGIES = [:rememberable, :http_authenticatable, :token_authenticatable, :authenticatable]
|
56
57
|
|
57
58
|
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
|
58
59
|
|
@@ -147,10 +148,6 @@ module Devise
|
|
147
148
|
mattr_accessor :mailer_sender
|
148
149
|
@@mailer_sender = nil
|
149
150
|
|
150
|
-
# Content Type of Devise e-mails.
|
151
|
-
mattr_accessor :mailer_content_type
|
152
|
-
@@mailer_content_type = 'text/html'
|
153
|
-
|
154
151
|
# Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
|
155
152
|
mattr_accessor :token_authentication_key
|
156
153
|
@@token_authentication_key = :auth_token
|
@@ -183,9 +180,7 @@ module Devise
|
|
183
180
|
|
184
181
|
# Configure default url options to be used within Devise and ActionController.
|
185
182
|
def default_url_options(&block)
|
186
|
-
|
187
|
-
Devise::Mapping.singleton_class : Devise::Mapping.metaclass
|
188
|
-
who.send :define_method, :default_url_options, &block
|
183
|
+
Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
|
189
184
|
end
|
190
185
|
|
191
186
|
# A method used internally to setup warden manager from the Rails initialize
|
@@ -210,17 +205,6 @@ module Devise
|
|
210
205
|
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
211
206
|
end
|
212
207
|
|
213
|
-
# constant-time comparison algorithm to prevent timing attacks
|
214
|
-
def secure_compare(a, b)
|
215
|
-
return false unless a.present? && b.present?
|
216
|
-
return false unless a.bytesize == b.bytesize
|
217
|
-
l = a.unpack "C#{a.bytesize}"
|
218
|
-
|
219
|
-
res = 0
|
220
|
-
b.each_byte { |byte| res |= byte ^ l.shift }
|
221
|
-
res == 0
|
222
|
-
end
|
223
|
-
|
224
208
|
# Make Devise aware of an 3rd party Devise-module. For convenience.
|
225
209
|
#
|
226
210
|
# == Options:
|
@@ -231,9 +215,6 @@ module Devise
|
|
231
215
|
# Default is +nil+ (i.e. +false+).
|
232
216
|
# +controller+ - Symbol representing a name of an exisiting or custom *controller* for this module.
|
233
217
|
# Default is +nil+ (i.e. +false+).
|
234
|
-
# +route+ - Symbol representing the name of a *route* related to this module which a set of
|
235
|
-
# route view helpers should be created for.
|
236
|
-
# Default is +nil+ (i.e. +false+).
|
237
218
|
#
|
238
219
|
# == Examples:
|
239
220
|
#
|
@@ -242,7 +223,7 @@ module Devise
|
|
242
223
|
# Devise.add_module(:party_module, :model => 'party_module/model')
|
243
224
|
#
|
244
225
|
def add_module(module_name, options = {})
|
245
|
-
Devise::ALL
|
226
|
+
Devise::ALL.unshift module_name unless Devise::ALL.include?(module_name)
|
246
227
|
Devise::STRATEGIES.unshift module_name if options[:strategy] && !Devise::STRATEGIES.include?(module_name)
|
247
228
|
|
248
229
|
if options[:controller]
|
@@ -251,10 +232,6 @@ module Devise
|
|
251
232
|
Devise::CONTROLLERS[controller].unshift module_name unless Devise::CONTROLLERS[controller].include?(module_name)
|
252
233
|
end
|
253
234
|
|
254
|
-
if options[:route]
|
255
|
-
Devise::ROUTES.unshift options[:route] unless Devise::ROUTES.include?(options[:route])
|
256
|
-
end
|
257
|
-
|
258
235
|
if options[:model]
|
259
236
|
Devise::Models.module_eval do
|
260
237
|
autoload :"#{module_name.to_s.classify}", options[:model]
|
@@ -2,17 +2,16 @@ module Devise
|
|
2
2
|
module Controllers
|
3
3
|
# Those helpers are convenience methods added to ApplicationController.
|
4
4
|
module Helpers
|
5
|
+
extend ActiveSupport::Concern
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?", :"#{m}_session"] }.flatten
|
7
|
+
included do
|
8
|
+
helper_method :warden, :signed_in?, :devise_controller?,
|
9
|
+
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
11
|
+
# Use devise default_url_options. We have to declare it here to overwrite
|
12
|
+
# default definitions.
|
13
|
+
def default_url_options(options=nil)
|
14
|
+
Devise::Mapping.default_url_options
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -48,12 +47,6 @@ module Devise
|
|
48
47
|
warden.authenticate?(:scope => scope)
|
49
48
|
end
|
50
49
|
|
51
|
-
# Check if the any scope is signed in session, without running
|
52
|
-
# authentication hooks.
|
53
|
-
def anybody_signed_in?
|
54
|
-
Devise.mappings.keys.any? { |scope| signed_in?(scope) }
|
55
|
-
end
|
56
|
-
|
57
50
|
# Sign in an user that already was authenticated. This helper is useful for logging
|
58
51
|
# users in after sign up.
|
59
52
|
#
|
@@ -66,7 +59,6 @@ module Devise
|
|
66
59
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
67
60
|
resource ||= resource_or_scope
|
68
61
|
warden.set_user(resource, :scope => scope)
|
69
|
-
@_session = request.session # Recalculate session
|
70
62
|
end
|
71
63
|
|
72
64
|
# Sign out a given user or scope. This helper is useful for signing out an user
|
@@ -93,8 +85,7 @@ module Devise
|
|
93
85
|
#
|
94
86
|
def stored_location_for(resource_or_scope)
|
95
87
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
96
|
-
|
97
|
-
session.delete(key) || session.delete(key.to_sym)
|
88
|
+
session.delete(:"#{scope}.return_to")
|
98
89
|
end
|
99
90
|
|
100
91
|
# The default url to be used after signing in. This is used by all Devise
|
@@ -107,13 +98,13 @@ module Devise
|
|
107
98
|
#
|
108
99
|
# map.user_root '/users', :controller => 'users' # creates user_root_path
|
109
100
|
#
|
110
|
-
# map.
|
111
|
-
#
|
101
|
+
# map.resources :users do |users|
|
102
|
+
# users.root # creates user_root_path
|
112
103
|
# end
|
113
104
|
#
|
114
105
|
#
|
115
|
-
# If
|
116
|
-
#
|
106
|
+
# If none of these are defined, root_path is used. However, if this default
|
107
|
+
# is not enough, you can customize it, for example:
|
117
108
|
#
|
118
109
|
# def after_sign_in_path_for(resource)
|
119
110
|
# if resource.is_a?(User) && resource.can_publish?
|
@@ -125,7 +116,7 @@ module Devise
|
|
125
116
|
#
|
126
117
|
def after_sign_in_path_for(resource_or_scope)
|
127
118
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
128
|
-
home_path = "#{scope}_root_path"
|
119
|
+
home_path = :"#{scope}_root_path"
|
129
120
|
respond_to?(home_path, true) ? send(home_path) : root_path
|
130
121
|
end
|
131
122
|
|
@@ -147,11 +138,7 @@ module Devise
|
|
147
138
|
def sign_in_and_redirect(resource_or_scope, resource=nil, skip=false)
|
148
139
|
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
149
140
|
resource ||= resource_or_scope
|
150
|
-
|
151
|
-
@_session = request.session # Recalculate session
|
152
|
-
else
|
153
|
-
sign_in(scope, resource)
|
154
|
-
end
|
141
|
+
sign_in(scope, resource) unless skip
|
155
142
|
redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
|
156
143
|
end
|
157
144
|
|
@@ -163,20 +150,6 @@ module Devise
|
|
163
150
|
redirect_to after_sign_out_path_for(scope)
|
164
151
|
end
|
165
152
|
|
166
|
-
# Sign out all active users or scopes. This helper is useful for signing out all roles
|
167
|
-
# in one click. This signs out ALL scopes in warden.
|
168
|
-
def sign_out_all_scopes
|
169
|
-
Devise.mappings.keys.each { |s| warden.user(s) }
|
170
|
-
warden.raw_session.inspect
|
171
|
-
warden.logout
|
172
|
-
end
|
173
|
-
|
174
|
-
# Override Rails' handle unverified request to sign out all scopes.
|
175
|
-
def handle_unverified_request
|
176
|
-
sign_out_all_scopes
|
177
|
-
super # call the default behaviour which resets the session
|
178
|
-
end
|
179
|
-
|
180
153
|
# Define authentication filters and accessor helpers based on mappings.
|
181
154
|
# These filters should be used inside the controllers as before_filters,
|
182
155
|
# so you can control the scope of the user who should be signed in to
|
@@ -193,7 +166,7 @@ module Devise
|
|
193
166
|
# user_signed_in? # Checks whether there is an user signed in or not
|
194
167
|
# admin_signed_in? # Checks whether there is an admin signed in or not
|
195
168
|
# current_user # Current signed in user
|
196
|
-
# current_admin #
|
169
|
+
# current_admin # Currend signed in admin
|
197
170
|
# user_session # Session data available only to the user scope
|
198
171
|
# admin_session # Session data available only to the admin scope
|
199
172
|
#
|
@@ -4,28 +4,18 @@ module Devise
|
|
4
4
|
# included in ApplicationController since they all depend on the url being
|
5
5
|
# accessed.
|
6
6
|
module InternalHelpers #:nodoc:
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include Devise::Controllers::ScopedViews
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
unloadable
|
10
|
+
included do
|
11
|
+
helpers = [:resource, :scope_name, :resource_name,
|
12
|
+
:resource_class, :devise_mapping, :devise_controller?]
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
hide_action *helpers
|
15
|
+
helper_method *helpers
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module ScopedViews
|
22
|
-
def scoped_views
|
23
|
-
defined?(@scoped_views) ? @scoped_views : Devise.scoped_views
|
24
|
-
end
|
25
|
-
|
26
|
-
def scoped_views=(value)
|
27
|
-
@scoped_views = value
|
28
|
-
end
|
17
|
+
before_filter :is_devise_resource?
|
18
|
+
skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
|
29
19
|
end
|
30
20
|
|
31
21
|
# Gets the actual resource stored in the instance variable
|
@@ -72,7 +62,7 @@ module Devise
|
|
72
62
|
|
73
63
|
# Build a devise resource.
|
74
64
|
def build_resource
|
75
|
-
self.resource
|
65
|
+
self.resource = resource_class.new(params[resource_name] || {})
|
76
66
|
end
|
77
67
|
|
78
68
|
# Helper for use in before_filters where no authentication is required.
|
@@ -108,22 +98,6 @@ module Devise
|
|
108
98
|
set_flash_message(key, kind, true)
|
109
99
|
end
|
110
100
|
|
111
|
-
# Render a view for the specified scope. Turned off by default.
|
112
|
-
# Accepts just :controller as option.
|
113
|
-
def render_with_scope(action, options={})
|
114
|
-
controller_name = options.delete(:controller) || self.controller_name
|
115
|
-
|
116
|
-
if self.class.scoped_views
|
117
|
-
begin
|
118
|
-
render :template => "#{controller_name}/#{devise_mapping.as}/#{action}"
|
119
|
-
rescue ActionView::MissingTemplate
|
120
|
-
render action, :controller => controller_name
|
121
|
-
end
|
122
|
-
else
|
123
|
-
render action, :controller => controller_name
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
101
|
end
|
128
102
|
end
|
129
103
|
end
|