Merge pull request #4744 from betagouv/add-sign-in-link-to-account-already-exists-email
Usager : dans l'email « Le compte existe déjà », ajoute un lien vers la démarche
This commit is contained in:
commit
f2b7200edc
7 changed files with 87 additions and 22 deletions
|
@ -25,7 +25,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
|||
existing_user = User.find_by(email: params[:user][:email])
|
||||
if existing_user.present?
|
||||
if existing_user.confirmed?
|
||||
UserMailer.new_account_warning(existing_user).deliver_later
|
||||
UserMailer.new_account_warning(existing_user, @procedure).deliver_later
|
||||
else
|
||||
existing_user.resend_confirmation_instructions
|
||||
end
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
|
||||
class UserMailer < ApplicationMailer
|
||||
helper MailerHelper
|
||||
|
||||
layout 'mailers/layout'
|
||||
|
||||
def new_account_warning(user)
|
||||
def new_account_warning(user, procedure = nil)
|
||||
@user = user
|
||||
@subject = "Demande de création de compte"
|
||||
@procedure = procedure
|
||||
|
||||
mail(to: user.email, subject: @subject)
|
||||
mail(to: user.email, subject: @subject, procedure: @procedure)
|
||||
end
|
||||
|
||||
def account_already_taken(user, requested_email)
|
||||
|
|
|
@ -7,9 +7,25 @@
|
|||
Une demande de création de compte a été réalisée sur le site demarches-simplifiees.fr pour l'email #{@user.email}.
|
||||
|
||||
%p
|
||||
Votre compte existe déjà. Si vous souhaitez changer votre mot de passe, veuillez suivre les instructions à l'adresse suivante
|
||||
#{link_to(new_password_url(@user), new_password_url(@user))}.
|
||||
%strong Votre compte existe déjà.
|
||||
|
||||
- if @procedure
|
||||
%p
|
||||
Si vous souhaitez remplir la démarche
|
||||
= surround '« ', ' »,' do
|
||||
%i= @procedure.libelle
|
||||
cliquez sur le bouton ci-dessous.
|
||||
|
||||
= round_button("Commencer la démarche « #{@procedure.libelle.truncate(60)} »", commencer_sign_in_url(path: @procedure.path), :primary)
|
||||
= vertical_margin(16)
|
||||
= round_button('J’ai oublié mon mot de passe', new_password_url(@user), :secondary)
|
||||
|
||||
- else
|
||||
%p
|
||||
Vous n'avez rien à faire. Si vous avez oublié votre mot de passe, cliquez sur le bouton ci-dessous.
|
||||
= round_button('J’ai oublié mon mot de passe', new_password_url(@user), :secondary)
|
||||
|
||||
= vertical_margin(6)
|
||||
%p
|
||||
Si vous n'êtes pas à l'origine de cette demande, vous pouvez ignorer ce mail.
|
||||
|
||||
|
|
|
@ -91,27 +91,52 @@ feature 'Signing up:' do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when a user is not confirmed yet' do
|
||||
context 'when the user is not confirmed yet' do
|
||||
before do
|
||||
create(:user, :unconfirmed, email: user_email, password: user_password)
|
||||
end
|
||||
|
||||
scenario 'the email confirmation page is displayed' do
|
||||
visit commencer_path(path: procedure.path)
|
||||
click_on 'Créer un compte demarches-simplifiees.fr'
|
||||
click_on 'Créer un compte'
|
||||
|
||||
sign_up_with user_email, user_password
|
||||
|
||||
# The same page than for initial sign-ups is displayed, to avoid leaking informations
|
||||
# about the accound existence.
|
||||
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
|
||||
|
||||
# The confirmation email is sent again
|
||||
confirmation_email = open_email(user_email)
|
||||
expect(confirmation_email.body).to have_text('Pour activer votre compte')
|
||||
end
|
||||
end
|
||||
|
||||
# Ideally, when signing-in with an unconfirmed account,
|
||||
# the user would be redirected to the "resend email confirmation" page.
|
||||
#
|
||||
# However the check for unconfirmed accounts is made by Warden every time a page is loaded –
|
||||
# and much earlier than SessionsController#create.
|
||||
#
|
||||
# For now only test the default behavior (an error message is displayed).
|
||||
scenario 'they get an error message' do
|
||||
visit root_path
|
||||
click_on 'Connexion'
|
||||
context 'when the user already has a confirmed account' do
|
||||
before do
|
||||
create(:user, email: user_email, password: user_password)
|
||||
end
|
||||
|
||||
sign_in_with user_email, user_password
|
||||
expect(page).to have_content 'Vous devez confirmer votre adresse email pour continuer'
|
||||
scenario 'they get a warning email, containing a link to the procedure' do
|
||||
visit commencer_path(path: procedure.path)
|
||||
click_on 'Créer un compte'
|
||||
|
||||
sign_up_with user_email, user_password
|
||||
|
||||
# The same page than for initial sign-ups is displayed, to avoid leaking informations
|
||||
# about the accound existence.
|
||||
expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}"
|
||||
|
||||
# A warning email is sent
|
||||
warning_email = open_email(user_email)
|
||||
expect(warning_email.body).to have_text('Votre compte existe déjà')
|
||||
|
||||
# When clicking the main button, the user has a link to directly sign-in
|
||||
# for the procedure they were initially starting
|
||||
click_procedure_sign_in_link_for user_email
|
||||
|
||||
expect(page).to have_current_path new_user_session_path
|
||||
expect(page).to have_procedure_description(procedure)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,11 @@ class UserMailerPreview < ActionMailer::Preview
|
|||
UserMailer.new_account_warning(user)
|
||||
end
|
||||
|
||||
def new_account_warning___with_procedure
|
||||
procedure = Procedure.new(libelle: 'Dotation d’Équipement des Territoires Ruraux - Exercice 2019', path: 'dotation-etr')
|
||||
UserMailer.new_account_warning(user, procedure)
|
||||
end
|
||||
|
||||
def account_already_taken
|
||||
UserMailer.account_already_taken(user, 'dircab@territoires.gouv.fr')
|
||||
end
|
||||
|
|
|
@ -8,6 +8,15 @@ RSpec.describe UserMailer, type: :mailer do
|
|||
|
||||
it { expect(subject.to).to eq([user.email]) }
|
||||
it { expect(subject.body).to include(user.email) }
|
||||
it { expect(subject.body).to have_link('J’ai oublié mon mot de passe') }
|
||||
|
||||
context 'when a procedure is provided' do
|
||||
let(:procedure) { build(:procedure) }
|
||||
|
||||
subject { described_class.new_account_warning(user, procedure) }
|
||||
|
||||
it { expect(subject.body).to have_link("Commencer la démarche « #{procedure.libelle} »", href: commencer_sign_in_url(path: procedure.path)) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '.account_already_taken' do
|
||||
|
|
|
@ -55,6 +55,13 @@ module FeatureHelpers
|
|||
visit "/users/confirmation?#{token_params}"
|
||||
end
|
||||
|
||||
def click_procedure_sign_in_link_for(email)
|
||||
confirmation_email = open_email(email)
|
||||
procedure_sign_in_link = confirmation_email.body.match(/href="([^"]*\/commencer\/[^"]*)"/)[1]
|
||||
|
||||
visit procedure_sign_in_link
|
||||
end
|
||||
|
||||
def click_reset_password_link_for(email)
|
||||
reset_password_email = open_email(email)
|
||||
token_params = reset_password_email.body.match(/reset_password_token=[^"]+/)
|
||||
|
|
Loading…
Reference in a new issue