launch merge process if an unlinked DS account with the same email exists
This commit is contained in:
parent
f6879eba60
commit
f7299da1e7
4 changed files with 52 additions and 10 deletions
|
@ -13,16 +13,23 @@ class FranceConnect::ParticulierController < ApplicationController
|
||||||
fci = FranceConnectService.find_or_retrieve_france_connect_information(params[:code])
|
fci = FranceConnectService.find_or_retrieve_france_connect_information(params[:code])
|
||||||
|
|
||||||
if fci.user.nil?
|
if fci.user.nil?
|
||||||
fci.associate_user!(fci.email_france_connect)
|
preexisting_unlinked_user = User.find_by(email: fci.email_france_connect.downcase)
|
||||||
end
|
|
||||||
|
|
||||||
user = fci.user
|
if preexisting_unlinked_user.nil?
|
||||||
|
fci.associate_user!(fci.email_france_connect)
|
||||||
if user.can_france_connect?
|
connect_france_connect_particulier(fci.user)
|
||||||
connect_france_connect_particulier(user)
|
else
|
||||||
|
redirect_to france_connect_particulier_merge_path(fci.create_merge_token!)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
fci.destroy
|
user = fci.user
|
||||||
redirect_to new_user_session_path, alert: t('errors.messages.france_connect.forbidden_html', reset_link: new_user_password_path)
|
|
||||||
|
if user.can_france_connect?
|
||||||
|
connect_france_connect_particulier(user)
|
||||||
|
else
|
||||||
|
fci.destroy
|
||||||
|
redirect_to new_user_session_path, alert: t('errors.messages.france_connect.forbidden_html', reset_link: new_user_password_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue Rack::OAuth2::Client::Error => e
|
rescue Rack::OAuth2::Client::Error => e
|
||||||
|
@ -30,6 +37,9 @@ class FranceConnect::ParticulierController < ApplicationController
|
||||||
redirect_france_connect_error_connection
|
redirect_france_connect_error_connection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def merge
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def redirect_to_login_if_fc_aborted
|
def redirect_to_login_if_fc_aborted
|
||||||
|
|
5
app/views/france_connect/particulier/merge.html.haml
Normal file
5
app/views/france_connect/particulier/merge.html.haml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
= content_for :title, "Fusion des comptes FC et #{APPLICATION_NAME}"
|
||||||
|
|
||||||
|
.container
|
||||||
|
%h1.page-title Fusion des comptes FranceConnect et #{APPLICATION_NAME}
|
||||||
|
|
|
@ -124,6 +124,7 @@ Rails.application.routes.draw do
|
||||||
namespace :france_connect do
|
namespace :france_connect do
|
||||||
get 'particulier' => 'particulier#login'
|
get 'particulier' => 'particulier#login'
|
||||||
get 'particulier/callback' => 'particulier#callback'
|
get 'particulier/callback' => 'particulier#callback'
|
||||||
|
get 'particulier/merge/:merge_token' => 'particulier#merge', as: :particulier_merge
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :champs do
|
namespace :champs do
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
describe FranceConnect::ParticulierController, type: :controller do
|
describe FranceConnect::ParticulierController, type: :controller do
|
||||||
let(:birthdate) { '20150821' }
|
let(:birthdate) { '20150821' }
|
||||||
let(:email) { 'email_from_fc@test.com' }
|
let(:email) { 'EMAIL_from_fc@test.com' }
|
||||||
|
|
||||||
let(:user_info) do
|
let(:user_info) do
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ describe FranceConnect::ParticulierController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when france_connect_particulier_id exists in database' do
|
context 'when france_connect_particulier_id exists in database' do
|
||||||
let!(:fci) { FranceConnectInformation.create!(user_info.merge(user_id: fc_user.id)) }
|
let!(:fci) { FranceConnectInformation.create!(user_info.merge(user_id: fc_user&.id)) }
|
||||||
|
|
||||||
context 'and is linked to an user' do
|
context 'and is linked to an user' do
|
||||||
let(:fc_user) { create(:user, email: 'associated_user@a.com') }
|
let(:fc_user) { create(:user, email: 'associated_user@a.com') }
|
||||||
|
@ -81,6 +81,32 @@ describe FranceConnect::ParticulierController, type: :controller do
|
||||||
expect(flash[:alert]).to be_present
|
expect(flash[:alert]).to be_present
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'and is not linked to an user' do
|
||||||
|
let(:fc_user) { nil }
|
||||||
|
|
||||||
|
context 'and no user with the same email exists' do
|
||||||
|
it 'creates an user with the same email and log in' do
|
||||||
|
expect { subject }.to change { User.count }.by(1)
|
||||||
|
|
||||||
|
user = User.last
|
||||||
|
|
||||||
|
expect(user.email).to eq(email.downcase)
|
||||||
|
expect(controller.current_user).to eq(user)
|
||||||
|
expect(response).to redirect_to(root_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'and an user with the same email exists' do
|
||||||
|
let!(:preexisting_user) { create(:user, email: email) }
|
||||||
|
|
||||||
|
it 'redirects to the merge process' do
|
||||||
|
expect { subject }.not_to change { User.count }
|
||||||
|
|
||||||
|
expect(response).to redirect_to(france_connect_particulier_merge_path(fci.reload.merge_token))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when france_connect_particulier_id does not exist in database' do
|
context 'when france_connect_particulier_id does not exist in database' do
|
||||||
|
|
Loading…
Reference in a new issue