<commit_before>class ProblemsController < ApplicationController
	before_action :logged_in_user, only: [:index, :show]
	before_action :admin_user, only: [:destroy, :create, :index, :show, :edit, :update, :new]
	
	def index
		@problems = Problem.paginate(page: params[:page])
	end

	def show
		@problem = Problem.find(params[:id])
	end

	def new
		@problem = Problem.new
	end

	def create
		@problem = Problem.new(problem_params)
		if @problem.save
      redirect_to problems_url
		else
			render 'new'
		end
	end

	def destroy
    Problem.find(params[:id]).destroy
    flash[:success] = "Problem deleted"
    redirect_to problems_url
  end

	def edit
		@problem = Problem.find(params[:id])
	end

	def update
		@problem = Problem.find(params[:id])
		if @problem.update_attributes(problem_params)
			flash[:success] = "Changes saved successfully"
			redirect_to @problem
		else
			render 'edit'
		end
	end

	private
		def problem_params
			params.require(:problem).permit(:name, :category, :description, :points)
		end

		def logged_in_user
			unless logged_in?
				store_location
				flash[:danger] = "Please log in."
				redirect_to login_url
			end
		end
		
		def admin_user
      unless logged_in? && current_user.admin?
				store_location
				flash[:danger] = "Access Denied."
				redirect_to login_url
			end
    end
end<commit_msg>Redirects non-admins to root and non-logged in to login<commit_after>class ProblemsController < ApplicationController
	before_action :logged_in_user, only: [:index, :show, :destroy, :create, :index, :show, :edit, :update, :new]
	before_action :admin_user, only: [:destroy, :create, :index, :show, :edit, :update, :new]
	
	def index
		@problems = Problem.paginate(page: params[:page])
	end

	def show
		@problem = Problem.find(params[:id])
	end

	def new
		@problem = Problem.new
	end

	def create
		@problem = Problem.new(problem_params)
		if @problem.save
      redirect_to problems_url
		else
			render 'new'
		end
	end

	def destroy
    Problem.find(params[:id]).destroy
    flash[:success] = "Problem deleted"
    redirect_to problems_url
  end

	def edit
		@problem = Problem.find(params[:id])
	end

	def update
		@problem = Problem.find(params[:id])
		if @problem.update_attributes(problem_params)
			flash[:success] = "Changes saved successfully"
			redirect_to @problem
		else
			render 'edit'
		end
	end

	private
		def problem_params
			params.require(:problem).permit(:name, :category, :description, :points)
		end

		def logged_in_user
			unless logged_in?
				store_location
				flash[:danger] = "Please log in."
				redirect_to login_url
			end
		end
		
		def admin_user
      unless logged_in? && current_user.admin?
				store_location
				flash[:danger] = "Access Denied."
				redirect_to root_url
			end
    end
end
{'fraction_non_alphanumeric': 0.1033610408384532, 'fraction_numerical': 0.0, 'mean_word_length': 3.7889273356401385, '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': '1543865', 'n_tokens_mistral': 1064, 'n_tokens_neox': 898, 'n_words': 240}