demarches-normaliennes/app/services/sync_credentials_service.rb
2018-01-15 22:14:39 +01:00

39 lines
1,008 B
Ruby

class SyncCredentialsService
def initialize klass, email_was, email, encrypted_password
@klass = klass
@email_was = email_was
@email = email
@encrypted_password = encrypted_password
end
def change_credentials!
if @klass != User
user = User.find_by(email: @email_was)
if user
return false if !user.update_columns(
email: @email,
encrypted_password: @encrypted_password)
end
end
if @klass != Gestionnaire
gestionnaire = Gestionnaire.find_by(email: @email_was)
if gestionnaire
return false if !gestionnaire.update_columns(
email: @email,
encrypted_password: @encrypted_password)
end
end
if @klass != Administrateur
administrateur = Administrateur.find_by(email: @email_was)
if administrateur
return false if !administrateur.update_columns(
email: @email,
encrypted_password: @encrypted_password)
end
end
true
end
end