demarches-normaliennes/app/models/concerns/credentials_syncable_concern.rb

19 lines
399 B
Ruby
Raw Normal View History

2017-02-07 16:56:21 +01:00
module CredentialsSyncableConcern
2017-08-28 11:18:38 +02:00
extend ActiveSupport::Concern
2017-02-07 16:56:21 +01:00
included do
after_update :sync_credentials
end
2017-02-07 16:56:21 +01:00
def sync_credentials
if email_changed? || encrypted_password_changed?
return force_sync_credentials
2017-02-07 16:56:21 +01:00
end
true
end
2017-02-07 16:56:21 +01:00
def force_sync_credentials
SyncCredentialsService.new(self.class, email_was, email, encrypted_password).change_credentials!
end
2017-02-07 16:56:21 +01:00
end