diff --git a/app/controllers/administrateurs/activate_controller.rb b/app/controllers/administrateurs/activate_controller.rb index 2d45c0da1..b4bf8346d 100644 --- a/app/controllers/administrateurs/activate_controller.rb +++ b/app/controllers/administrateurs/activate_controller.rb @@ -47,7 +47,6 @@ class Administrateurs::ActivateController < ApplicationController if resource&.valid_password?(password) sign_in resource - resource.force_sync_credentials end end end diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index ec5755987..b66d836be 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -42,7 +42,6 @@ class Users::ConfirmationsController < Devise::ConfirmationsController if sign_in_after_confirmation?(resource) resource.remember_me = true sign_in(resource) - resource.force_sync_credentials after_sign_in_path_for(resource_name) else super(resource_name, resource) diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 949b58e31..774436d69 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -101,7 +101,6 @@ class Users::SessionsController < Devise::SessionsController if resource.valid_password?(params[:user][:password]) resource.remember_me = remember_me sign_in resource - resource.force_sync_credentials end end resource diff --git a/app/models/administrateur.rb b/app/models/administrateur.rb index 0a3007694..9a9f39174 100644 --- a/app/models/administrateur.rb +++ b/app/models/administrateur.rb @@ -1,5 +1,4 @@ class Administrateur < ApplicationRecord - include CredentialsSyncableConcern include EmailSanitizableConcern include ActiveRecord::SecureToken diff --git a/app/models/concerns/credentials_syncable_concern.rb b/app/models/concerns/credentials_syncable_concern.rb deleted file mode 100644 index f42b4adae..000000000 --- a/app/models/concerns/credentials_syncable_concern.rb +++ /dev/null @@ -1,18 +0,0 @@ -module CredentialsSyncableConcern - extend ActiveSupport::Concern - - included do - after_update :sync_credentials - end - - def sync_credentials - if saved_change_to_email? || saved_change_to_encrypted_password? - return force_sync_credentials - end - true - end - - def force_sync_credentials - SyncCredentialsService.new(self.class, email_before_last_save, email, encrypted_password).change_credentials! - end -end diff --git a/app/models/instructeur.rb b/app/models/instructeur.rb index b61fd3b2d..5fcb1b205 100644 --- a/app/models/instructeur.rb +++ b/app/models/instructeur.rb @@ -1,5 +1,4 @@ class Instructeur < ApplicationRecord - include CredentialsSyncableConcern include EmailSanitizableConcern has_and_belongs_to_many :administrateurs diff --git a/app/models/user.rb b/app/models/user.rb index 42f7ceaa1..1f07f518d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,4 @@ class User < ApplicationRecord - include CredentialsSyncableConcern include EmailSanitizableConcern enum loged_in_with_france_connect: { diff --git a/app/services/sync_credentials_service.rb b/app/services/sync_credentials_service.rb deleted file mode 100644 index 13322b1f4..000000000 --- a/app/services/sync_credentials_service.rb +++ /dev/null @@ -1,33 +0,0 @@ -class SyncCredentialsService - def initialize(klass, email_before_last_save, email, encrypted_password) - @klass = klass - @email_before_last_save = email_before_last_save - @email = email - @encrypted_password = encrypted_password - end - - def change_credentials! - if @klass != User - user = User.find_by(email: @email_before_last_save) - if user && !user.update_columns(email: @email, encrypted_password: @encrypted_password) - return false - end - end - - if @klass != Instructeur - instructeur = Instructeur.find_by(email: @email_before_last_save) - if instructeur && !instructeur.update_columns(email: @email, encrypted_password: @encrypted_password) - return false - end - end - - if @klass != Administrateur - administrateur = Administrateur.find_by(email: @email_before_last_save) - if administrateur && !administrateur.update_columns(email: @email, encrypted_password: @encrypted_password) - return false - end - end - - true - end -end