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
|
|
|
|
2018-01-15 19:12:15 +01:00
|
|
|
included do
|
|
|
|
after_update :sync_credentials
|
|
|
|
end
|
2017-02-07 16:56:21 +01:00
|
|
|
|
2018-01-15 19:12:15 +01:00
|
|
|
def sync_credentials
|
2018-01-30 17:14:56 +01:00
|
|
|
if saved_change_to_email? || saved_change_to_encrypted_password?
|
2018-01-15 19:12:15 +01:00
|
|
|
return force_sync_credentials
|
2017-02-07 16:56:21 +01:00
|
|
|
end
|
2018-01-15 19:12:15 +01:00
|
|
|
true
|
|
|
|
end
|
2017-02-07 16:56:21 +01:00
|
|
|
|
2018-01-15 19:12:15 +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!
|
2018-01-15 19:12:15 +01:00
|
|
|
end
|
2017-02-07 16:56:21 +01:00
|
|
|
end
|