From 3cf3dc462353008ebba0762b0ff0929275d3bc35 Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Wed, 21 Aug 2024 16:23:56 +0200 Subject: [PATCH] make email confirmation more generic --- app/controllers/users/activate_controller.rb | 2 +- app/mailers/user_mailer.rb | 14 ++++++++++++++ app/models/user.rb | 6 ++++++ ...avis_invitation_and_confirm_email.html.haml | 2 +- .../resend_confirmation_email.html.haml | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 app/views/user_mailer/resend_confirmation_email.html.haml diff --git a/app/controllers/users/activate_controller.rb b/app/controllers/users/activate_controller.rb index 4ab7c47ac25..f5dd798c890 100644 --- a/app/controllers/users/activate_controller.rb +++ b/app/controllers/users/activate_controller.rb @@ -40,7 +40,7 @@ def confirm_email else if user.present? flash[:alert] = "Ce lien n'est plus valable, un nouveau lien a été envoyé à l'adresse #{user.email}" - User.create_or_promote_to_tiers(user.email, SecureRandom.hex) + user.resend_confirmation_email! else flash[:alert] = "Un problème est survenu, vous pouvez nous contacter sur #{Current.contact_email}" end diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index d6fb81b495d..cff0e46494e 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -63,6 +63,20 @@ def invite_tiers(user, token, dossier) reply_to: Current.contact_email) end + def resend_confirmation_email(user, token) + @token = token + @user = user + subject = "Vérification de votre mail" + + configure_defaults_for_user(user) + + bypass_unverified_mail_protection! + + mail(to: user.email, + subject: subject, + reply_to: Current.contact_email) + end + def invite_gestionnaire(user, reset_password_token, groupe_gestionnaire) @reset_password_token = reset_password_token @user = user diff --git a/app/models/user.rb b/app/models/user.rb index cb7234590d9..98806a5d26c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -95,6 +95,12 @@ def invite_expert_and_send_avis!(avis) AvisMailer.avis_invitation_and_confirm_email(self, token, avis).deliver_later end + def resend_confirmation_email! + token = SecureRandom.hex(10) + self.update!(confirmation_token: token, confirmation_sent_at: Time.zone.now) + UserMailer.resend_confirmation_email(self, token).deliver_later + end + def invite_gestionnaire!(groupe_gestionnaire) UserMailer.invite_gestionnaire(self, set_reset_password_token, groupe_gestionnaire).deliver_later end diff --git a/app/views/avis_mailer/avis_invitation_and_confirm_email.html.haml b/app/views/avis_mailer/avis_invitation_and_confirm_email.html.haml index ce4db376a6b..aab81b4597a 100644 --- a/app/views/avis_mailer/avis_invitation_and_confirm_email.html.haml +++ b/app/views/avis_mailer/avis_invitation_and_confirm_email.html.haml @@ -24,7 +24,7 @@ - if @avis.expert.user.active? %p - = round_button("Confirmer le mail pour donner votre avis", @url, :primary) + = round_button('Confirmez votre adresse email pour donner votre avis', users_confirm_email_url(token: @token), :primary) - else %p = round_button("Inscrivez-vous pour donner votre avis", @url, :primary) diff --git a/app/views/user_mailer/resend_confirmation_email.html.haml b/app/views/user_mailer/resend_confirmation_email.html.haml new file mode 100644 index 00000000000..a189423c4b4 --- /dev/null +++ b/app/views/user_mailer/resend_confirmation_email.html.haml @@ -0,0 +1,18 @@ +- content_for(:title, "Vérification de votre mail sur #{Current.application_name}") + +%p + Bonjour, + +%p + Votre précédente confirmation de mail n'a pas fonctionné, vous pouvez essayer de nouveau en cliquant sur ce bouton : + = round_button 'Je confirme', users_confirm_email_url(token: @token), :primary + +%p + Vous pouvez aussi utiliser ce lien : + = link_to(users_confirm_email_url(token: @token), users_confirm_email_url(token: @token)) + +%p + Nous restons à votre disposition si vous avez besoin d’accompagnement à l'adresse #{link_to CONTACT_EMAIL, "mailto:#{CONTACT_EMAIL}"}. + + += render partial: "layouts/mailers/signature"