6826bf03b0
instead of looking linked user by email because : - follows FC recommendation to fetch ds account by openid - the email is not a valid key as many user can share the same FCI email. The following scenario is now working A user A (email: 1@mail.com) uses FC to connect to DS => It is connected as 1@mail.com Another user B (email: generic@mail.com) uses FC to connect => It is connected as generic@mail.com The first user A change its FC email to generic@mail.com and connect to DS => It is still connected as 1@mail.com
40 lines
1.5 KiB
Ruby
40 lines
1.5 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: france_connect_informations
|
|
#
|
|
# id :integer not null, primary key
|
|
# birthdate :date
|
|
# birthplace :string
|
|
# data :jsonb
|
|
# email_france_connect :string
|
|
# family_name :string
|
|
# gender :string
|
|
# given_name :string
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# france_connect_particulier_id :string
|
|
# user_id :integer not null
|
|
#
|
|
class FranceConnectInformation < ApplicationRecord
|
|
belongs_to :user, optional: true
|
|
|
|
validates :france_connect_particulier_id, presence: true, allow_blank: false, allow_nil: false
|
|
|
|
def associate_user!
|
|
begin
|
|
user = User.create!(
|
|
email: email_france_connect.downcase,
|
|
password: Devise.friendly_token[0, 20],
|
|
confirmed_at: Time.zone.now
|
|
)
|
|
rescue ActiveRecord::RecordNotUnique
|
|
# ignore this exception because we check before is user is nil.
|
|
# exception can be raised in race conditions, when FranceConnect calls callback 2 times.
|
|
# At the 2nd call, user is nil but exception is raised at the creation of the user
|
|
# because the first call has already created a user
|
|
end
|
|
|
|
update_attribute('user_id', user.id)
|
|
touch # needed to update updated_at column
|
|
end
|
|
end
|