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
|
|
|
|
if email_changed? || encrypted_password_changed?
|
|
|
|
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
|
|
|
|
SyncCredentialsService.new(self.class, email_was, email, encrypted_password).change_credentials!
|
|
|
|
end
|
2017-02-07 16:56:21 +01:00
|
|
|
end
|