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
data/lib/devise/rails.rb
CHANGED
|
@@ -41,5 +41,66 @@ module Devise
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
|
+
|
|
45
|
+
initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
|
|
46
|
+
# We can get rid of this once we support Rails > 3.2
|
|
47
|
+
ActionDispatch::Routing::RoutesProxy.class_eval do
|
|
48
|
+
def respond_to?(method, include_private = false)
|
|
49
|
+
super || routes.url_helpers.respond_to?(method)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
initializer "devise.deprecations" do
|
|
55
|
+
unless defined?(Rails::Generators)
|
|
56
|
+
if Devise.case_insensitive_keys == false
|
|
57
|
+
warn "\n[DEVISE] Devise.case_insensitive_keys is false which is no longer " \
|
|
58
|
+
"supported. If you want to continue running on this mode, please ensure " \
|
|
59
|
+
"you are not using validatable (you can copy the validations directly to your model) " \
|
|
60
|
+
"and set case_insensitive_keys to an empty array.\n"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if Devise.apply_schema && defined?(Mongoid)
|
|
64
|
+
warn "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \
|
|
65
|
+
"automatically configuring your DB. This no longer happens. You should " \
|
|
66
|
+
"set Devise.apply_schema to false and manually set the fields used by Devise as shown here: " \
|
|
67
|
+
"https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# TODO: Deprecate the true value of this option as well
|
|
71
|
+
if Devise.use_salt_as_remember_token == false
|
|
72
|
+
warn "\n[DEVISE] Devise.use_salt_as_remember_token is false which is no longer " \
|
|
73
|
+
"supported. Devise now only uses the salt as remember token and the remember_token " \
|
|
74
|
+
"column can be removed from your models.\n"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
if Devise.reset_password_within.nil?
|
|
78
|
+
warn "\n[DEVISE] Devise.reset_password_within is nil. Please set this value to " \
|
|
79
|
+
"an interval (for example, 6.hours) and add a reset_password_sent_at field to " \
|
|
80
|
+
"your Devise models (if they don't have one already).\n"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
config.after_initialize do
|
|
85
|
+
example = <<-YAML
|
|
86
|
+
en:
|
|
87
|
+
devise:
|
|
88
|
+
registrations:
|
|
89
|
+
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.'
|
|
90
|
+
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
|
91
|
+
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
|
92
|
+
YAML
|
|
93
|
+
|
|
94
|
+
if I18n.t(:"devise.registrations.reasons", :default => {}).present?
|
|
95
|
+
warn "\n[DEVISE] devise.registrations.reasons in yml files is deprecated, " \
|
|
96
|
+
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
if I18n.t(:"devise.registrations.inactive_signed_up", :default => "").present?
|
|
100
|
+
warn "\n[DEVISE] devise.registrations.inactive_signed_up in yml files is deprecated, " \
|
|
101
|
+
"please use devise.registrations.signed_up_but_REASON instead. The default values are:\n\n#{example}\n"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
44
105
|
end
|
|
45
106
|
end
|
data/lib/devise/schema.rb
CHANGED
|
@@ -40,6 +40,11 @@ module Devise
|
|
|
40
40
|
apply_devise_schema :confirmation_sent_at, DateTime
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
# Creates unconfirmed_email
|
|
44
|
+
def reconfirmable
|
|
45
|
+
apply_devise_schema :unconfirmed_email, String
|
|
46
|
+
end
|
|
47
|
+
|
|
43
48
|
# Creates reset_password_token and reset_password_sent_at.
|
|
44
49
|
#
|
|
45
50
|
# == Options
|
|
@@ -6,7 +6,11 @@ module Devise
|
|
|
6
6
|
# parameters both from params or from http authorization headers. See database_authenticatable
|
|
7
7
|
# for an example.
|
|
8
8
|
class Authenticatable < Base
|
|
9
|
-
attr_accessor :authentication_hash, :password
|
|
9
|
+
attr_accessor :authentication_hash, :authentication_type, :password
|
|
10
|
+
|
|
11
|
+
def store?
|
|
12
|
+
!mapping.to.skip_session_storage.include?(authentication_type)
|
|
13
|
+
end
|
|
10
14
|
|
|
11
15
|
def valid?
|
|
12
16
|
valid_for_params_auth? || valid_for_http_auth?
|
|
@@ -47,7 +51,7 @@ module Devise
|
|
|
47
51
|
# * If all authentication keys are present;
|
|
48
52
|
#
|
|
49
53
|
def valid_for_http_auth?
|
|
50
|
-
http_authenticatable? && request.authorization && with_authentication_hash(http_auth_hash)
|
|
54
|
+
http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)
|
|
51
55
|
end
|
|
52
56
|
|
|
53
57
|
# Check if this is strategy is valid for params authentication by:
|
|
@@ -58,8 +62,8 @@ module Devise
|
|
|
58
62
|
# * If all authentication keys are present;
|
|
59
63
|
#
|
|
60
64
|
def valid_for_params_auth?
|
|
61
|
-
params_authenticatable? &&
|
|
62
|
-
valid_params? && with_authentication_hash(params_auth_hash)
|
|
65
|
+
params_authenticatable? && valid_params_request? &&
|
|
66
|
+
valid_params? && with_authentication_hash(:params_auth, params_auth_hash)
|
|
63
67
|
end
|
|
64
68
|
|
|
65
69
|
# Check if the model accepts this strategy as http authenticatable.
|
|
@@ -83,8 +87,8 @@ module Devise
|
|
|
83
87
|
Hash[*keys.zip(decode_credentials).flatten]
|
|
84
88
|
end
|
|
85
89
|
|
|
86
|
-
# By default, a request is valid
|
|
87
|
-
def
|
|
90
|
+
# By default, a request is valid if the controller set the proper env variable.
|
|
91
|
+
def valid_params_request?
|
|
88
92
|
!!env["devise.allow_params_authentication"]
|
|
89
93
|
end
|
|
90
94
|
|
|
@@ -101,12 +105,12 @@ module Devise
|
|
|
101
105
|
# Helper to decode credentials from HTTP.
|
|
102
106
|
def decode_credentials
|
|
103
107
|
return [] unless request.authorization && request.authorization =~ /^Basic (.*)/m
|
|
104
|
-
|
|
108
|
+
Base64.decode64($1).split(/:/, 2)
|
|
105
109
|
end
|
|
106
110
|
|
|
107
111
|
# Sets the authentication hash and the password from params_auth_hash or http_auth_hash.
|
|
108
|
-
def with_authentication_hash(auth_values)
|
|
109
|
-
self.authentication_hash = {}
|
|
112
|
+
def with_authentication_hash(auth_type, auth_values)
|
|
113
|
+
self.authentication_hash, self.authentication_type = {}, auth_type
|
|
110
114
|
self.password = auth_values[:password]
|
|
111
115
|
|
|
112
116
|
parse_authentication_key_values(auth_values, authentication_keys) &&
|
|
@@ -152,4 +156,4 @@ module Devise
|
|
|
152
156
|
end
|
|
153
157
|
end
|
|
154
158
|
end
|
|
155
|
-
end
|
|
159
|
+
end
|
|
@@ -11,7 +11,7 @@ module Devise
|
|
|
11
11
|
# a password, you can pass "X" as password and it will simply be ignored.
|
|
12
12
|
class TokenAuthenticatable < Authenticatable
|
|
13
13
|
def store?
|
|
14
|
-
!mapping.to.
|
|
14
|
+
super && !mapping.to.skip_session_storage.include?(:token_auth)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def authenticate!
|
|
@@ -27,8 +27,8 @@ module Devise
|
|
|
27
27
|
|
|
28
28
|
private
|
|
29
29
|
|
|
30
|
-
#
|
|
31
|
-
def
|
|
30
|
+
# Token Authenticatable can be authenticated with params in any controller and any verb.
|
|
31
|
+
def valid_params_request?
|
|
32
32
|
true
|
|
33
33
|
end
|
|
34
34
|
|
data/lib/devise/version.rb
CHANGED
data/lib/devise.rb
CHANGED
|
@@ -16,10 +16,8 @@ module Devise
|
|
|
16
16
|
|
|
17
17
|
module Controllers
|
|
18
18
|
autoload :Helpers, 'devise/controllers/helpers'
|
|
19
|
-
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
|
20
19
|
autoload :Rememberable, 'devise/controllers/rememberable'
|
|
21
20
|
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
|
22
|
-
autoload :SharedHelpers, 'devise/controllers/shared_helpers'
|
|
23
21
|
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
|
24
22
|
end
|
|
25
23
|
|
|
@@ -84,7 +82,7 @@ module Devise
|
|
|
84
82
|
# False by default for backwards compatibility.
|
|
85
83
|
mattr_accessor :case_insensitive_keys
|
|
86
84
|
@@case_insensitive_keys = false
|
|
87
|
-
|
|
85
|
+
|
|
88
86
|
# Keys that should have whitespace stripped.
|
|
89
87
|
# False by default for backwards compatibility.
|
|
90
88
|
mattr_accessor :strip_whitespace_keys
|
|
@@ -120,27 +118,23 @@ module Devise
|
|
|
120
118
|
mattr_accessor :remember_for
|
|
121
119
|
@@remember_for = 2.weeks
|
|
122
120
|
|
|
123
|
-
# If true, a valid remember token can be re-used between multiple browsers.
|
|
124
|
-
mattr_accessor :remember_across_browsers
|
|
125
|
-
@@remember_across_browsers = true
|
|
126
|
-
|
|
127
121
|
# If true, extends the user's remember period when remembered via cookie.
|
|
128
122
|
mattr_accessor :extend_remember_period
|
|
129
123
|
@@extend_remember_period = false
|
|
130
124
|
|
|
131
|
-
# If true, uses salt as remember token and does not create it in the database.
|
|
132
|
-
# By default is false for backwards compatibility.
|
|
133
|
-
mattr_accessor :use_salt_as_remember_token
|
|
134
|
-
@@use_salt_as_remember_token = false
|
|
135
|
-
|
|
136
125
|
# Time interval you can access your account before confirming your account.
|
|
137
|
-
mattr_accessor :
|
|
138
|
-
@@
|
|
126
|
+
mattr_accessor :allow_unconfirmed_access_for
|
|
127
|
+
@@allow_unconfirmed_access_for = 0.days
|
|
139
128
|
|
|
140
|
-
# Defines which key will be used when confirming an account
|
|
129
|
+
# Defines which key will be used when confirming an account.
|
|
141
130
|
mattr_accessor :confirmation_keys
|
|
142
131
|
@@confirmation_keys = [ :email ]
|
|
143
132
|
|
|
133
|
+
# Defines if email should be reconfirmable.
|
|
134
|
+
# False by default for backwards compatibility.
|
|
135
|
+
mattr_accessor :reconfirmable
|
|
136
|
+
@@reconfirmable = false
|
|
137
|
+
|
|
144
138
|
# Time interval to timeout the user session without activity.
|
|
145
139
|
mattr_accessor :timeout_in
|
|
146
140
|
@@timeout_in = 30.minutes
|
|
@@ -153,11 +147,6 @@ module Devise
|
|
|
153
147
|
mattr_accessor :encryptor
|
|
154
148
|
@@encryptor = nil
|
|
155
149
|
|
|
156
|
-
# Tells if devise should apply the schema in ORMs where devise declaration
|
|
157
|
-
# and schema belongs to the same class (as Datamapper and Mongoid).
|
|
158
|
-
mattr_accessor :apply_schema
|
|
159
|
-
@@apply_schema = true
|
|
160
|
-
|
|
161
150
|
# Scoped views. Since it relies on fallbacks to render default views, it's
|
|
162
151
|
# turned off by default.
|
|
163
152
|
mattr_accessor :scoped_views
|
|
@@ -190,6 +179,7 @@ module Devise
|
|
|
190
179
|
@@reset_password_keys = [ :email ]
|
|
191
180
|
|
|
192
181
|
# Time interval you can reset your password with a reset password key
|
|
182
|
+
# Nil by default for backwards compatibility.
|
|
193
183
|
mattr_accessor :reset_password_within
|
|
194
184
|
@@reset_password_within = nil
|
|
195
185
|
|
|
@@ -205,14 +195,13 @@ module Devise
|
|
|
205
195
|
mattr_accessor :token_authentication_key
|
|
206
196
|
@@token_authentication_key = :auth_token
|
|
207
197
|
|
|
208
|
-
#
|
|
209
|
-
mattr_accessor :
|
|
210
|
-
@@
|
|
198
|
+
# Skip session storage for the following strategies
|
|
199
|
+
mattr_accessor :skip_session_storage
|
|
200
|
+
@@skip_session_storage = []
|
|
211
201
|
|
|
212
202
|
# Which formats should be treated as navigational.
|
|
213
|
-
# We need both :"*/*" and "*/*" to work on different Rails versions.
|
|
214
203
|
mattr_accessor :navigational_formats
|
|
215
|
-
@@navigational_formats = [
|
|
204
|
+
@@navigational_formats = ["*/*", :html]
|
|
216
205
|
|
|
217
206
|
# When set to true, signing out a user signs out all other scopes.
|
|
218
207
|
mattr_accessor :sign_out_all_scopes
|
|
@@ -222,6 +211,45 @@ module Devise
|
|
|
222
211
|
mattr_accessor :sign_out_via
|
|
223
212
|
@@sign_out_via = :get
|
|
224
213
|
|
|
214
|
+
# The parent controller all Devise controllers inherits from.
|
|
215
|
+
# Defaults to ApplicationController. This should be set early
|
|
216
|
+
# in the initialization process and should be set to a string.
|
|
217
|
+
mattr_accessor :parent_controller
|
|
218
|
+
@@parent_controller = "ApplicationController"
|
|
219
|
+
|
|
220
|
+
# The router Devise should use to generate routes. Defaults
|
|
221
|
+
# to :main_app. Should be overriden by engines in order
|
|
222
|
+
# to provide custom routes.
|
|
223
|
+
mattr_accessor :router_name
|
|
224
|
+
@@router_name = :main_app
|
|
225
|
+
|
|
226
|
+
# DEPRECATED CONFIG
|
|
227
|
+
|
|
228
|
+
# If true, uses salt as remember token and does not create it in the database.
|
|
229
|
+
# By default is false for backwards compatibility.
|
|
230
|
+
mattr_accessor :use_salt_as_remember_token
|
|
231
|
+
@@use_salt_as_remember_token = false
|
|
232
|
+
|
|
233
|
+
# Tells if devise should apply the schema in ORMs where devise declaration
|
|
234
|
+
# and schema belongs to the same class (as Datamapper and Mongoid).
|
|
235
|
+
mattr_accessor :apply_schema
|
|
236
|
+
@@apply_schema = true
|
|
237
|
+
|
|
238
|
+
def self.remember_across_browsers=(value)
|
|
239
|
+
warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n"
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
def self.confirm_within=(value)
|
|
243
|
+
warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n"
|
|
244
|
+
Devise.allow_unconfirmed_access_for = value
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def self.stateless_token=(value)
|
|
248
|
+
warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \
|
|
249
|
+
"instead, for example: Devise.skip_session_storage << :token_auth\n"
|
|
250
|
+
Devise.skip_session_storage << :token_auth
|
|
251
|
+
end
|
|
252
|
+
|
|
225
253
|
# PRIVATE CONFIGURATION
|
|
226
254
|
|
|
227
255
|
# Store scopes mappings.
|
|
@@ -315,7 +343,7 @@ module Devise
|
|
|
315
343
|
#
|
|
316
344
|
def self.add_module(module_name, options = {})
|
|
317
345
|
ALL << module_name
|
|
318
|
-
options.assert_valid_keys(:strategy, :model, :controller, :route)
|
|
346
|
+
options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input)
|
|
319
347
|
|
|
320
348
|
if strategy = options[:strategy]
|
|
321
349
|
strategy = (strategy == true ? module_name : strategy)
|
|
@@ -327,7 +355,7 @@ module Devise
|
|
|
327
355
|
CONTROLLERS[module_name] = controller
|
|
328
356
|
end
|
|
329
357
|
|
|
330
|
-
NO_INPUT << strategy if
|
|
358
|
+
NO_INPUT << strategy if options[:no_input]
|
|
331
359
|
|
|
332
360
|
if route = options[:route]
|
|
333
361
|
case route
|
|
@@ -361,7 +389,7 @@ module Devise
|
|
|
361
389
|
# initialization.
|
|
362
390
|
#
|
|
363
391
|
# Devise.initialize do |config|
|
|
364
|
-
# config.
|
|
392
|
+
# config.allow_unconfirmed_access_for = 2.days
|
|
365
393
|
#
|
|
366
394
|
# config.warden do |manager|
|
|
367
395
|
# # Configure warden to use other strategies, like oauth.
|
|
@@ -394,11 +422,6 @@ module Devise
|
|
|
394
422
|
end
|
|
395
423
|
end
|
|
396
424
|
|
|
397
|
-
# Returns true if Rails version is bigger than 3.0.x
|
|
398
|
-
def self.rack_session?
|
|
399
|
-
Rails::VERSION::STRING[0,3] != "3.0"
|
|
400
|
-
end
|
|
401
|
-
|
|
402
425
|
# Regenerates url helpers considering Devise.mapping
|
|
403
426
|
def self.regenerate_helpers!
|
|
404
427
|
Devise::Controllers::UrlHelpers.remove_helpers!
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require 'rails/generators/active_record'
|
|
2
2
|
require 'generators/devise/orm_helpers'
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
module ActiveRecord
|
|
6
5
|
module Generators
|
|
7
6
|
class DeviseGenerator < ActiveRecord::Generators::Base
|
|
@@ -21,13 +20,52 @@ module ActiveRecord
|
|
|
21
20
|
def generate_model
|
|
22
21
|
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
|
23
22
|
end
|
|
24
|
-
|
|
23
|
+
|
|
25
24
|
def inject_devise_content
|
|
26
25
|
inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
|
|
27
26
|
# Setup accessible (or protected) attributes for your model
|
|
28
27
|
attr_accessible :email, :password, :password_confirmation, :remember_me
|
|
29
28
|
CONTENT
|
|
30
29
|
end
|
|
30
|
+
|
|
31
|
+
def migration_data
|
|
32
|
+
<<RUBY
|
|
33
|
+
## Database authenticatable
|
|
34
|
+
t.string :email, :null => false, :default => ""
|
|
35
|
+
t.string :encrypted_password, :null => false, :default => ""
|
|
36
|
+
|
|
37
|
+
## Recoverable
|
|
38
|
+
t.string :reset_password_token
|
|
39
|
+
t.datetime :reset_password_sent_at
|
|
40
|
+
|
|
41
|
+
## Rememberable
|
|
42
|
+
t.datetime :remember_created_at
|
|
43
|
+
|
|
44
|
+
## Trackable
|
|
45
|
+
t.integer :sign_in_count, :default => 0
|
|
46
|
+
t.datetime :current_sign_in_at
|
|
47
|
+
t.datetime :last_sign_in_at
|
|
48
|
+
t.string :current_sign_in_ip
|
|
49
|
+
t.string :last_sign_in_ip
|
|
50
|
+
|
|
51
|
+
## Encryptable
|
|
52
|
+
# t.string :password_salt
|
|
53
|
+
|
|
54
|
+
## Confirmable
|
|
55
|
+
# t.string :confirmation_token
|
|
56
|
+
# t.datetime :confirmed_at
|
|
57
|
+
# t.datetime :confirmation_sent_at
|
|
58
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
|
59
|
+
|
|
60
|
+
## Lockable
|
|
61
|
+
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
|
|
62
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
|
63
|
+
# t.datetime :locked_at
|
|
64
|
+
|
|
65
|
+
## Token authenticatable
|
|
66
|
+
# t.string :authentication_token
|
|
67
|
+
RUBY
|
|
68
|
+
end
|
|
31
69
|
end
|
|
32
70
|
end
|
|
33
71
|
end
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
|
-
<% if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1 -%>
|
|
3
2
|
def change
|
|
4
|
-
<% else -%>
|
|
5
|
-
def self.up
|
|
6
|
-
<% end -%>
|
|
7
3
|
create_table(:<%= table_name %>) do |t|
|
|
8
|
-
|
|
9
|
-
t.recoverable
|
|
10
|
-
t.rememberable
|
|
11
|
-
t.trackable
|
|
12
|
-
|
|
13
|
-
# t.encryptable
|
|
14
|
-
# t.confirmable
|
|
15
|
-
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
|
|
16
|
-
# t.token_authenticatable
|
|
4
|
+
<%= migration_data -%>
|
|
17
5
|
|
|
18
6
|
<% attributes.each do |attribute| -%>
|
|
19
7
|
t.<%= attribute.type %> :<%= attribute.name %>
|
|
@@ -28,10 +16,4 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
|
28
16
|
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
|
29
17
|
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
|
30
18
|
end
|
|
31
|
-
|
|
32
|
-
<% unless ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1 -%>
|
|
33
|
-
def self.down
|
|
34
|
-
drop_table :<%= table_name %>
|
|
35
|
-
end
|
|
36
|
-
<% end -%>
|
|
37
19
|
end
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
|
3
3
|
change_table(:<%= table_name %>) do |t|
|
|
4
|
-
|
|
5
|
-
t.recoverable
|
|
6
|
-
t.rememberable
|
|
7
|
-
t.trackable
|
|
8
|
-
|
|
9
|
-
# t.encryptable
|
|
10
|
-
# t.confirmable
|
|
11
|
-
# t.lockable :lock_strategy => :<%= Devise.lock_strategy %>, :unlock_strategy => :<%= Devise.unlock_strategy %>
|
|
12
|
-
# t.token_authenticatable
|
|
4
|
+
<%= migration_data -%>
|
|
13
5
|
|
|
14
6
|
<% attributes.each do |attribute| -%>
|
|
15
7
|
t.<%= attribute.type %> :<%= attribute.name %>
|
|
@@ -32,17 +32,6 @@ module Devise
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
|
|
36
|
-
include ViewPathTemplates
|
|
37
|
-
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
|
38
|
-
desc "Copies shared Devise views to your application."
|
|
39
|
-
|
|
40
|
-
# Override copy_views to just copy mailer and shared.
|
|
41
|
-
def copy_views
|
|
42
|
-
view_directory :shared
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
35
|
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
|
47
36
|
include ViewPathTemplates
|
|
48
37
|
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
|
@@ -80,12 +69,15 @@ module Devise
|
|
|
80
69
|
end
|
|
81
70
|
|
|
82
71
|
class ViewsGenerator < Rails::Generators::Base
|
|
72
|
+
include ViewPathTemplates
|
|
73
|
+
|
|
74
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
|
83
75
|
desc "Copies Devise views to your application."
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
def copy_views
|
|
78
|
+
copy_file "_links.erb", "#{target_path}/_links.erb"
|
|
79
|
+
end
|
|
87
80
|
|
|
88
|
-
invoke SharedViewsGenerator
|
|
89
81
|
hook_for :form_builder, :aliases => "-b",
|
|
90
82
|
:desc => "Form builder to be used",
|
|
91
83
|
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
|
@@ -9,9 +9,52 @@ module Mongoid
|
|
|
9
9
|
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def inject_field_types
|
|
13
|
+
inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists?
|
|
14
|
+
end
|
|
15
|
+
|
|
12
16
|
def inject_devise_content
|
|
13
17
|
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
|
|
14
18
|
end
|
|
19
|
+
|
|
20
|
+
def migration_data
|
|
21
|
+
<<RUBY
|
|
22
|
+
## Database authenticatable
|
|
23
|
+
field :email, :type => String, :null => false, :default => ""
|
|
24
|
+
field :encrypted_password, :type => String, :null => false, :default => ""
|
|
25
|
+
|
|
26
|
+
## Recoverable
|
|
27
|
+
field :reset_password_token, :type => String
|
|
28
|
+
field :reset_password_sent_at, :type => Time
|
|
29
|
+
|
|
30
|
+
## Rememberable
|
|
31
|
+
field :remember_created_at, :type => Time
|
|
32
|
+
|
|
33
|
+
## Trackable
|
|
34
|
+
field :sign_in_count, :type => Integer, :default => 0
|
|
35
|
+
field :current_sign_in_at, :type => Time
|
|
36
|
+
field :last_sign_in_at, :type => Time
|
|
37
|
+
field :current_sign_in_ip, :type => String
|
|
38
|
+
field :last_sign_in_ip, :type => String
|
|
39
|
+
|
|
40
|
+
## Encryptable
|
|
41
|
+
# field :password_salt, :type => String
|
|
42
|
+
|
|
43
|
+
## Confirmable
|
|
44
|
+
# field :confirmation_token, :type => String
|
|
45
|
+
# field :confirmed_at, :type => Time
|
|
46
|
+
# field :confirmation_sent_at, :type => Time
|
|
47
|
+
# field :unconfirmed_email, :type => String # Only if using reconfirmable
|
|
48
|
+
|
|
49
|
+
## Lockable
|
|
50
|
+
# field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
|
|
51
|
+
# field :unlock_token, :type => String # Only if unlock strategy is :email or :both
|
|
52
|
+
# field :locked_at, :type => Time
|
|
53
|
+
|
|
54
|
+
## Token authenticatable
|
|
55
|
+
# field :authentication_token, :type => String
|
|
56
|
+
RUBY
|
|
57
|
+
end
|
|
15
58
|
end
|
|
16
59
|
end
|
|
17
60
|
end
|
|
@@ -9,6 +9,9 @@ Devise.setup do |config|
|
|
|
9
9
|
# Configure the class responsible to send e-mails.
|
|
10
10
|
# config.mailer = "Devise::Mailer"
|
|
11
11
|
|
|
12
|
+
# Automatically apply schema changes in tableless databases
|
|
13
|
+
config.apply_schema = false
|
|
14
|
+
|
|
12
15
|
# ==> ORM configuration
|
|
13
16
|
# Load and configure the ORM. Supports :active_record (default) and
|
|
14
17
|
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
|
@@ -43,9 +46,15 @@ Devise.setup do |config|
|
|
|
43
46
|
config.strip_whitespace_keys = [ :email ]
|
|
44
47
|
|
|
45
48
|
# Tell if authentication through request.params is enabled. True by default.
|
|
49
|
+
# It can be set to an array that will enable params authentication only for the
|
|
50
|
+
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
|
51
|
+
# enable it only for database (email + password) authentication.
|
|
46
52
|
# config.params_authenticatable = true
|
|
47
53
|
|
|
48
54
|
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
|
55
|
+
# It can be set to an array that will enable http authentication only for the
|
|
56
|
+
# given strategies, for example, `config.http_authenticatable = [:token]` will
|
|
57
|
+
# enable it only for token authentication.
|
|
49
58
|
# config.http_authenticatable = false
|
|
50
59
|
|
|
51
60
|
# If http headers should be returned for AJAX requests. True by default.
|
|
@@ -59,6 +68,13 @@ Devise.setup do |config|
|
|
|
59
68
|
# Does not affect registerable.
|
|
60
69
|
# config.paranoid = true
|
|
61
70
|
|
|
71
|
+
# By default Devise will store the user in session. You can skip storage for
|
|
72
|
+
# :http_auth and :token_auth by adding those symbols to the array below.
|
|
73
|
+
# Notice that if you are skipping storage for all authentication paths, you
|
|
74
|
+
# may want to disable generating routes to Devise's sessions controller by
|
|
75
|
+
# passing :skip => :sessions to `devise_for` in your config/routes.rb
|
|
76
|
+
config.skip_session_storage = [:http_auth]
|
|
77
|
+
|
|
62
78
|
# ==> Configuration for :database_authenticatable
|
|
63
79
|
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
|
64
80
|
# using other encryptors, it sets how many times you want the password re-encrypted.
|
|
@@ -77,7 +93,13 @@ Devise.setup do |config|
|
|
|
77
93
|
# able to access the website for two days without confirming his account,
|
|
78
94
|
# access will be blocked just in the third day. Default is 0.days, meaning
|
|
79
95
|
# the user cannot access the website without confirming his account.
|
|
80
|
-
# config.
|
|
96
|
+
# config.allow_unconfirmed_access_for = 2.days
|
|
97
|
+
|
|
98
|
+
# If true, requires any email changes to be confirmed (exctly the same way as
|
|
99
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
|
100
|
+
# db field (see migrations). Until confirmed new email is stored in
|
|
101
|
+
# unconfirmed email column, and copied to email column on successful confirmation.
|
|
102
|
+
config.reconfirmable = true
|
|
81
103
|
|
|
82
104
|
# Defines which key will be used when confirming an account
|
|
83
105
|
# config.confirmation_keys = [ :email ]
|
|
@@ -86,9 +108,6 @@ Devise.setup do |config|
|
|
|
86
108
|
# The time the user will be remembered without asking for credentials again.
|
|
87
109
|
# config.remember_for = 2.weeks
|
|
88
110
|
|
|
89
|
-
# If true, a valid remember token can be re-used between multiple browsers.
|
|
90
|
-
# config.remember_across_browsers = true
|
|
91
|
-
|
|
92
111
|
# If true, extends the user's remember period when remembered via cookie.
|
|
93
112
|
# config.extend_remember_period = false
|
|
94
113
|
|
|
@@ -145,7 +164,7 @@ Devise.setup do |config|
|
|
|
145
164
|
# Time interval you can reset your password with a reset password key.
|
|
146
165
|
# Don't put a too small interval or your users won't have the time to
|
|
147
166
|
# change their passwords.
|
|
148
|
-
config.reset_password_within =
|
|
167
|
+
config.reset_password_within = 6.hours
|
|
149
168
|
|
|
150
169
|
# ==> Configuration for :encryptable
|
|
151
170
|
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
|
@@ -159,10 +178,6 @@ Devise.setup do |config|
|
|
|
159
178
|
# Defines name of the authentication token params key
|
|
160
179
|
# config.token_authentication_key = :auth_token
|
|
161
180
|
|
|
162
|
-
# If true, authentication through token does not store user in session and needs
|
|
163
|
-
# to be supplied on each request. Useful if you are using the token as API token.
|
|
164
|
-
# config.stateless_token = false
|
|
165
|
-
|
|
166
181
|
# ==> Scopes configuration
|
|
167
182
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
|
168
183
|
# "users/sessions/new". It's turned off by default because it's slower if you
|
|
@@ -186,9 +201,8 @@ Devise.setup do |config|
|
|
|
186
201
|
# If you have any extra navigational formats, like :iphone or :mobile, you
|
|
187
202
|
# should add them to the navigational formats lists.
|
|
188
203
|
#
|
|
189
|
-
# The
|
|
190
|
-
#
|
|
191
|
-
# config.navigational_formats = [:"*/*", "*/*", :html]
|
|
204
|
+
# The "*/*" below is required to match Internet Explorer requests.
|
|
205
|
+
# config.navigational_formats = ["*/*", :html]
|
|
192
206
|
|
|
193
207
|
# The default HTTP method used to sign out a resource. Default is :delete.
|
|
194
208
|
config.sign_out_via = :delete
|