devise 1.4.2 → 1.4.3
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/.gitignore +3 -1
- data/.travis.yml +3 -2
- data/CHANGELOG.rdoc +16 -1
- data/Gemfile +4 -2
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/app/controllers/devise/confirmations_controller.rb +7 -1
- data/app/controllers/devise/registrations_controller.rb +8 -2
- data/app/controllers/devise/sessions_controller.rb +6 -4
- data/app/views/devise/confirmations/new.html.erb +3 -3
- data/app/views/devise/passwords/edit.html.erb +5 -5
- data/app/views/devise/passwords/new.html.erb +3 -3
- data/app/views/devise/registrations/edit.html.erb +9 -9
- data/app/views/devise/registrations/new.html.erb +7 -7
- data/app/views/devise/sessions/new.html.erb +6 -6
- data/app/views/devise/unlocks/new.html.erb +3 -3
- data/config/locales/en.yml +4 -0
- data/devise.gemspec +1 -1
- data/lib/devise.rb +11 -6
- data/lib/devise/controllers/helpers.rb +1 -0
- data/lib/devise/controllers/url_helpers.rb +20 -11
- data/lib/devise/hooks/timeoutable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +9 -2
- data/lib/devise/mapping.rb +8 -1
- data/lib/devise/models/authenticatable.rb +9 -0
- data/lib/devise/models/confirmable.rb +8 -3
- data/lib/devise/models/database_authenticatable.rb +3 -0
- data/lib/devise/models/lockable.rb +5 -5
- data/lib/devise/models/recoverable.rb +10 -3
- data/lib/devise/models/trackable.rb +1 -1
- data/lib/devise/models/validatable.rb +1 -1
- data/lib/devise/rails.rb +13 -0
- data/lib/devise/rails/routes.rb +22 -10
- data/lib/devise/rails/warden_compat.rb +5 -10
- data/lib/devise/schema.rb +5 -3
- data/lib/devise/strategies/token_authenticatable.rb +5 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/active_record/devise_generator.rb +10 -5
- data/lib/generators/active_record/templates/migration_existing.rb +34 -0
- data/lib/generators/devise/orm_helpers.rb +8 -0
- data/lib/generators/templates/devise.rb +12 -5
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +1 -1
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +3 -3
- data/test/controllers/helpers_test.rb +1 -1
- data/test/generators/active_record_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +4 -3
- data/test/helpers/devise_helper_test.rb +10 -2
- data/test/integration/authenticatable_test.rb +17 -0
- data/test/integration/confirmable_test.rb +10 -1
- data/test/integration/lockable_test.rb +1 -1
- data/test/integration/recoverable_test.rb +12 -3
- data/test/integration/registerable_test.rb +10 -2
- data/test/integration/token_authenticatable_test.rb +11 -0
- data/test/mailers/confirmation_instructions_test.rb +6 -0
- data/test/mailers/reset_password_instructions_test.rb +6 -0
- data/test/mailers/unlock_instructions_test.rb +6 -0
- data/test/models/confirmable_test.rb +2 -2
- data/test/models/encryptable_test.rb +4 -2
- data/test/models/validatable_test.rb +3 -2
- data/test/models_test.rb +9 -11
- data/test/orm/mongoid.rb +3 -0
- data/test/rails_app/app/active_record/user.rb +0 -2
- data/test/rails_app/app/mailers/users/mailer.rb +3 -0
- data/test/rails_app/app/mongoid/shim.rb +0 -5
- data/test/rails_app/config/application.rb +1 -0
- data/test/rails_app/config/initializers/devise.rb +3 -2
- data/test/rails_app/config/routes.rb +1 -1
- data/test/rails_app/lib/shared_user.rb +1 -0
- metadata +12 -12
- data/Gemfile.lock +0 -158
- data/lib/devise/email.rb +0 -23
data/lib/devise/mapping.rb
CHANGED
@@ -22,7 +22,8 @@ module Devise
|
|
22
22
|
# # is the modules included in the class
|
23
23
|
#
|
24
24
|
class Mapping #:nodoc:
|
25
|
-
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
|
25
|
+
attr_reader :singular, :scoped_path, :path, :controllers, :path_names,
|
26
|
+
:class_name, :sign_out_via, :format, :used_routes
|
26
27
|
alias :name :singular
|
27
28
|
|
28
29
|
# Receives an object and find a scope for it. If a scope cannot be found,
|
@@ -72,6 +73,12 @@ module Devise
|
|
72
73
|
|
73
74
|
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
|
74
75
|
@format = options[:format]
|
76
|
+
|
77
|
+
@used_routes = self.routes
|
78
|
+
if options.has_key?(:only)
|
79
|
+
@used_routes = Array(options.delete(:only)).map { |s| s.to_s.singularize.to_sym } & @used_routes
|
80
|
+
end
|
81
|
+
@used_routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym }
|
75
82
|
end
|
76
83
|
|
77
84
|
# Return modules for the mapping.
|
@@ -82,6 +82,15 @@ module Devise
|
|
82
82
|
module ClassMethods
|
83
83
|
Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
|
84
84
|
|
85
|
+
def serialize_into_session(record)
|
86
|
+
[record.to_key, record.authenticatable_salt]
|
87
|
+
end
|
88
|
+
|
89
|
+
def serialize_from_session(key, salt)
|
90
|
+
record = to_adapter.get(key)
|
91
|
+
record if record && record.authenticatable_salt == salt
|
92
|
+
end
|
93
|
+
|
85
94
|
def params_authenticatable?(strategy)
|
86
95
|
params_authenticatable.is_a?(Array) ?
|
87
96
|
params_authenticatable.include?(strategy) : params_authenticatable
|
@@ -29,7 +29,7 @@ module Devise
|
|
29
29
|
after_create :send_confirmation_instructions, :if => :confirmation_required?
|
30
30
|
end
|
31
31
|
|
32
|
-
# Confirm a user by setting
|
32
|
+
# Confirm a user by setting its confirmed_at to actual time. If the user
|
33
33
|
# is already confirmed, add en error to email field
|
34
34
|
def confirm!
|
35
35
|
unless_confirmed do
|
@@ -127,8 +127,13 @@ module Devise
|
|
127
127
|
generate_confirmation_token && save(:validate => false)
|
128
128
|
end
|
129
129
|
|
130
|
+
def after_password_reset
|
131
|
+
super
|
132
|
+
confirm! unless confirmed?
|
133
|
+
end
|
134
|
+
|
130
135
|
module ClassMethods
|
131
|
-
# Attempt to find a user by
|
136
|
+
# Attempt to find a user by its email. If a record is found, send new
|
132
137
|
# confirmation instructions to it. If not user is found, returns a new user
|
133
138
|
# with an email not found error.
|
134
139
|
# Options must contain the user email
|
@@ -138,7 +143,7 @@ module Devise
|
|
138
143
|
confirmable
|
139
144
|
end
|
140
145
|
|
141
|
-
# Find a user by
|
146
|
+
# Find a user by its confirmation token and try to confirm it.
|
142
147
|
# If no user is found, returns a new user with an error.
|
143
148
|
# If the user is already confirmed, create an error for the user
|
144
149
|
# Options must have the confirmation_token
|
@@ -10,6 +10,9 @@ module Devise
|
|
10
10
|
#
|
11
11
|
# DatabaseAuthenticable adds the following options to devise_for:
|
12
12
|
#
|
13
|
+
# * +pepper+: a random string used to provide a more secure hash. Use
|
14
|
+
# `rake secret` to generate new keys.
|
15
|
+
#
|
13
16
|
# * +stretches+: the cost given to bcrypt.
|
14
17
|
#
|
15
18
|
# == Examples
|
@@ -3,13 +3,13 @@ module Devise
|
|
3
3
|
# Handles blocking a user access after a certain number of attempts.
|
4
4
|
# Lockable accepts two different strategies to unlock a user after it's
|
5
5
|
# blocked: email and time. The former will send an email to the user when
|
6
|
-
# the lock happens, containing a link to unlock
|
6
|
+
# the lock happens, containing a link to unlock its account. The second
|
7
7
|
# will unlock the user automatically after some configured time (ie 2.hours).
|
8
8
|
# It's also possible to setup lockable to use both email and time strategies.
|
9
9
|
#
|
10
10
|
# == Options
|
11
11
|
#
|
12
|
-
# Lockable adds the following options to
|
12
|
+
# Lockable adds the following options to +devise+:
|
13
13
|
#
|
14
14
|
# * +maximum_attempts+: how many attempts should be accepted before blocking the user.
|
15
15
|
# * +lock_strategy+: lock the user account by :failed_attempts or :none.
|
@@ -22,7 +22,7 @@ module Devise
|
|
22
22
|
|
23
23
|
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
|
24
24
|
|
25
|
-
# Lock a user setting
|
25
|
+
# Lock a user setting its locked_at to actual time.
|
26
26
|
def lock_access!
|
27
27
|
self.locked_at = Time.now
|
28
28
|
|
@@ -132,7 +132,7 @@ module Devise
|
|
132
132
|
end
|
133
133
|
|
134
134
|
module ClassMethods
|
135
|
-
# Attempt to find a user by
|
135
|
+
# Attempt to find a user by its email. If a record is found, send new
|
136
136
|
# unlock instructions to it. If not user is found, returns a new user
|
137
137
|
# with an email not found error.
|
138
138
|
# Options must contain the user email
|
@@ -142,7 +142,7 @@ module Devise
|
|
142
142
|
lockable
|
143
143
|
end
|
144
144
|
|
145
|
-
# Find a user by
|
145
|
+
# Find a user by its unlock token and try to unlock it.
|
146
146
|
# If no user is found, returns a new user with an error.
|
147
147
|
# If the user is not locked, creates an error for the user
|
148
148
|
# Options must have the unlock_token
|
@@ -29,7 +29,11 @@ module Devise
|
|
29
29
|
def reset_password!(new_password, new_password_confirmation)
|
30
30
|
self.password = new_password
|
31
31
|
self.password_confirmation = new_password_confirmation
|
32
|
-
|
32
|
+
if valid?
|
33
|
+
clear_reset_password_token
|
34
|
+
after_password_reset
|
35
|
+
end
|
36
|
+
|
33
37
|
save
|
34
38
|
end
|
35
39
|
|
@@ -89,8 +93,11 @@ module Devise
|
|
89
93
|
self.reset_password_sent_at = nil if respond_to?(:reset_password_sent_at=)
|
90
94
|
end
|
91
95
|
|
96
|
+
def after_password_reset
|
97
|
+
end
|
98
|
+
|
92
99
|
module ClassMethods
|
93
|
-
# Attempt to find a user by
|
100
|
+
# Attempt to find a user by its email. If a record is found, send new
|
94
101
|
# password instructions to it. If not user is found, returns a new user
|
95
102
|
# with an email not found error.
|
96
103
|
# Attributes must contain the user email
|
@@ -105,7 +112,7 @@ module Devise
|
|
105
112
|
generate_token(:reset_password_token)
|
106
113
|
end
|
107
114
|
|
108
|
-
# Attempt to find a user by
|
115
|
+
# Attempt to find a user by its reset_password_token to reset its
|
109
116
|
# password. If a user is found and token is still valid, reset its password and automatically
|
110
117
|
# try saving the record. If not user is found, returns a new user
|
111
118
|
# containing an error in reset_password_token attribute.
|
@@ -8,7 +8,7 @@ module Devise
|
|
8
8
|
# * current_sign_in_at - A tiemstamp updated when the user signs in
|
9
9
|
# * last_sign_in_at - Holds the timestamp of the previous sign in
|
10
10
|
# * current_sign_in_ip - The remote ip updated when the user sign in
|
11
|
-
# *
|
11
|
+
# * last_sign_in_ip - Holds the remote ip of the previous sign in
|
12
12
|
#
|
13
13
|
module Trackable
|
14
14
|
def update_tracked_fields!(request)
|
@@ -2,7 +2,7 @@ module Devise
|
|
2
2
|
module Models
|
3
3
|
# Validatable creates all needed validations for a user email and password.
|
4
4
|
# It's optional, given you may want to create the validations by yourself.
|
5
|
-
# Automatically validate if the email is present, unique and
|
5
|
+
# Automatically validate if the email is present, unique and its format is
|
6
6
|
# valid. Also tests presence of password, confirmation and length.
|
7
7
|
#
|
8
8
|
# == Options
|
data/lib/devise/rails.rb
CHANGED
@@ -39,5 +39,18 @@ module Devise
|
|
39
39
|
Devise.include_helpers(Devise::OmniAuth)
|
40
40
|
end
|
41
41
|
end
|
42
|
+
|
43
|
+
initializer "devise.mongoid_version_warning" do
|
44
|
+
if defined?(Mongoid)
|
45
|
+
require 'mongoid/version'
|
46
|
+
if Mongoid::VERSION.to_f < 2.1
|
47
|
+
puts "\n[DEVISE] Please note that Mongoid versions prior to 2.1 handle dirty model " \
|
48
|
+
"object attributes in such a way that the Devise `validatable` module will not apply " \
|
49
|
+
"its usual uniqueness and format validations for the email field. It is recommended " \
|
50
|
+
"that you upgrade to Mongoid 2.1+ for this and other fixes, but if for some reason you " \
|
51
|
+
"are unable to do so, you should add these validations manually.\n"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
42
55
|
end
|
43
56
|
end
|
data/lib/devise/rails/routes.rb
CHANGED
@@ -5,6 +5,7 @@ module ActionDispatch::Routing
|
|
5
5
|
def finalize_with_devise!
|
6
6
|
finalize_without_devise!
|
7
7
|
Devise.configure_warden!
|
8
|
+
Devise.regenerate_helpers!
|
8
9
|
end
|
9
10
|
alias_method_chain :finalize!, :devise
|
10
11
|
end
|
@@ -93,7 +94,7 @@ module ActionDispatch::Routing
|
|
93
94
|
#
|
94
95
|
# Also pay attention that when you use a namespace it will affect all the helpers and methods for controllers
|
95
96
|
# and views. For example, using the above setup you'll end with following methods:
|
96
|
-
# current_publisher_account, authenticate_publisher_account!,
|
97
|
+
# current_publisher_account, authenticate_publisher_account!, publisher_account_signed_in, etc.
|
97
98
|
#
|
98
99
|
# * :skip => tell which controller you want to skip routes from being created:
|
99
100
|
#
|
@@ -188,11 +189,7 @@ module ActionDispatch::Routing
|
|
188
189
|
raise_no_devise_method_error!(mapping.class_name)
|
189
190
|
end
|
190
191
|
|
191
|
-
routes = mapping.
|
192
|
-
if options.has_key?(:only)
|
193
|
-
routes = Array(options.delete(:only)).map { |s| s.to_s.singularize.to_sym } & mapping.routes
|
194
|
-
end
|
195
|
-
routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym }
|
192
|
+
routes = mapping.used_routes
|
196
193
|
|
197
194
|
devise_scope mapping.name do
|
198
195
|
yield if block_given?
|
@@ -205,11 +202,15 @@ module ActionDispatch::Routing
|
|
205
202
|
|
206
203
|
# Allow you to add authentication request from the router:
|
207
204
|
#
|
208
|
-
# authenticate
|
205
|
+
# authenticate do
|
209
206
|
# resources :post
|
210
207
|
# end
|
211
208
|
#
|
212
|
-
|
209
|
+
# authenticate(:admin) do
|
210
|
+
# resources :users
|
211
|
+
# end
|
212
|
+
#
|
213
|
+
def authenticate(scope=nil)
|
213
214
|
constraint = lambda do |request|
|
214
215
|
request.env["warden"].authenticate!(:scope => scope)
|
215
216
|
end
|
@@ -274,6 +275,17 @@ module ActionDispatch::Routing
|
|
274
275
|
# Notice you cannot have two scopes mapping to the same URL. And remember, if
|
275
276
|
# you try to access a devise controller without specifying a scope, it will
|
276
277
|
# raise ActionNotFound error.
|
278
|
+
#
|
279
|
+
# Also be aware of that 'devise_scope' and 'as' use the singular form of the
|
280
|
+
# noun where other devise route commands expect the plural form. This would be a
|
281
|
+
# good and working example.
|
282
|
+
#
|
283
|
+
# devise_scope :user do
|
284
|
+
# match "/some/route" => "some_devise_controller"
|
285
|
+
# end
|
286
|
+
# devise_for :users
|
287
|
+
#
|
288
|
+
# Notice and be aware of the differences above between :user and :users
|
277
289
|
def devise_scope(scope)
|
278
290
|
constraint = lambda do |request|
|
279
291
|
request.env["devise.mapping"] = Devise.mappings[scope]
|
@@ -319,7 +331,7 @@ module ActionDispatch::Routing
|
|
319
331
|
:cancel => mapping.path_names[:cancel]
|
320
332
|
}
|
321
333
|
|
322
|
-
resource :registration, :
|
334
|
+
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration],
|
323
335
|
:path_names => path_names, :controller => controllers[:registrations] do
|
324
336
|
get :cancel
|
325
337
|
end
|
@@ -335,7 +347,7 @@ module ActionDispatch::Routing
|
|
335
347
|
::OmniAuth.config.path_prefix = path_prefix
|
336
348
|
end
|
337
349
|
|
338
|
-
match "#{path_prefix}/:action/callback", :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)),
|
350
|
+
match "#{path_prefix}/:action/callback", :constraints => { :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) },
|
339
351
|
:to => controllers[:omniauth_callbacks], :as => :omniauth_callback
|
340
352
|
ensure
|
341
353
|
@scope[:path] = path
|
@@ -15,21 +15,16 @@ end
|
|
15
15
|
|
16
16
|
class Warden::SessionSerializer
|
17
17
|
def serialize(record)
|
18
|
-
|
18
|
+
klass = record.class
|
19
|
+
array = klass.serialize_into_session(record)
|
20
|
+
array.unshift(klass.name)
|
19
21
|
end
|
20
22
|
|
21
23
|
def deserialize(keys)
|
22
|
-
|
23
|
-
raise "Devise changed how it stores objects in session. If you are seeing this message, " <<
|
24
|
-
"you can fix it by changing one character in your secret_token or cleaning up your " <<
|
25
|
-
"database sessions if you are using a db store."
|
26
|
-
end
|
27
|
-
|
28
|
-
klass, id, salt = keys
|
24
|
+
klass, *args = keys
|
29
25
|
|
30
26
|
begin
|
31
|
-
|
32
|
-
record if record && record.authenticatable_salt == salt
|
27
|
+
ActiveSupport::Inflector.constantize(klass).serialize_from_session(*args)
|
33
28
|
rescue NameError => e
|
34
29
|
if e.message =~ /uninitialized constant/
|
35
30
|
Rails.logger.debug "[Devise] Trying to deserialize invalid class #{klass}"
|
data/lib/devise/schema.rb
CHANGED
@@ -3,11 +3,12 @@ module Devise
|
|
3
3
|
# and overwrite the apply_schema method.
|
4
4
|
module Schema
|
5
5
|
|
6
|
-
# Creates email when
|
6
|
+
# Creates encrypted_password, and email when it is used as an authentication
|
7
|
+
# key (default).
|
7
8
|
#
|
8
9
|
# == Options
|
9
10
|
# * :null - When true, allow columns to be null.
|
10
|
-
# * :default -
|
11
|
+
# * :default - Set to "" when :null is false, unless overridden.
|
11
12
|
#
|
12
13
|
# == Notes
|
13
14
|
# For Datamapper compatibility, we explicitly hardcode the limit for the
|
@@ -21,7 +22,8 @@ module Devise
|
|
21
22
|
apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
|
22
23
|
end
|
23
24
|
|
24
|
-
# Creates password salt for encryption support
|
25
|
+
# Creates password salt for encryption support when using encryptors other
|
26
|
+
# than the database_authenticable default of bcrypt.
|
25
27
|
def encryptable
|
26
28
|
apply_devise_schema :password_salt, String
|
27
29
|
end
|
@@ -39,7 +39,11 @@ module Devise
|
|
39
39
|
|
40
40
|
# Try both scoped and non scoped keys.
|
41
41
|
def params_auth_hash
|
42
|
-
params[scope]
|
42
|
+
if params[scope].kind_of?(Hash) && params[scope].has_key?(authentication_keys.first)
|
43
|
+
params[scope]
|
44
|
+
else
|
45
|
+
params
|
46
|
+
end
|
43
47
|
end
|
44
48
|
|
45
49
|
# Overwrite authentication keys to use token_authentication_key.
|
data/lib/devise/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
require 'generators/devise/orm_helpers'
|
3
3
|
|
4
|
+
|
4
5
|
module ActiveRecord
|
5
6
|
module Generators
|
6
7
|
class DeviseGenerator < ActiveRecord::Generators::Base
|
@@ -9,14 +10,18 @@ module ActiveRecord
|
|
9
10
|
include Devise::Generators::OrmHelpers
|
10
11
|
source_root File.expand_path("../templates", __FILE__)
|
11
12
|
|
12
|
-
def generate_model
|
13
|
-
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
14
|
-
end
|
15
|
-
|
16
13
|
def copy_devise_migration
|
17
|
-
|
14
|
+
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
15
|
+
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
|
16
|
+
else
|
17
|
+
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
18
|
+
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def generate_model
|
22
|
+
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
23
|
+
end
|
24
|
+
|
20
25
|
def inject_devise_content
|
21
26
|
inject_into_class(model_path, class_name, model_contents + <<CONTENT) if model_exists?
|
22
27
|
# Setup accessible (or protected) attributes for your model
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
t.database_authenticatable :null => false
|
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
|
13
|
+
|
14
|
+
<% for attribute in attributes -%>
|
15
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
16
|
+
<% end -%>
|
17
|
+
|
18
|
+
# Uncomment below if timestamps were not included in your original model.
|
19
|
+
# t.timestamps
|
20
|
+
end
|
21
|
+
|
22
|
+
add_index :<%= table_name %>, :email, :unique => true
|
23
|
+
add_index :<%= table_name %>, :reset_password_token, :unique => true
|
24
|
+
# add_index :<%= table_name %>, :confirmation_token, :unique => true
|
25
|
+
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
26
|
+
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.down
|
30
|
+
# By default, we don't want to make any assumption about how to roll back a migration when your
|
31
|
+
# model already existed. Please edit below which fields you would like to remove in this migration.
|
32
|
+
raise ActiveRecord::IrreversibleMigration
|
33
|
+
end
|
34
|
+
end
|
@@ -14,6 +14,14 @@ CONTENT
|
|
14
14
|
def model_exists?
|
15
15
|
File.exists?(File.join(destination_root, model_path))
|
16
16
|
end
|
17
|
+
|
18
|
+
def migration_exists?(table_name)
|
19
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
20
|
+
end
|
21
|
+
|
22
|
+
def migration_path
|
23
|
+
@migration_path ||= File.join("db", "migrate")
|
24
|
+
end
|
17
25
|
|
18
26
|
def model_path
|
19
27
|
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
@@ -2,7 +2,8 @@
|
|
2
2
|
# four configuration values can also be set straight in your models.
|
3
3
|
Devise.setup do |config|
|
4
4
|
# ==> Mailer Configuration
|
5
|
-
# Configure the e-mail address which will be shown in
|
5
|
+
# Configure the e-mail address which will be shown in Devise::Mailer,
|
6
|
+
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
6
7
|
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
7
8
|
|
8
9
|
# Configure the class responsible to send e-mails.
|
@@ -35,7 +36,7 @@ Devise.setup do |config|
|
|
35
36
|
# These keys will be downcased upon creating or modifying a user and when used
|
36
37
|
# to authenticate or find a user. Default is :email.
|
37
38
|
config.case_insensitive_keys = [ :email ]
|
38
|
-
|
39
|
+
|
39
40
|
# Configure which authentication keys should have whitespace stripped.
|
40
41
|
# These keys will have whitespace before and after removed upon creating or
|
41
42
|
# modifying a user and when used to authenticate or find a user. Default is :email.
|
@@ -61,7 +62,11 @@ Devise.setup do |config|
|
|
61
62
|
# ==> Configuration for :database_authenticatable
|
62
63
|
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
63
64
|
# using other encryptors, it sets how many times you want the password re-encrypted.
|
64
|
-
|
65
|
+
#
|
66
|
+
# Limiting the stretches to just one in testing will increase the performance of
|
67
|
+
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
68
|
+
# a value less than 10 in other environments.
|
69
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
65
70
|
|
66
71
|
# Setup a pepper to generate the encrypted password.
|
67
72
|
# config.pepper = <%= SecureRandom.hex(64).inspect %>
|
@@ -100,8 +105,10 @@ Devise.setup do |config|
|
|
100
105
|
# Range for password length. Default is 6..128.
|
101
106
|
# config.password_length = 6..128
|
102
107
|
|
103
|
-
#
|
104
|
-
#
|
108
|
+
# Email regex used to validate email formats. It simply asserts that
|
109
|
+
# an one (and only one) @ exists in the given string. This is mainly
|
110
|
+
# to give user feedback and not to assert the e-mail validity.
|
111
|
+
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
105
112
|
|
106
113
|
# ==> Configuration for :timeoutable
|
107
114
|
# The time you want to timeout the user session without activity. After this
|