From e68fc0811f1a7875cecb07108511c0b0c7d31126 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Jan 2018 16:00:14 +0100 Subject: [PATCH] FC ParticulierController: callback syntax cleaning --- .../france_connect/particulier_controller.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/france_connect/particulier_controller.rb b/app/controllers/france_connect/particulier_controller.rb index 271bfe89a..451149820 100644 --- a/app/controllers/france_connect/particulier_controller.rb +++ b/app/controllers/france_connect/particulier_controller.rb @@ -4,14 +4,17 @@ class FranceConnect::ParticulierController < ApplicationController end def callback - return redirect_to new_user_session_path if !params.has_key?(:code) + if params[:code].nil? + return redirect_to new_user_session_path + end user_infos = FranceConnectService.retrieve_user_informations_particulier(params[:code]) if user_infos.present? - france_connect_information = FranceConnectInformation.find_by_france_connect_particulier user_infos + france_connect_information = FranceConnectInformation.find_by_france_connect_particulier(user_infos) - france_connect_information = FranceConnectInformation.create( + if france_connect_information.nil? + france_connect_information = FranceConnectInformation.create( {gender: user_infos[:gender], given_name: user_infos[:given_name], family_name: user_infos[:family_name], @@ -19,14 +22,17 @@ class FranceConnect::ParticulierController < ApplicationController birthdate: user_infos[:birthdate], birthplace: user_infos[:birthplace], france_connect_particulier_id: user_infos[:france_connect_particulier_id]} - ) if france_connect_information.nil? + ) + end user = france_connect_information.user salt = FranceConnectSaltService.new(france_connect_information).salt - return redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) if user.nil? + if user.nil? + return redirect_to france_connect_particulier_new_path(fci_id: france_connect_information.id, salt: salt) + end - connect_france_connect_particulier user + connect_france_connect_particulier(user) end rescue Rack::OAuth2::Client::Error => e Rails.logger.error e.message