Remove credenticals synchronisation logic

This commit is contained in:
simon lehericey 2019-08-11 19:25:36 +02:00
parent 58ecf18390
commit dab1519b8c
8 changed files with 0 additions and 57 deletions

View file

@ -47,7 +47,6 @@ class Administrateurs::ActivateController < ApplicationController
if resource&.valid_password?(password)
sign_in resource
resource.force_sync_credentials
end
end
end

View file

@ -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)

View file

@ -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

View file

@ -1,5 +1,4 @@
class Administrateur < ApplicationRecord
include CredentialsSyncableConcern
include EmailSanitizableConcern
include ActiveRecord::SecureToken

View file

@ -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

View file

@ -1,5 +1,4 @@
class Instructeur < ApplicationRecord
include CredentialsSyncableConcern
include EmailSanitizableConcern
has_and_belongs_to_many :administrateurs

View file

@ -1,5 +1,4 @@
class User < ApplicationRecord
include CredentialsSyncableConcern
include EmailSanitizableConcern
enum loged_in_with_france_connect: {

View file

@ -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