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