<commit_before>class UsersController < ApplicationController

  before_action :authenticate_user!, only: [:edit, :update, :destroy]

  def show
    @user = User.find(params[:id])
    if @user.private?
      redirect_to root_path unless current_user && @user == current_user
    end
  end

  def edit
    @user = current_user
  end

  def update
    begin
      uparams = user_params
    rescue ActionController::ParameterMissing
      uparams = {favorite_languages: []}
    end

    @user = current_user
    if @user.update_attributes(uparams)
      redirect_to @user, flash: { success: 'User successfully updated' }
    end
  end

  def destroy
    @user = current_user
    @user.destroy
    redirect_to root_url, notice: "Successfully removed your user account"
  end

  def token_delete
    @user = User.find_by(account_delete_token: params[:account_delete_token])
    if @user.nil?
      redirect_to root_url, notice: "Account could not be found. You may have already deleted it, or your GitHub username may have changed."
    end
  end

  def token_destroy
    @user = User.find_by(account_delete_token: params[:account_delete_token])
    @user.destroy
    redirect_to root_url, notice: "Successfully removed your user account"
  end

  private

    def user_params
      params.require(:user).permit(
        :private,
        :email,
        :password,<commit_msg>User can sometimes not be found in token_destroy. Fix CODETRIAGE-B9<commit_after>class UsersController < ApplicationController

  before_action :authenticate_user!, only: [:edit, :update, :destroy]

  def show
    @user = User.find(params[:id])
    if @user.private?
      redirect_to root_path unless current_user && @user == current_user
    end
  end

  def edit
    @user = current_user
  end

  def update
    begin
      uparams = user_params
    rescue ActionController::ParameterMissing
      uparams = {favorite_languages: []}
    end

    @user = current_user
    if @user.update_attributes(uparams)
      redirect_to @user, flash: { success: 'User successfully updated' }
    end
  end

  def destroy
    @user = current_user
    @user.destroy
    redirect_to root_url, notice: "Successfully removed your user account"
  end

  def token_delete
    @user = User.find_by(account_delete_token: params[:account_delete_token])
    if @user.nil?
      redirect_to root_url, notice: "Account could not be found. You may have already deleted it, or your GitHub username may have changed."
    end
  end

  def token_destroy
    @user = User.find_by!(account_delete_token: params[:account_delete_token])
    @user.destroy
    redirect_to root_url, notice: "Successfully removed your user account"
  end

  private

    def user_params
      params.require(:user).permit(
        :private,
        :email,
        :password,
{'fraction_non_alphanumeric': 0.07972828030032178, 'fraction_numerical': 0.0003575259206292456, 'mean_word_length': 3.291411042944785, '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': '5537041', 'n_tokens_mistral': 852, 'n_tokens_neox': 827, 'n_words': 242}