diff --git a/lib/devise.rb b/lib/devise.rb index 0d9aee27..a6d242d6 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -143,6 +143,10 @@ module Devise mattr_accessor :lock_strategy @@lock_strategy = :failed_attempts + # Defines which key will be used when locking and unlocking an account + mattr_accessor :unlock_keys + @@unlock_keys = [ :email ] + # Defines which strategy can be used to unlock an account. # Values: :email, :time, :both mattr_accessor :unlock_strategy @@ -156,6 +160,10 @@ module Devise mattr_accessor :unlock_in @@unlock_in = 1.hour + # Defines which key will be used when recovering the password for an account + mattr_accessor :reset_password_keys + @@reset_password_keys = [ :email ] + # The default scope which is used by warden. mattr_accessor :default_scope @@default_scope = nil diff --git a/lib/devise/models/lockable.rb b/lib/devise/models/lockable.rb index c910daa4..54f3f640 100644 --- a/lib/devise/models/lockable.rb +++ b/lib/devise/models/lockable.rb @@ -15,6 +15,7 @@ module Devise # * +lock_strategy+: lock the user account by :failed_attempts or :none. # * +unlock_strategy+: unlock the user account by :time, :email, :both or :none. # * +unlock_in+: the time you want to lock the user after to lock happens. Only available when unlock_strategy is :time or :both. + # * +unlock_keys+: the keys you want to use when locking and unlocking an account # module Lockable extend ActiveSupport::Concern @@ -161,11 +162,7 @@ module Devise Devise.friendly_token end - def unlock_keys - [:email] - end - - Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in) + Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in, :unlock_keys) end end end diff --git a/lib/devise/models/recoverable.rb b/lib/devise/models/recoverable.rb index 73533060..ae415f6e 100644 --- a/lib/devise/models/recoverable.rb +++ b/lib/devise/models/recoverable.rb @@ -3,6 +3,12 @@ module Devise # Recoverable takes care of reseting the user password and send reset instructions. # + # ==Options + # + # Recoverable adds the following options to devise_for: + # + # * +reset_password_keys+: the keys you want to use when recovering the password for an account + # # == Examples # # # resets the user password and save the record, true if valid passwords are given, otherwise false @@ -67,10 +73,6 @@ module Devise generate_token(:reset_password_token) end - def reset_password_keys - [:email] - end - # Attempt to find a user by it's reset_password_token to reset it's # password. If a user is found, reset it's password and automatically # try saving the record. If not user is found, returns a new user @@ -81,6 +83,8 @@ module Devise recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) if recoverable.persisted? recoverable end + + Devise::Models.config(self, :reset_password_keys) end end end diff --git a/lib/generators/templates/devise.rb b/lib/generators/templates/devise.rb index b459c777..10170933 100644 --- a/lib/generators/templates/devise.rb +++ b/lib/generators/templates/devise.rb @@ -94,6 +94,9 @@ Devise.setup do |config| # :none = No lock strategy. You should handle locking by yourself. # config.lock_strategy = :failed_attempts + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [ :email ] + # Defines which strategy will be used to unlock an account. # :email = Sends an unlock link to the user email # :time = Re-enables login after a certain amount of time (see :unlock_in below) @@ -108,6 +111,11 @@ Devise.setup do |config| # Time interval to unlock the account if :time is enabled as unlock_strategy. # config.unlock_in = 1.hour + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [ :email ] + # ==> Configuration for :encryptable # Allow you to use another encryption algorithm besides bcrypt (default). You can use # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index c1e402d8..1aeee649 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -89,6 +89,9 @@ Devise.setup do |config| # :none = No lock strategy. You should handle locking by yourself. # config.lock_strategy = :failed_attempts + # Defines which key will be used when locking and unlocking an account + # config.unlock_keys = [ :email ] + # Defines which strategy will be used to unlock an account. # :email = Sends an unlock link to the user email # :time = Re-enables login after a certain amount of time (see :unlock_in below) @@ -103,6 +106,11 @@ Devise.setup do |config| # Time interval to unlock the account if :time is enabled as unlock_strategy. # config.unlock_in = 1.hour + # ==> Configuration for :recoverable + # + # Defines which key will be used when recovering the password for an account + # config.reset_password_keys = [ :email ] + # ==> Configuration for :encryptable # Allow you to use another encryption algorithm besides bcrypt (default). You can use # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,