FC ParticulierController: callback syntax cleaning

This commit is contained in:
simon lehericey 2018-01-11 16:00:14 +01:00 committed by Simon Lehericey
parent 4294c8eec7
commit e68fc0811f

View file

@ -4,13 +4,16 @@ 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)
if france_connect_information.nil?
france_connect_information = FranceConnectInformation.create(
{gender: user_infos[:gender],
given_name: user_infos[:given_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