devise 1.1.9 → 1.2.rc
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.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +34 -26
- data/README.rdoc +134 -100
- data/app/controllers/devise/confirmations_controller.rb +1 -1
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +1 -1
- data/app/controllers/devise/registrations_controller.rb +59 -6
- data/app/controllers/devise/sessions_controller.rb +3 -2
- data/app/controllers/devise/unlocks_controller.rb +1 -1
- data/app/helpers/devise_helper.rb +4 -2
- data/app/mailers/devise/mailer.rb +27 -10
- data/app/views/devise/confirmations/new.html.erb +1 -1
- data/app/views/devise/passwords/edit.html.erb +2 -2
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/edit.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 +6 -0
- data/app/views/devise/unlocks/new.html.erb +1 -1
- data/config/locales/en.yml +9 -2
- data/lib/devise.rb +116 -58
- data/lib/devise/controllers/helpers.rb +103 -107
- data/lib/devise/controllers/internal_helpers.rb +23 -7
- data/lib/devise/controllers/scoped_views.rb +4 -6
- data/lib/devise/controllers/url_helpers.rb +3 -5
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/restful_authentication_sha1.rb +4 -4
- data/lib/devise/failure_app.rb +29 -21
- data/lib/devise/hooks/forgetable.rb +2 -1
- data/lib/devise/hooks/rememberable.rb +11 -9
- data/lib/devise/mapping.rb +12 -5
- data/lib/devise/models.rb +0 -14
- data/lib/devise/models/authenticatable.rb +40 -30
- data/lib/devise/models/confirmable.rb +11 -15
- data/lib/devise/models/database_authenticatable.rb +23 -35
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +8 -7
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +5 -3
- data/lib/devise/models/registerable.rb +13 -0
- data/lib/devise/models/rememberable.rb +38 -30
- data/lib/devise/models/timeoutable.rb +20 -3
- data/lib/devise/models/token_authenticatable.rb +19 -7
- data/lib/devise/models/validatable.rb +16 -4
- data/lib/devise/modules.rb +15 -8
- data/lib/devise/omniauth.rb +47 -0
- data/lib/devise/omniauth/config.rb +30 -0
- data/lib/devise/omniauth/test_helpers.rb +57 -0
- data/lib/devise/omniauth/url_helpers.rb +29 -0
- data/lib/devise/orm/active_record.rb +2 -0
- data/lib/devise/orm/mongoid.rb +4 -2
- data/lib/devise/rails.rb +26 -46
- data/lib/devise/rails/routes.rb +64 -20
- data/lib/devise/rails/warden_compat.rb +18 -20
- data/lib/devise/schema.rb +13 -14
- data/lib/devise/strategies/authenticatable.rb +33 -7
- data/lib/devise/strategies/database_authenticatable.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +1 -1
- data/lib/devise/strategies/token_authenticatable.rb +6 -2
- data/lib/devise/test_helpers.rb +11 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +1 -0
- data/lib/generators/devise/orm_helpers.rb +3 -2
- data/lib/generators/templates/devise.rb +70 -39
- data/test/controllers/helpers_test.rb +43 -67
- data/test/controllers/internal_helpers_test.rb +29 -8
- data/test/controllers/url_helpers_test.rb +2 -1
- data/test/failure_app_test.rb +56 -21
- data/test/generators/generators_test_helper.rb +4 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/views_generator_test.rb +37 -0
- data/test/integration/authenticatable_test.rb +147 -62
- data/test/integration/database_authenticatable_test.rb +22 -0
- data/test/integration/http_authenticatable_test.rb +12 -2
- data/test/integration/omniauthable_test.rb +107 -0
- data/test/integration/recoverable_test.rb +39 -20
- data/test/integration/registerable_test.rb +30 -4
- data/test/integration/rememberable_test.rb +57 -34
- data/test/integration/timeoutable_test.rb +10 -1
- data/test/integration/token_authenticatable_test.rb +12 -17
- data/test/mailers/confirmation_instructions_test.rb +4 -0
- data/test/mailers/reset_password_instructions_test.rb +4 -0
- data/test/mailers/unlock_instructions_test.rb +4 -0
- data/test/mapping_test.rb +37 -3
- data/test/models/confirmable_test.rb +3 -3
- data/test/models/database_authenticatable_test.rb +14 -71
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +17 -1
- data/test/models/recoverable_test.rb +17 -0
- data/test/models/rememberable_test.rb +186 -125
- data/test/models/token_authenticatable_test.rb +1 -13
- data/test/models_test.rb +5 -5
- data/test/omniauth/url_helpers_test.rb +47 -0
- data/test/rails_app/app/active_record/admin.rb +4 -1
- data/test/rails_app/app/active_record/user.rb +5 -4
- data/test/rails_app/app/controllers/{sessions_controller.rb → admins/sessions_controller.rb} +1 -1
- data/test/rails_app/app/controllers/home_controller.rb +9 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +7 -0
- data/test/rails_app/app/mongoid/admin.rb +4 -1
- data/test/rails_app/app/mongoid/shim.rb +16 -3
- data/test/rails_app/app/mongoid/user.rb +5 -5
- data/test/rails_app/config/initializers/devise.rb +52 -28
- data/test/rails_app/config/routes.rb +14 -6
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +21 -17
- data/test/rails_app/db/schema.rb +17 -51
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +23 -0
- data/test/routes_test.rb +42 -9
- data/test/support/integration.rb +3 -3
- data/test/support/webrat/integrations/rails.rb +7 -0
- data/test/test_helper.rb +2 -0
- data/test/test_helpers_test.rb +29 -0
- metadata +60 -30
- data/Gemfile +0 -27
- data/Gemfile.lock +0 -115
- data/Rakefile +0 -55
- data/TODO +0 -3
- data/lib/devise/encryptors/bcrypt.rb +0 -19
- data/lib/generators/devise_install_generator.rb +0 -4
- data/lib/generators/devise_views_generator.rb +0 -4
- data/test/indifferent_hash.rb +0 -33
- data/test/support/test_silencer.rb +0 -5
@@ -0,0 +1,29 @@
|
|
1
|
+
module Devise
|
2
|
+
module OmniAuth
|
3
|
+
module UrlHelpers
|
4
|
+
def self.define_helpers(mapping)
|
5
|
+
return unless mapping.omniauthable?
|
6
|
+
|
7
|
+
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
8
|
+
def #{mapping.name}_omniauth_authorize_path(provider, params = {})
|
9
|
+
if Devise.omniauth_configs[provider.to_sym]
|
10
|
+
"/#{mapping.path}/auth/\#{provider}\#{'?'+params.to_param if params.present?}"
|
11
|
+
else
|
12
|
+
raise ArgumentError, "Could not find omniauth provider \#{provider.inspect}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
URL_HELPERS
|
16
|
+
end
|
17
|
+
|
18
|
+
def omniauth_authorize_path(resource_or_scope, *args)
|
19
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
20
|
+
send("#{scope}_omniauth_authorize_path", *args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def omniauth_callback_path(resource_or_scope, *args)
|
24
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
25
|
+
send("#{scope}_omniauth_callback_path", *args)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/devise/orm/mongoid.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'orm_adapter/adapters/mongoid'
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module Orm
|
3
5
|
module Mongoid
|
@@ -16,7 +18,7 @@ module Devise
|
|
16
18
|
# Tell how to apply schema methods
|
17
19
|
def apply_devise_schema(name, type, options={})
|
18
20
|
type = Time if type == DateTime
|
19
|
-
field name, { :type => type }.merge(options)
|
21
|
+
field name, { :type => type }.merge!(options)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -26,4 +28,4 @@ end
|
|
26
28
|
Mongoid::Document::ClassMethods.class_eval do
|
27
29
|
include Devise::Models
|
28
30
|
include Devise::Orm::Mongoid::Hook
|
29
|
-
end
|
31
|
+
end
|
data/lib/devise/rails.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'devise/rails/routes'
|
2
2
|
require 'devise/rails/warden_compat'
|
3
3
|
|
4
|
-
# Include UrlHelpers in ActionController and ActionView as soon as they are loaded.
|
5
|
-
ActiveSupport.on_load(:action_controller) { include Devise::Controllers::UrlHelpers }
|
6
|
-
ActiveSupport.on_load(:action_view) { include Devise::Controllers::UrlHelpers }
|
7
|
-
|
8
4
|
module Devise
|
9
5
|
class Engine < ::Rails::Engine
|
10
6
|
config.devise = Devise
|
11
7
|
|
8
|
+
# Initialize Warden and copy its configurations.
|
12
9
|
config.app_middleware.use Warden::Manager do |config|
|
13
10
|
Devise.warden_config = config
|
14
11
|
end
|
@@ -16,54 +13,37 @@ module Devise
|
|
16
13
|
# Force routes to be loaded if we are doing any eager load.
|
17
14
|
config.before_eager_load { |app| app.reload_routes! }
|
18
15
|
|
19
|
-
|
20
|
-
Devise.
|
21
|
-
warn "[WARNING] config.encryptor is not set in your config/initializers/devise.rb. " \
|
22
|
-
"Devise will then set it to :bcrypt. If you were using the previous default " \
|
23
|
-
"encryptor, please add config.encryptor = :sha1 to your configuration file." if Devise.mailer_sender
|
24
|
-
:bcrypt
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
initializer "devise.add_filters" do |app|
|
29
|
-
app.config.filter_parameters += [:password, :password_confirmation]
|
30
|
-
app.config.filter_parameters.uniq
|
16
|
+
initializer "devise.url_helpers" do
|
17
|
+
Devise.include_helpers(Devise::Controllers)
|
31
18
|
end
|
32
19
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
translations = begin
|
38
|
-
I18n.t("devise.mailer", :raise => true).map { |k, v| k if v.is_a?(String) }.compact
|
39
|
-
rescue Exception => e # Do not care if something fails
|
40
|
-
[]
|
41
|
-
end
|
42
|
-
|
43
|
-
keys = actions & translations
|
44
|
-
|
45
|
-
keys.each do |key|
|
46
|
-
ActiveSupport::Deprecation.warn "The I18n message 'devise.mailer.#{key}' is deprecated. " \
|
47
|
-
"Please use 'devise.mailer.#{key}.subject' instead."
|
20
|
+
initializer "devise.omniauth" do |app|
|
21
|
+
Devise.omniauth_configs.each do |provider, config|
|
22
|
+
app.middleware.use config.strategy_class, *config.args do |strategy|
|
23
|
+
config.strategy = strategy
|
48
24
|
end
|
49
25
|
end
|
50
26
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
I18n.t("devise.sessions", :raise => true).keys
|
56
|
-
rescue Exception => e # Do not care if something fails
|
57
|
-
[]
|
58
|
-
end
|
59
|
-
|
60
|
-
keys = flash & translations
|
27
|
+
if Devise.omniauth_configs.any?
|
28
|
+
Devise.include_helpers(Devise::OmniAuth)
|
29
|
+
end
|
30
|
+
end
|
61
31
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
32
|
+
initializer "devise.encryptor_check" do
|
33
|
+
case Devise.encryptor
|
34
|
+
when :bcrypt
|
35
|
+
puts "[DEVISE] From version 1.2, there is no need to set your encryptor to bcrypt " <<
|
36
|
+
"since encryptors are only enabled if you include :encryptable in your models. " <<
|
37
|
+
"With this change, we can integrate better with bcrypt and get rid of the " <<
|
38
|
+
"password_salt column (since bcrypt stores the salt with password). " <<
|
39
|
+
"Please comment config.encryptor in your initializer to get rid of this warning."
|
40
|
+
when nil
|
41
|
+
# Nothing to say
|
42
|
+
else
|
43
|
+
puts "[DEVISE] You are using #{Devise.encryptor} as encryptor. From version 1.2, " <<
|
44
|
+
"you need to explicitly add `devise :encryptable, :encryptor => #{Devise.encryptor.to_sym}` " <<
|
45
|
+
"to your models and comment the current value in the config/initializers/devise.rb"
|
66
46
|
end
|
67
47
|
end
|
68
48
|
end
|
69
|
-
end
|
49
|
+
end
|
data/lib/devise/rails/routes.rb
CHANGED
@@ -5,7 +5,6 @@ module ActionDispatch::Routing
|
|
5
5
|
def finalize_with_devise!
|
6
6
|
finalize_without_devise!
|
7
7
|
Devise.configure_warden!
|
8
|
-
ActionController::Base.send :include, Devise::Controllers::Helpers
|
9
8
|
end
|
10
9
|
alias_method_chain :finalize!, :devise
|
11
10
|
end
|
@@ -70,6 +69,13 @@ module ActionDispatch::Routing
|
|
70
69
|
#
|
71
70
|
# devise_for :users, :controllers => { :sessions => "users/sessions" }
|
72
71
|
#
|
72
|
+
# * :sign_out_via => the HTTP method(s) accepted for the :sign_out action (default: :get),
|
73
|
+
# if you wish to restrict this to accept only :post or :delete requests you should do:
|
74
|
+
#
|
75
|
+
# devise_for :users, :sign_out_via => [ :post, :delete ]
|
76
|
+
#
|
77
|
+
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
78
|
+
#
|
73
79
|
# * :module => the namespace to find controlers. By default, devise will access devise/sessions,
|
74
80
|
# devise/registrations and so on. If you want to namespace all at once, use module:
|
75
81
|
#
|
@@ -85,6 +91,10 @@ module ActionDispatch::Routing
|
|
85
91
|
# Will use publisher/sessions controller instead of devise/sessions controller. You can revert
|
86
92
|
# this by providing the :module option to devise_for.
|
87
93
|
#
|
94
|
+
# Also pay attention that when you use a namespace it will affect all the helpers and methods for controllers
|
95
|
+
# and views. For example, using the above setup you'll end with following methods:
|
96
|
+
# current_publisher_account, authenticate_publisher_account!, pusblisher_account_signed_in, etc.
|
97
|
+
#
|
88
98
|
# * :skip => tell which controller you want to skip routes from being created:
|
89
99
|
#
|
90
100
|
# devise_for :users, :skip => :sessions
|
@@ -113,19 +123,33 @@ module ActionDispatch::Routing
|
|
113
123
|
# end
|
114
124
|
# end
|
115
125
|
#
|
126
|
+
# ==== Adding custom actions to override controllers
|
127
|
+
#
|
128
|
+
# You can pass a block to devise_for that will add any routes defined in the block to Devise's
|
129
|
+
# list of known actions. This is important if you add a custom action to a controller that
|
130
|
+
# overrides an out of the box Devise controller.
|
131
|
+
# For example:
|
132
|
+
#
|
133
|
+
# class RegistrationsController < Devise::RegistrationsController
|
134
|
+
# def update
|
135
|
+
# # do something different here
|
136
|
+
# end
|
137
|
+
#
|
138
|
+
# def deactivate
|
139
|
+
# # not a standard action
|
140
|
+
# # deactivate code here
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
#
|
144
|
+
# In order to get Devise to recognize the deactivate action, your devise_for entry should look like this,
|
145
|
+
#
|
146
|
+
# devise_for :owners, :controllers => { :registrations => "registrations" } do
|
147
|
+
# post "deactivate", :to => "registrations#deactivate", :as => "deactivate_registration"
|
148
|
+
# end
|
149
|
+
#
|
116
150
|
def devise_for(*resources)
|
117
151
|
options = resources.extract_options!
|
118
152
|
|
119
|
-
if as = options.delete(:as)
|
120
|
-
ActiveSupport::Deprecation.warn ":as is deprecated, please use :path instead."
|
121
|
-
options[:path] ||= as
|
122
|
-
end
|
123
|
-
|
124
|
-
if scope = options.delete(:scope)
|
125
|
-
ActiveSupport::Deprecation.warn ":scope is deprecated, please use :singular instead."
|
126
|
-
options[:singular] ||= scope
|
127
|
-
end
|
128
|
-
|
129
153
|
options[:as] ||= @scope[:as] if @scope[:as].present?
|
130
154
|
options[:module] ||= @scope[:module] if @scope[:module].present?
|
131
155
|
options[:path_prefix] ||= @scope[:path] if @scope[:path].present?
|
@@ -154,7 +178,7 @@ module ActionDispatch::Routing
|
|
154
178
|
devise_scope mapping.name do
|
155
179
|
yield if block_given?
|
156
180
|
with_devise_exclusive_scope mapping.fullpath, mapping.name do
|
157
|
-
routes.each { |mod| send(
|
181
|
+
routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) }
|
158
182
|
end
|
159
183
|
end
|
160
184
|
end
|
@@ -203,22 +227,22 @@ module ActionDispatch::Routing
|
|
203
227
|
|
204
228
|
def devise_session(mapping, controllers) #:nodoc:
|
205
229
|
resource :session, :only => [], :controller => controllers[:sessions], :path => "" do
|
206
|
-
get
|
207
|
-
post
|
208
|
-
|
230
|
+
get :new, :path => mapping.path_names[:sign_in], :as => "new"
|
231
|
+
post :create, :path => mapping.path_names[:sign_in]
|
232
|
+
match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy", :via => mapping.sign_out_via
|
209
233
|
end
|
210
234
|
end
|
211
|
-
|
235
|
+
|
212
236
|
def devise_password(mapping, controllers) #:nodoc:
|
213
237
|
resource :password, :only => [:new, :create, :edit, :update],
|
214
238
|
:path => mapping.path_names[:password], :controller => controllers[:passwords]
|
215
239
|
end
|
216
|
-
|
240
|
+
|
217
241
|
def devise_confirmation(mapping, controllers) #:nodoc:
|
218
242
|
resource :confirmation, :only => [:new, :create, :show],
|
219
243
|
:path => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
|
220
244
|
end
|
221
|
-
|
245
|
+
|
222
246
|
def devise_unlock(mapping, controllers) #:nodoc:
|
223
247
|
if mapping.to.unlock_strategy_enabled?(:email)
|
224
248
|
resource :unlock, :only => [:new, :create, :show],
|
@@ -227,8 +251,28 @@ module ActionDispatch::Routing
|
|
227
251
|
end
|
228
252
|
|
229
253
|
def devise_registration(mapping, controllers) #:nodoc:
|
230
|
-
|
231
|
-
|
254
|
+
path_names = {
|
255
|
+
:new => mapping.path_names[:sign_up],
|
256
|
+
:cancel => mapping.path_names[:cancel]
|
257
|
+
}
|
258
|
+
|
259
|
+
resource :registration, :except => :show, :path => mapping.path_names[:registration],
|
260
|
+
:path_names => path_names, :controller => controllers[:registrations] do
|
261
|
+
get :cancel
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def devise_omniauth_callback(mapping, controllers) #:nodoc:
|
266
|
+
path_prefix = "/#{mapping.path}/auth"
|
267
|
+
|
268
|
+
if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix
|
269
|
+
warn "[DEVISE] You can only add :omniauthable behavior to one model."
|
270
|
+
else
|
271
|
+
::OmniAuth.config.path_prefix = path_prefix
|
272
|
+
end
|
273
|
+
|
274
|
+
match "/auth/:action/callback", :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)),
|
275
|
+
:to => controllers[:omniauth_callbacks], :as => :omniauth_callback
|
232
276
|
end
|
233
277
|
|
234
278
|
def with_devise_exclusive_scope(new_path, new_as) #:nodoc:
|
@@ -3,9 +3,9 @@ module Warden::Mixins::Common
|
|
3
3
|
@request ||= ActionDispatch::Request.new(env)
|
4
4
|
end
|
5
5
|
|
6
|
+
# This is called internally by Warden on logout
|
6
7
|
def reset_session!
|
7
|
-
|
8
|
-
raw_session.clear
|
8
|
+
request.reset_session
|
9
9
|
end
|
10
10
|
|
11
11
|
def cookies
|
@@ -15,25 +15,28 @@ end
|
|
15
15
|
|
16
16
|
class Warden::SessionSerializer
|
17
17
|
def serialize(record)
|
18
|
-
[record.class.name, record.
|
18
|
+
[record.class.name, record.to_key, record.authenticatable_salt]
|
19
19
|
end
|
20
20
|
|
21
21
|
def deserialize(keys)
|
22
|
-
|
23
|
-
|
24
|
-
if klass.is_a?(Class)
|
22
|
+
if keys.size == 2
|
25
23
|
raise "Devise changed how it stores objects in session. If you are seeing this message, " <<
|
26
|
-
"you can fix it by changing one character in your cookie secret
|
27
|
-
"
|
24
|
+
"you can fix it by changing one character in your cookie secret or cleaning up your " <<
|
25
|
+
"database sessions if you are using a db store."
|
28
26
|
end
|
29
27
|
|
30
|
-
klass
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
klass, id, salt = keys
|
29
|
+
|
30
|
+
begin
|
31
|
+
record = klass.constantize.to_adapter.get(id)
|
32
|
+
record if record && record.authenticatable_salt == salt
|
33
|
+
rescue NameError => e
|
34
|
+
if e.message =~ /uninitialized constant/
|
35
|
+
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"
|
36
|
+
nil
|
37
|
+
else
|
38
|
+
raise
|
39
|
+
end
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
@@ -44,10 +47,6 @@ unless Devise.rack_session?
|
|
44
47
|
alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
|
45
48
|
alias_method :regular_update, :update unless method_defined?(:regular_update)
|
46
49
|
|
47
|
-
def [](key)
|
48
|
-
super(convert_key(key))
|
49
|
-
end
|
50
|
-
|
51
50
|
def []=(key, value)
|
52
51
|
regular_writer(convert_key(key), value)
|
53
52
|
end
|
@@ -92,7 +91,6 @@ unless Devise.rack_session?
|
|
92
91
|
def symbolize_keys; to_hash.symbolize_keys end
|
93
92
|
|
94
93
|
def to_options!; self end
|
95
|
-
def to_hash; Hash.new.update(self) end
|
96
94
|
|
97
95
|
protected
|
98
96
|
|
data/lib/devise/schema.rb
CHANGED
@@ -3,11 +3,6 @@ module Devise
|
|
3
3
|
# and overwrite the apply_schema method.
|
4
4
|
module Schema
|
5
5
|
|
6
|
-
def authenticatable(*args)
|
7
|
-
ActiveSupport::Deprecation.warn "t.authenticatable in migrations is deprecated. Please use t.database_authenticatable instead.", caller
|
8
|
-
database_authenticatable(*args)
|
9
|
-
end
|
10
|
-
|
11
6
|
# Creates email, encrypted_password and password_salt.
|
12
7
|
#
|
13
8
|
# == Options
|
@@ -21,17 +16,17 @@ module Devise
|
|
21
16
|
null = options[:null] || false
|
22
17
|
default = options.key?(:default) ? options[:default] : ("" if null == false)
|
23
18
|
|
24
|
-
if options.delete(:encryptor)
|
25
|
-
ActiveSupport::Deprecation.warn ":encryptor as option is deprecated, simply remove it."
|
26
|
-
end
|
27
|
-
|
28
19
|
apply_devise_schema :email, String, :null => null, :default => default
|
29
20
|
apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
|
30
|
-
|
31
|
-
|
21
|
+
end
|
22
|
+
|
23
|
+
# Creates password salt for encryption support.
|
24
|
+
def encryptable
|
25
|
+
apply_devise_schema :password_salt, String
|
26
|
+
end
|
32
27
|
|
33
28
|
# Creates authentication_token.
|
34
|
-
def token_authenticatable
|
29
|
+
def token_authenticatable
|
35
30
|
apply_devise_schema :authentication_token, String
|
36
31
|
end
|
37
32
|
|
@@ -48,8 +43,12 @@ module Devise
|
|
48
43
|
end
|
49
44
|
|
50
45
|
# Creates remember_token and remember_created_at.
|
51
|
-
|
52
|
-
|
46
|
+
#
|
47
|
+
# == Options
|
48
|
+
# * :use_salt - When true, does not create a remember_token and use password_salt instead.
|
49
|
+
def rememberable(options={})
|
50
|
+
use_salt = options.fetch(:use_salt, Devise.use_salt_as_remember_token)
|
51
|
+
apply_devise_schema :remember_token, String unless use_salt
|
53
52
|
apply_devise_schema :remember_created_at, DateTime
|
54
53
|
end
|
55
54
|
|
@@ -9,7 +9,7 @@ module Devise
|
|
9
9
|
attr_accessor :authentication_hash, :password
|
10
10
|
|
11
11
|
def valid?
|
12
|
-
|
12
|
+
valid_for_params_auth? || valid_for_http_auth?
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -21,7 +21,6 @@ module Devise
|
|
21
21
|
case result
|
22
22
|
when Symbol, String
|
23
23
|
fail!(result)
|
24
|
-
false
|
25
24
|
else
|
26
25
|
result
|
27
26
|
end
|
@@ -97,15 +96,17 @@ module Devise
|
|
97
96
|
|
98
97
|
# Helper to decode credentials from HTTP.
|
99
98
|
def decode_credentials
|
100
|
-
return [] unless request.authorization && request.authorization =~ /^Basic (.*)/
|
99
|
+
return [] unless request.authorization && request.authorization =~ /^Basic (.*)/m
|
101
100
|
ActiveSupport::Base64.decode64($1).split(/:/, 2)
|
102
101
|
end
|
103
102
|
|
104
103
|
# Sets the authentication hash and the password from params_auth_hash or http_auth_hash.
|
105
|
-
def with_authentication_hash(
|
106
|
-
self.authentication_hash =
|
107
|
-
self.password =
|
108
|
-
|
104
|
+
def with_authentication_hash(auth_values)
|
105
|
+
self.authentication_hash = {}
|
106
|
+
self.password = auth_values[:password]
|
107
|
+
|
108
|
+
parse_authentication_key_values(auth_values, authentication_keys) &&
|
109
|
+
parse_authentication_key_values(request_values, request_keys)
|
109
110
|
end
|
110
111
|
|
111
112
|
# Holds the authentication keys.
|
@@ -113,6 +114,31 @@ module Devise
|
|
113
114
|
@authentication_keys ||= mapping.to.authentication_keys
|
114
115
|
end
|
115
116
|
|
117
|
+
# Holds request keys.
|
118
|
+
def request_keys
|
119
|
+
@request_keys ||= mapping.to.request_keys
|
120
|
+
end
|
121
|
+
|
122
|
+
# Returns values from the request object.
|
123
|
+
def request_values
|
124
|
+
keys = request_keys.respond_to?(:keys) ? request_keys.keys : request_keys
|
125
|
+
values = keys.map { |k| self.request.send(k) }
|
126
|
+
Hash[keys.zip(values)]
|
127
|
+
end
|
128
|
+
|
129
|
+
# Parse authentication keys considering if they should be enforced or not.
|
130
|
+
def parse_authentication_key_values(hash, keys)
|
131
|
+
keys.each do |key, enforce|
|
132
|
+
value = hash[key].presence
|
133
|
+
if value
|
134
|
+
self.authentication_hash[key] = value
|
135
|
+
else
|
136
|
+
return false unless enforce == false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
true
|
140
|
+
end
|
141
|
+
|
116
142
|
# Holds the authenticatable name for this class. Devise::Strategies::DatabaseAuthenticatable
|
117
143
|
# becomes simply :database.
|
118
144
|
def authenticatable_name
|