From ff1952085acd0b039683a67642bda3f56ac93e6e Mon Sep 17 00:00:00 2001 From: Dean Lofts Date: Sat, 24 Aug 2024 18:34:37 +1000 Subject: [PATCH 1/2] fix --- .../users/registrations_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index f965ca6..f771772 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -34,15 +34,23 @@ def edit def update @user = current_user @user.tags = JSON.parse(@user.tags) if @user.tags.is_a?(String) - - if params[:user][:password].present? || params[:user][:password_confirmation].present? + + # Check if password or email is being updated + password_or_email_update = params[:user][:password].present? || + params[:user][:email] != @user.email + + if password_or_email_update successfully_updated = @user.update_with_password(account_update_params) else + # Remove password keys from params + params[:user].delete(:password) + params[:user].delete(:password_confirmation) params[:user].delete(:current_password) - successfully_updated = @user.update_without_password(account_update_params.except(:current_password)) + successfully_updated = @user.update(account_update_params) end - + if successfully_updated + bypass_sign_in(@user) # Sign in the user bypassing validation redirect_to edit_user_registration_path, notice: 'Profile updated successfully' else render :edit From 5c882e411f0ef933470191bd2c4c339b07054457 Mon Sep 17 00:00:00 2001 From: Dean Lofts Date: Sat, 24 Aug 2024 18:47:28 +1000 Subject: [PATCH 2/2] fix --- .../users/registrations_controller.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index f771772..4061792 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -34,21 +34,14 @@ def edit def update @user = current_user @user.tags = JSON.parse(@user.tags) if @user.tags.is_a?(String) - - # Check if password or email is being updated - password_or_email_update = params[:user][:password].present? || - params[:user][:email] != @user.email - - if password_or_email_update + + if params[:user][:password].present? || params[:user][:password_confirmation].present? successfully_updated = @user.update_with_password(account_update_params) else - # Remove password keys from params - params[:user].delete(:password) - params[:user].delete(:password_confirmation) params[:user].delete(:current_password) - successfully_updated = @user.update(account_update_params) + successfully_updated = @user.update_without_password(account_update_params.except(:current_password)) end - + if successfully_updated bypass_sign_in(@user) # Sign in the user bypassing validation redirect_to edit_user_registration_path, notice: 'Profile updated successfully' @@ -79,4 +72,4 @@ def account_update_params end end end -end +end \ No newline at end of file