<commit_before>class UsersController < ApplicationController

  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(user_params)

    if @user.save
      flash[:success] = "Successfully registered!"
      session[:user_id] = @user.id
      redirect_to @user
    else
      render 'new'
    end
  end

  def edit
    @user = User.find(params[:id])
  end

  def update
    @user = User.find(params[:id])
    if @user.update(user_params)
      flash[:success] = "User info updated successfully"
      redirect_to @user
    else
      render 'edit'
      flash[:error] = "user info was not updated"
    end
  end

  def destroy
    @user = User.find(params[:id])
    @user.destroy
    flash[:success] = "account successfully terminated"
    redirect_to products_path
  end

  private
  def user_params
    params.require(:user).permit(:username, :email, :password)
  end
end<commit_msg>add private method check_user to prevent users from deleting others' accounts<commit_after>class UsersController < ApplicationController

  def show
    @user = User.find(params[:id])
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(user_params)

    if @user.save
      flash[:success] = "Successfully registered!"
      session[:user_id] = @user.id
      redirect_to @user
    else
      render 'new'
    end
  end

  def edit
    @user = User.find(params[:id])
  end

  def update
    @user = User.find(params[:id])
    if @user.update(user_params)
      flash[:success] = "User info updated successfully"
      redirect_to @user
    else
      render 'edit'
      flash[:error] = "user info was not updated"
    end
  end

  def destroy
    @user = User.find(params[:id])
    @user.destroy
    flash[:success] = "account successfully terminated"
    redirect_to products_path
  end

  private

  def check_user
    unless current_user == User.find(params[:id])
      flash[:danger] = "That is not your account"
      redirect_to '/'
  end
  def user_params
    params.require(:user).permit(:username, :email, :password)
  end
end
{'fraction_non_alphanumeric': 0.10396975425330812, 'fraction_numerical': 0.0, 'mean_word_length': 2.8075539568345325, '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': '2544001', 'n_tokens_mistral': 674, 'n_tokens_neox': 652, 'n_words': 182}