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

19 lines
428 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
2018-01-30 17:14:56 +01:00
if saved_change_to_email? || saved_change_to_encrypted_password?
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
2018-01-30 17:14:56 +01:00
SyncCredentialsService.new(self.class, email_before_last_save, email, encrypted_password).change_credentials!
end
2017-02-07 16:56:21 +01:00
end