From b65f10847a821123b2e8b2ede486f01cf58d3519 Mon Sep 17 00:00:00 2001 From: compwron Date: Sun, 12 Jan 2025 20:38:51 -0800 Subject: [PATCH 1/3] use dig --- app/controllers/users/passwords_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index 69fd45c5ba..7f844eaf99 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -4,7 +4,7 @@ class Users::PasswordsController < Devise::PasswordsController include SmsBodyHelper def create - @email = params[resource_name][:email] + @email = params.dig(resource_name, :email) @phone_number = params[resource_name][:phone_number] @resource = @email.blank? ? User.find_by(phone_number: @phone_number) : User.find_by(email: @email) From cbd423969f2bdcf7d0317fde39b621165e89460e Mon Sep 17 00:00:00 2001 From: compwron Date: Sun, 12 Jan 2025 20:51:22 -0800 Subject: [PATCH 2/3] more nil checking --- app/controllers/users/passwords_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index 7f844eaf99..17def2abb2 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -5,13 +5,13 @@ class Users::PasswordsController < Devise::PasswordsController def create @email = params.dig(resource_name, :email) - @phone_number = params[resource_name][:phone_number] - @resource = @email.blank? ? User.find_by(phone_number: @phone_number) : User.find_by(email: @email) + @phone_number = params.dig(resource_name, :phone_number) unless valid_params?(@email, @phone_number) render_error return if @errors end + @resource = @email.blank? ? User.find_by(phone_number: @phone_number) : User.find_by(email: @email) send_password redirect_to after_sending_reset_password_instructions_path_for(resource_name), From 704133c2f0e7abed14f6fb767724ec33071447d7 Mon Sep 17 00:00:00 2001 From: compwron Date: Sun, 12 Jan 2025 21:23:03 -0800 Subject: [PATCH 3/3] fix --- app/controllers/users/passwords_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/passwords_controller.rb b/app/controllers/users/passwords_controller.rb index 17def2abb2..31655cdd59 100644 --- a/app/controllers/users/passwords_controller.rb +++ b/app/controllers/users/passwords_controller.rb @@ -6,12 +6,12 @@ class Users::PasswordsController < Devise::PasswordsController def create @email = params.dig(resource_name, :email) @phone_number = params.dig(resource_name, :phone_number) + @resource = @email.blank? ? User.find_by(phone_number: @phone_number) : User.find_by(email: @email) unless valid_params?(@email, @phone_number) render_error return if @errors end - @resource = @email.blank? ? User.find_by(phone_number: @phone_number) : User.find_by(email: @email) send_password redirect_to after_sending_reset_password_instructions_path_for(resource_name),