diff --git a/app/controllers/concerns/authenticator.rb b/app/controllers/concerns/authenticator.rb index 45150f52eabfd5a6665c4e4e9996edcee2230d69..88e5e3d81303462b68bb8b830540bf1b1d0c4ff8 100644 --- a/app/controllers/concerns/authenticator.rb +++ b/app/controllers/concerns/authenticator.rb @@ -85,6 +85,8 @@ module Authenticator # Check if the user exists under the same email with no social uid and that social accounts are allowed def auth_changed_to_social?(email) + return true if Rails.configuration.social_switching + Rails.configuration.loadbalanced_configuration && User.exists?(email: email, provider: @user_domain) && !allow_greenlight_accounts? diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 65d9cb28b4beaf515ab7b12b611a1c7575ced6e6..d6dbe8c0c2195e314af85ac8f90f7b1edaeaedc7 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -266,7 +266,10 @@ flash: { alert: I18n.t("registration.insecure_password") } unless User.secure_pa # Set the user's social id to the new id being passed def switch_account_to_social - user = User.find_by(email: @auth['info']['email'], provider: @user_domain) + user = User.find_by({ + email: @auth['info']['email'], + provider: Rails.configuration.loadbalanced_configuration ? @user_domain : nil + }.compact) logger.info "Switching social account for #{user.uid}" diff --git a/config/application.rb b/config/application.rb index 80ec53b5a8e31487ec5d13b1eb77e2717016ee2b..d23746fd7a09e0c9c423a20e56a7cdcf2da2d30b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -186,5 +186,7 @@ module Greenlight # Max avatar image size config.max_avatar_size = ENV['MAX_AVATAR_SIZE'].to_i.zero? ? 100_000 : ENV['MAX_AVATAR_SIZE'].to_i + + config.social_switching = ENV['SOCIAL_SWITCHING'] == "true" end end