Sync credentials between user, gestionnaire and administrateur account

This commit is contained in:
Xavier J 2016-12-07 17:24:01 +01:00
parent d282d7bbea
commit 7cb2e80a3d
7 changed files with 96 additions and 12 deletions

View file

@ -6,6 +6,7 @@ class Administrateur < ActiveRecord::Base
has_many :procedures
before_save :ensure_api_token
after_update :sync_credentials, if: -> { Features.unified_login }
def ensure_api_token
if api_token.nil?
@ -25,4 +26,11 @@ class Administrateur < ActiveRecord::Base
break token unless Administrateur.find_by(api_token: token)
end
end
def sync_credentials
if email_changed? || encrypted_password_changed?
return SyncCredentialsService.new(Administrateur, email_was, email, encrypted_password).change_credentials!
end
true
end
end

View file

@ -88,12 +88,7 @@ class Gestionnaire < ActiveRecord::Base
def sync_credentials
if email_changed? || encrypted_password_changed?
user = User.find_by(email: email_was)
if user
return user.update_columns(
email: email,
encrypted_password: encrypted_password)
end
return SyncCredentialsService.new(Gestionnaire, email_was, email, encrypted_password).change_credentials!
end
true
end

View file

@ -39,12 +39,7 @@ class User < ActiveRecord::Base
def sync_credentials
if email_changed? || encrypted_password_changed?
gestionnaire = Gestionnaire.find_by(email: email_was)
if gestionnaire
return gestionnaire.update_columns(
email: email,
encrypted_password: encrypted_password)
end
return SyncCredentialsService.new(User, email_was, email, encrypted_password).change_credentials!
end
true
end