mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Do not run validatins unless on reconfirmable branch, closes #1515.
This commit is contained in:
parent
94e5a589b6
commit
89db0dd44d
4 changed files with 18 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
devise (1.5.2)
|
||||
devise (2.0.0.rc)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
orm_adapter (~> 0.0.3)
|
||||
warden (~> 1.1)
|
||||
|
|
|
@ -40,15 +40,17 @@ module Devise
|
|||
# is already confirmed, add an error to email field. If the user is invalid
|
||||
# add errors
|
||||
def confirm!
|
||||
unless_confirmed do
|
||||
pending_any_confirmation do
|
||||
self.confirmation_token = nil
|
||||
self.confirmed_at = Time.now.utc
|
||||
|
||||
if self.class.reconfirmable
|
||||
if self.class.reconfirmable && unconfirmed_email.present?
|
||||
@bypass_postpone = true
|
||||
self.email = unconfirmed_email if unconfirmed_email.present?
|
||||
self.email = unconfirmed_email
|
||||
self.unconfirmed_email = nil
|
||||
save
|
||||
|
||||
# We need to validate in such cases to enforce e-mail uniqueness
|
||||
save(:validate => true)
|
||||
else
|
||||
save(:validate => false)
|
||||
end
|
||||
|
@ -73,7 +75,7 @@ module Devise
|
|||
|
||||
# Resend confirmation token. This method does not need to generate a new token.
|
||||
def resend_confirmation_token
|
||||
unless_confirmed { send_confirmation_instructions }
|
||||
pending_any_confirmation { send_confirmation_instructions }
|
||||
end
|
||||
|
||||
# Overwrites active_for_authentication? for confirmation
|
||||
|
@ -133,10 +135,9 @@ module Devise
|
|||
confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago
|
||||
end
|
||||
|
||||
# Checks whether the record is confirmed or not or a new email has been added, yielding to the block
|
||||
# if it's already confirmed, otherwise adds an error to email.
|
||||
def unless_confirmed
|
||||
unless confirmed? && !pending_reconfirmation?
|
||||
# Checks whether the record requires any confirmation.
|
||||
def pending_any_confirmation
|
||||
if !confirmed? || pending_reconfirmation?
|
||||
yield
|
||||
else
|
||||
self.errors.add(:email, :already_confirmed)
|
||||
|
|
|
@ -238,6 +238,12 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
class ReconfirmableTest < ActiveSupport::TestCase
|
||||
test 'should not worry about validations on confirm even with reconfirmable' do
|
||||
admin = create_admin
|
||||
admin.reset_password_token = "a"
|
||||
assert admin.confirm!
|
||||
end
|
||||
|
||||
test 'should generate confirmation token after changing email' do
|
||||
admin = create_admin
|
||||
assert admin.confirm!
|
||||
|
|
|
@ -7,6 +7,7 @@ module SharedAdmin
|
|||
:unlock_strategy => :time, :lock_strategy => :none,
|
||||
:allow_unconfirmed_access_for => 2.weeks, :reconfirmable => true
|
||||
|
||||
validates_length_of :reset_password_token, :minimum => 3, :allow_blank => true
|
||||
validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue