Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
loftwah committed Aug 24, 2024
1 parent 1f7814a commit ff19520
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff19520

Please sign in to comment.