From 1fbd1d11c423b54469191f3aa8f83b45752f85b2 Mon Sep 17 00:00:00 2001 From: Milan Cvetkovic Date: Mon, 6 Nov 2023 18:05:30 +0000 Subject: [PATCH] Extract `welcome_options` function to simplify save function --- app/controllers/users_controller.rb | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ad569a3de..0b7f6ec91 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -197,20 +197,6 @@ class UsersController < ApplicationController flash[:matomo_goal] = Settings.matomo["goals"]["signup"] if defined?(Settings.matomo) - uri = URI(session[:referer]) if session[:referer].present? - welcome_options = {} - welcome_options["oauth_return_url"] = uri&.to_s if uri&.path == oauth_authorization_path - - begin - %r{map=(.*)/(.*)/(.*)}.match(uri.fragment) do |m| - editor = Rack::Utils.parse_query(uri.query).slice("editor") - welcome_options = { "zoom" => m[1], - "lat" => m[2], - "lon" => m[3] }.merge(editor).merge(welcome_options) - end - rescue StandardError - # Use default - end referer = welcome_path(welcome_options) if current_user.status == "active" @@ -323,6 +309,24 @@ class UsersController < ApplicationController private + def welcome_options + uri = URI(session[:referer]) if session[:referer].present? + welcome_options = {} + welcome_options["oauth_return_url"] = uri&.to_s if uri&.path == oauth_authorization_path + + begin + %r{map=(.*)/(.*)/(.*)}.match(uri.fragment) do |m| + editor = Rack::Utils.parse_query(uri.query).slice("editor") + welcome_options = { "zoom" => m[1], + "lat" => m[2], + "lon" => m[3] }.merge(editor).merge(welcome_options) + end + rescue StandardError + # Use default + end + welcome_options + end + ## # ensure that there is a "user" instance variable def lookup_user_by_name -- 2.39.5