Add check password to connect with france connect particulier whereas a TPS account have the same email adresse
This commit is contained in:
parent
02b7680083
commit
4961f39a71
5 changed files with 86 additions and 3 deletions
|
@ -14,6 +14,8 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
return redirect_to root_path if france_connect_particulier_id_blank?
|
||||
|
||||
@user = (User.new create_user_params).decorate
|
||||
end
|
||||
|
||||
|
@ -30,6 +32,24 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
connect_france_connect_particulier user
|
||||
end
|
||||
|
||||
def check_email
|
||||
return create if User.find_by_email(params[:user][:email]).nil?
|
||||
return redirect_to root_path if france_connect_particulier_id_blank?
|
||||
|
||||
unless params[:user][:password].nil?
|
||||
user = User.find_by_email(params[:user][:email])
|
||||
valid_password = user.valid_password?(params[:user][:password])
|
||||
|
||||
if valid_password
|
||||
user.update_attributes create_user_params
|
||||
return connect_france_connect_particulier user
|
||||
else
|
||||
flash.now.alert = 'Mot de passe invalide'
|
||||
end
|
||||
end
|
||||
@user = (User.new create_user_params).decorate
|
||||
end
|
||||
|
||||
def callback
|
||||
return redirect_to new_user_session_path unless params.has_key?(:code)
|
||||
|
||||
|
@ -56,6 +76,10 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
params.require(:user).permit(:france_connect_particulier_id, :gender, :given_name, :family_name, :birthdate, :birthplace, :email)
|
||||
end
|
||||
|
||||
def france_connect_particulier_id_blank?
|
||||
redirect_to root_path if params[:user][:france_connect_particulier_id].blank?
|
||||
end
|
||||
|
||||
def connect_france_connect_particulier user
|
||||
sign_in user
|
||||
|
||||
|
|
28
app/views/france_connect/particulier/check_email.html.haml
Normal file
28
app/views/france_connect/particulier/check_email.html.haml
Normal file
|
@ -0,0 +1,28 @@
|
|||
%h2.text-info
|
||||
= image_tag('logo_FC_02_small.png', style: 'height: 55px')
|
||||
France Connect - Particulier
|
||||
|
||||
%h3 Nouvelle connexion
|
||||
%h4.text-warning{style:'margin-left: 20px'} Email déjà utilisé
|
||||
|
||||
%br
|
||||
%p
|
||||
%h4.center Nous vous avons trouvé un compte qui utilise déjà cette adresse email.
|
||||
%p.center
|
||||
Afin d'associer ce compte à votre identifiant France Connect, merci de saisir votre mot de passe TPS.
|
||||
%br
|
||||
.center
|
||||
#france_connect_particulier_email
|
||||
= form_for @user, url: {controller: 'france_connect/particulier', action: :check_email}, method: :post do |f|
|
||||
.form-group.form-group-lg
|
||||
= f.text_field :email, class: "form-control", placeholder: "Entrez votre email", readonly: 'readonly'
|
||||
%br
|
||||
= f.password_field :password, class: "form-control", placeholder: "Entrez votre mot de passe"
|
||||
= f.hidden_field :email
|
||||
= f.hidden_field :gender
|
||||
= f.hidden_field :given_name
|
||||
= f.hidden_field :family_name
|
||||
= f.hidden_field :birthdate
|
||||
= f.hidden_field :birthplace
|
||||
= f.hidden_field :france_connect_particulier_id
|
||||
= f.submit 'Terminer', class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', id: 'valid_new_fcp'
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
.center
|
||||
#france_connect_particulier_email
|
||||
= form_for @user, url: {controller: 'france_connect/particulier', action: :create}, method: :post do |f|
|
||||
= form_for @user, url: {controller: 'france_connect/particulier', action: :check_email}, method: :post do |f|
|
||||
.form-group.form-group-lg
|
||||
= f.text_field :email, class: "form-control", placeholder: "Entrez votre email"
|
||||
= f.hidden_field :gender
|
||||
|
|
|
@ -24,6 +24,7 @@ Rails.application.routes.draw do
|
|||
|
||||
get 'particulier/new' => 'particulier#new'
|
||||
post 'particulier/create' => 'particulier#create'
|
||||
post 'particulier/check_email' => 'particulier#check_email'
|
||||
end
|
||||
|
||||
get 'demo' => 'demo#index'
|
||||
|
@ -44,7 +45,6 @@ Rails.application.routes.draw do
|
|||
post '/carte' => 'carte#save'
|
||||
|
||||
put '/archive' => 'dossiers#archive'
|
||||
|
||||
end
|
||||
resource :dossiers
|
||||
end
|
||||
|
|
|
@ -9,8 +9,9 @@ describe FranceConnect::ParticulierController, type: :controller do
|
|||
let(:birthplace) { '1234' }
|
||||
let(:france_connect_particulier_id) { 'blabla' }
|
||||
let(:email) { '' }
|
||||
let(:password) { '' }
|
||||
|
||||
let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email: email) }
|
||||
let(:user_info) { Hashie::Mash.new(france_connect_particulier_id: france_connect_particulier_id, given_name: given_name, family_name: family_name, birthdate: birthdate, birthplace: birthplace, gender: gender, email: email, password: password) }
|
||||
|
||||
describe '.login' do
|
||||
it 'redirect to france connect serveur' do
|
||||
|
@ -104,4 +105,34 @@ describe FranceConnect::ParticulierController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #check_email' do
|
||||
let(:email) { 'plop@gmail.com' }
|
||||
let(:password) { 'blabla141415' }
|
||||
|
||||
subject { post :check_email, user: user_info }
|
||||
|
||||
context 'when email is linked at an existant user' do
|
||||
context 'when email and password couple is valid' do
|
||||
let!(:user) { create(:user, email: email, password: password) }
|
||||
|
||||
it { expect { subject }.to change { user.reload.france_connect_particulier_id } }
|
||||
it { is_expected.to redirect_to root_path }
|
||||
end
|
||||
|
||||
context 'when email and password couple is not valid' do
|
||||
let!(:user) { create(:user, email: email, password: 'plop12345678') }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when email is not used' do
|
||||
it { expect { subject }.to change { User.count }.by(1) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue