lib/quo_vadis/model.rb in quo_vadis-2.1.7 vs lib/quo_vadis/model.rb in quo_vadis-2.1.8
- old
+ new
@@ -12,11 +12,11 @@
def authenticates(identifier: :email)
include InstanceMethodsOnActivation
has_one :qv_account, as: :model, class_name: 'QuoVadis::Account', dependent: :destroy, autosave: true
- before_validation :qv_copy_identifier_to_account, if: Proc.new { |m| m.qv_account }
+ before_validation :qv_copy_identifier_to_account, if: :has_authentication_account?
validate :qv_copy_password_errors, if: Proc.new { |m| m.qv_account&.password }
unless validators_on(identifier).any? { |v| ActiveRecord::Validations::UniquenessValidator === v }
raise NotImplementedError, <<~END
@@ -27,12 +27,12 @@
define_method :qv_copy_identifier_to_account do
qv_account.identifier = send identifier
end
- after_update :qv_log_email_change, if: :saved_change_to_email?
- after_update :qv_notify_email_change, if: :saved_change_to_email?
+ after_update :qv_log_email_change, if: [:has_authentication_account?, :saved_change_to_email?]
+ after_update :qv_notify_email_change, if: [:has_authentication_account?, :saved_change_to_email?]
QuoVadis.register_model self.name, identifier
end
end
@@ -53,9 +53,13 @@
(qv_account.password || qv_account.build_password).password_confirmation = val
end
def revoke_authentication_credentials
qv_account.revoke
+ end
+
+ def has_authentication_account?
+ !!qv_account
end
private
def qv_copy_password_errors