demarches-normaliennes/app/services/sync_credentials_service.rb

40 lines
1,008 B
Ruby
Raw Normal View History

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!
2018-01-11 19:04:39 +01:00
if @klass != User
user = User.find_by(email: @email_was)
if user
2018-01-11 19:04:39 +01:00
return false if !user.update_columns(
email: @email,
encrypted_password: @encrypted_password)
end
end
2018-01-11 19:04:39 +01:00
if @klass != Gestionnaire
gestionnaire = Gestionnaire.find_by(email: @email_was)
if gestionnaire
2018-01-11 19:04:39 +01:00
return false if !gestionnaire.update_columns(
email: @email,
encrypted_password: @encrypted_password)
end
end
2018-01-11 19:04:39 +01:00
if @klass != Administrateur
administrateur = Administrateur.find_by(email: @email_was)
if administrateur
2018-01-11 19:04:39 +01:00
return false if !administrateur.update_columns(
email: @email,
encrypted_password: @encrypted_password)
end
end
2017-02-07 16:56:21 +01:00
true
end
end