mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Allow send confirmation to change keys used
This commit is contained in:
parent
76a4800446
commit
7a1852e9f5
5 changed files with 29 additions and 2 deletions
|
@ -117,6 +117,10 @@ module Devise
|
|||
mattr_accessor :confirm_within
|
||||
@@confirm_within = 0.days
|
||||
|
||||
# Defines which key will be used when confirming an account
|
||||
mattr_accessor :confirmation_keys
|
||||
@@confirmation_keys = [ :email ]
|
||||
|
||||
# Time interval to timeout the user session without activity.
|
||||
mattr_accessor :timeout_in
|
||||
@@timeout_in = 30.minutes
|
||||
|
|
|
@ -133,7 +133,7 @@ module Devise
|
|||
# with an email not found error.
|
||||
# Options must contain the user email
|
||||
def send_confirmation_instructions(attributes={})
|
||||
confirmable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
|
||||
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
|
||||
confirmable.resend_confirmation_token if confirmable.persisted?
|
||||
confirmable
|
||||
end
|
||||
|
@ -153,7 +153,7 @@ module Devise
|
|||
generate_token(:confirmation_token)
|
||||
end
|
||||
|
||||
Devise::Models.config(self, :confirm_within)
|
||||
Devise::Models.config(self, :confirm_within, :confirmation_keys)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -65,6 +65,9 @@ Devise.setup do |config|
|
|||
# (ie 2 days).
|
||||
# config.confirm_within = 2.days
|
||||
|
||||
# Defines which key will be used when confirming an account
|
||||
# config.confirmation_keys = [ :email ]
|
||||
|
||||
# ==> Configuration for :rememberable
|
||||
# The time the user will be remembered without asking for credentials again.
|
||||
# config.remember_for = 2.weeks
|
||||
|
|
|
@ -218,4 +218,21 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
user.save
|
||||
assert user.reload.active?
|
||||
end
|
||||
|
||||
test 'should find a user to send email instructions for the user confirm it\'s email by authentication_keys' do
|
||||
swap Devise, :authentication_keys => [:username, :email] do
|
||||
user = create_user
|
||||
confirm_user = User.send_confirmation_instructions(:email => user.email, :username => user.username)
|
||||
assert_equal confirm_user, user
|
||||
end
|
||||
end
|
||||
|
||||
test 'should require all confirmation_keys' do
|
||||
swap Devise, :confirmation_keys => [:username, :email] do
|
||||
user = create_user
|
||||
confirm_user = User.send_confirmation_instructions(:email => user.email)
|
||||
assert_not confirm_user.persisted?
|
||||
assert_equal "can't be blank", confirm_user.errors[:username].join
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -62,6 +62,9 @@ Devise.setup do |config|
|
|||
# (ie 2 days).
|
||||
# config.confirm_within = 2.days
|
||||
|
||||
# Defines which key will be used when confirming an account
|
||||
# config.confirmation_keys = [ :email ]
|
||||
|
||||
# ==> Configuration for :rememberable
|
||||
# The time the user will be remembered without asking for credentials again.
|
||||
# config.remember_for = 2.weeks
|
||||
|
|
Loading…
Reference in a new issue