feat(particulier#associate_user): catch email already taken and redirect to reset password
This commit is contained in:
parent
828f491c14
commit
88a4619dcb
4 changed files with 32 additions and 0 deletions
|
@ -58,6 +58,12 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
|
||||
destination_path = destination_path(user)
|
||||
render :confirmation_sent, locals: { email:, destination_path: }
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
if e.record.errors.where(:email, :taken)
|
||||
redirect_to new_user_session_path, alert: t('errors.messages.france_connect.email_taken', reset_link: new_user_password_path)
|
||||
else
|
||||
redirect_to new_user_session_path, alert: t('errors.messages.france_connect.unknown_error')
|
||||
end
|
||||
end
|
||||
|
||||
def merge
|
||||
|
|
|
@ -751,6 +751,9 @@ en:
|
|||
# # etablissement_fail: 'Désolé, nous n’avons pas réussi à enregistrer l’établissement correspondant à ce numéro SIRET'
|
||||
france_connect:
|
||||
connexion: "Error trying to connect to France Connect."
|
||||
forbidden_html: "Only citizen can use FranceConnect. As an instructor or administrator, you should <a href='%{reset_link}'>reset your password</a>."
|
||||
email_taken: "This email is already in use. You should <a href='%{reset_link}'>reset your password</a>."
|
||||
unknown_error: "An error occured, please retry."
|
||||
evil_regexp: The regular expression you have entered is potentially dangerous and could lead to performance issues.
|
||||
mismatch_regexp: The provided example must match the regular expression
|
||||
syntax_error_regexp: The syntax of the regular expression is invalid
|
||||
|
|
|
@ -757,6 +757,8 @@ fr:
|
|||
france_connect:
|
||||
connexion: "Erreur lors de la connexion à France Connect."
|
||||
forbidden_html: "Seul-e-s les usagers peuvent se connecter via France Connect. En tant qu’instructeur ou administrateur, nous vous invitons à <a href='%{reset_link}'>réininitialiser votre mot de passe</a>."
|
||||
email_taken: "Cet email est déjà utilisé. Nous vous invitons à <a href='%{reset_link}'>réininitialiser votre mot de passe</a>."
|
||||
unknown_error: "Une erreure est survenue. Veuillez réessayer."
|
||||
evil_regexp: L'expression régulière que vous avez entrée est potentiellement dangereuse et pourrait entraîner des problèmes de performance
|
||||
mismatch_regexp: L'exemple doit correspondre à l'expression régulière fournie
|
||||
syntax_error_regexp: La syntaxe de l'expression régulière n'est pas valide
|
||||
|
|
|
@ -253,6 +253,27 @@ describe FranceConnect::ParticulierController, type: :controller do
|
|||
subject
|
||||
end
|
||||
end
|
||||
|
||||
context 'when associating the user conflict with existing one' do
|
||||
let(:fci) { instance_double('FranceConnectInformation') }
|
||||
let(:email) { 'user@example.com' }
|
||||
let(:user) { instance_double('User', id: 1) }
|
||||
let(:destination_path) { '/' }
|
||||
|
||||
before do
|
||||
create(:user, email:)
|
||||
invalid_user = build(:user, email:)
|
||||
allow(FranceConnectInformation).to receive(:find_by).with(merge_token: merge_token).and_return(fci)
|
||||
allow(fci).to receive(:valid_for_merge?).and_return(true)
|
||||
allow(fci).to receive(:email_france_connect).and_return(email)
|
||||
invalid_user.valid?
|
||||
allow(fci).to receive(:associate_user!).and_raise(ActiveRecord::RecordInvalid.new(invalid_user))
|
||||
end
|
||||
|
||||
it 'fails' do
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#confirm_email' do
|
||||
|
|
Loading…
Reference in a new issue