readapt name and logic

This commit is contained in:
simon lehericey 2024-07-31 17:50:14 +02:00 committed by Kara Diaby
parent 94be599401
commit eaef5c7e39
No known key found for this signature in database
GPG key ID: C4D1B0CF9F24D759
14 changed files with 210 additions and 512 deletions

View file

@ -8,7 +8,7 @@ class FranceConnectInformation < ApplicationRecord
validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false
def associate_user!(email)
def safely_associate_user!(email)
begin
user = User.create!(
email: email.downcase,
@ -22,11 +22,18 @@ class FranceConnectInformation < ApplicationRecord
# because the first call has already created a user
end
clean_tokens_and_requested_email
update_attribute('user_id', user.id)
touch # needed to update updated_at column
save!
end
def send_custom_confirmation_instructions(user)
def safely_update_user(user:)
self.user = user
clean_tokens_and_requested_email
save!
end
def send_custom_confirmation_instructions
token = SecureRandom.hex(10)
user.update!(confirmation_token: token, confirmation_sent_at: Time.zone.now)
UserMailer.custom_confirmation_instructions(user, token).deliver_later
@ -54,14 +61,18 @@ class FranceConnectInformation < ApplicationRecord
(MERGE_VALIDITY.ago < email_merge_token_created_at) && user_id.nil?
end
def delete_merge_token!
update(merge_token: nil, merge_token_created_at: nil)
end
def delete_email_merge_token!
update(email_merge_token: nil, email_merge_token_created_at: nil)
end
def clean_tokens_and_requested_email
self.merge_token = nil
self.merge_token_created_at = nil
self.email_merge_token = nil
self.email_merge_token_created_at = nil
self.requested_email = nil
end
def full_name
[given_name, family_name].compact.join(" ")
end