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