Model FC : au lieu de valider le mail on envoie une demande de confirmation par mail
This commit is contained in:
parent
f531ba65f2
commit
9c41c9a08f
1 changed files with 9 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
class FranceConnectInformation < ApplicationRecord
|
||||
MERGE_VALIDITY = 15.minutes
|
||||
CONFIRMATION_EMAIL_VALIDITY = 2.days
|
||||
|
||||
belongs_to :user, optional: true
|
||||
|
||||
|
@ -14,9 +15,9 @@ class FranceConnectInformation < ApplicationRecord
|
|||
password: Devise.friendly_token[0, 20],
|
||||
confirmed_at: Time.zone.now
|
||||
)
|
||||
user.after_confirmation
|
||||
send_custom_confirmation_instructions(user)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# ignore this exception because we check before is user is nil.
|
||||
# ignore this exception because we check before if 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
|
||||
|
@ -26,6 +27,12 @@ class FranceConnectInformation < ApplicationRecord
|
|||
touch # needed to update updated_at column
|
||||
end
|
||||
|
||||
def send_custom_confirmation_instructions(user)
|
||||
token = SecureRandom.hex(10)
|
||||
user.update!(confirmation_token: token, confirmation_sent_at: Time.zone.now)
|
||||
UserMailer.custom_confirmation_instructions(user, token).deliver_later
|
||||
end
|
||||
|
||||
def create_merge_token!
|
||||
merge_token = SecureRandom.uuid
|
||||
update(merge_token:, merge_token_created_at: Time.zone.now)
|
||||
|
|
Loading…
Reference in a new issue