<commit_before>class UsersController < ApplicationController
  
  before_filter :guests_only!, only: [ :new, :create ]
  before_filter :users_only!, only: [ :edit, :update, :destroy ]
  
  layout 'users'
  
  def show
    @user = current_user
    if @user.nil?
      not_found
    end
  end

  def new
    @user = User.new
  end
  
  def create
    @user = User.new params[:user]
    if @user.save
      redirect_to users_url, notice: 'Your account has been created.'
    else
      flash[:error] = 'Your account could not be created.'
      render :new
    end
  end

  def edit
    @user = current_user
  end
  
  def update
    @user = current_user
    params[:user].delete('password') if params[:user]['password'].empty?
    if @user.update_attributes params[:user]
      redirect_to user_url(@user.username), notice: 'Your account has been updated.'
    else
      flash[:error] = 'Your account could not be updated.'
      render :edit
    end
  end
  
  def destroy
    @user = current_user
    if @user.destroy
      redirect_to root_url, notice: 'Your account has been destroyed. Goodbye.'
    else
      flash[:error] = 'Your account could not be destroyed. Sorry.'
      render :edit
    end
  end
  
end<commit_msg>Redirects user to root on account update (fixes #6)<commit_after>class UsersController < ApplicationController
  
  before_filter :guests_only!, only: [ :new, :create ]
  before_filter :users_only!, only: [ :edit, :update, :destroy ]
  
  layout 'users'
  
  def show
    @user = current_user
    if @user.nil?
      not_found
    end
  end

  def new
    @user = User.new
  end
  
  def create
    @user = User.new params[:user]
    if @user.save
      redirect_to users_url, notice: 'Your account has been created.'
    else
      flash[:error] = 'Your account could not be created.'
      render :new
    end
  end

  def edit
    @user = current_user
  end
  
  def update
    @user = current_user
    params[:user].delete('password') if params[:user]['password'].empty?
    if @user.update_attributes params[:user]
      redirect_to root_url, notice: 'Your account has been updated. If you changed your password, you need to log in again with your new password.'
    else
      flash[:error] = 'Your account could not be updated.'
      render :edit
    end
  end
  
  def destroy
    @user = current_user
    if @user.destroy
      redirect_to root_url, notice: 'Your account has been destroyed. Goodbye.'
    else
      flash[:error] = 'Your account could not be destroyed. Sorry.'
      render :edit
    end
  end
  
end
{'fraction_non_alphanumeric': 0.09197651663405088, 'fraction_numerical': 0.0003913894324853229, 'mean_word_length': 2.6724137931034484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3933943', 'n_tokens_mistral': 785, 'n_tokens_neox': 775, 'n_words': 264}