Skip to content

Commit

Permalink
make email confirmation more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand committed Aug 21, 2024
1 parent ea354d4 commit 3cf3dc4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users/activate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Check warning on line 43 in app/controllers/users/activate_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/users/activate_controller.rb#L43

Added line #L43 was not covered by tests
else
flash[:alert] = "Un problème est survenu, vous pouvez nous contacter sur #{Current.contact_email}"
end
Expand Down
14 changes: 14 additions & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 69 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L67-L69

Added lines #L67 - L69 were not covered by tests

configure_defaults_for_user(user)

Check warning on line 71 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L71

Added line #L71 was not covered by tests

bypass_unverified_mail_protection!

Check warning on line 73 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L73

Added line #L73 was not covered by tests

mail(to: user.email,

Check warning on line 75 in app/mailers/user_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/user_mailer.rb#L75

Added line #L75 was not covered by tests
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
Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def invite_expert_and_send_avis!(avis)
AvisMailer.avis_invitation_and_confirm_email(self, token, avis).deliver_later
end

Check warning on line 96 in app/models/user.rb

View check run for this annotation

Codecov / codecov/patch

app/models/user.rb#L92-L96

Added lines #L92 - L96 were not covered by tests

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

Check warning on line 102 in app/models/user.rb

View check run for this annotation

Codecov / codecov/patch

app/models/user.rb#L98-L102

Added lines #L98 - L102 were not covered by tests

def invite_gestionnaire!(groupe_gestionnaire)
UserMailer.invite_gestionnaire(self, set_reset_password_token, groupe_gestionnaire).deliver_later
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions app/views/user_mailer/resend_confirmation_email.html.haml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3cf3dc4

Please sign in to comment.