demarches-normaliennes/app/services/sync_credentials_service.rb

34 lines
1 KiB
Ruby
Raw Normal View History

class SyncCredentialsService
def initialize(klass, email_before_last_save, email, encrypted_password)
@klass = klass
2018-01-30 17:14:56 +01:00
@email_before_last_save = email_before_last_save
@email = email
@encrypted_password = encrypted_password
end
def change_credentials!
2018-01-11 19:04:39 +01:00
if @klass != User
2018-01-30 17:14:56 +01:00
user = User.find_by(email: @email_before_last_save)
if user && !user.update_columns(email: @email, encrypted_password: @encrypted_password)
return false
end
end
2018-01-11 19:04:39 +01:00
if @klass != Gestionnaire
2018-01-30 17:14:56 +01:00
gestionnaire = Gestionnaire.find_by(email: @email_before_last_save)
if gestionnaire && !gestionnaire.update_columns(email: @email, encrypted_password: @encrypted_password)
return false
end
end
2018-01-11 19:04:39 +01:00
if @klass != Administrateur
2018-01-30 17:14:56 +01:00
administrateur = Administrateur.find_by(email: @email_before_last_save)
if administrateur && !administrateur.update_columns(email: @email, encrypted_password: @encrypted_password)
return false
end
end
2017-02-07 16:56:21 +01:00
true
end
end