<commit_before>class SubmissionsController < ApplicationController
	before_action :user_logged_in, only: [:create, :new]
	before_action :belong_to_team, only: [:index]
	before_action :competition_active, only: [:create, :new]

	def new
	end

	def create
		correct = false
		points = 0
		solution = params[:submission][:value]
		@problem = Problem.find(params[:submission][:id])

		# If the solution is correct
		if solution == @problem.solution
			correct = true

			# And it has not already been solved
			if @problem.solved_by?(current_user.team_id)
				flash[:warning] = "Your team has already solved this!"
				redirect_to problems_path
			else
				flash[:success] = @problem.correct_message
				points = @problem.points
				redirect_to problems_path
			end

		# Or the answer has already been guessed
		elsif ( Submission.find_by(team_id: current_user.team_id,
														 	submission: solution) )
			flash[:warning] = "Your team has already guessed that!"
			redirect_to @problem
		else
			flash[:danger] = @problem.false_message
			redirect_to @problem
		end
		Submission.create(team_id:  current_user.team_id,
					 						user_id: current_user.id,
					 						problem_id: @problem.id,
					 						submission: solution,
					 						correct: correct,
					 						points:	points)
	end

	private
		def competition_active
			start_time = Time.parse(Setting.find_by(name: 'start_time').value)
			end_time = Time.parse(Setting.find_by(name: 'end_time').value)

			unless (start_time < Time.zone.now && Time.zone.now < end_time)
				flash[:danger] = "The competition isn't active!"
				redirect_to root_url
			end
		end

		def belong_to_team
			unless current_user.team_id
				flash[:danger] = "You cannot solve problems unless you belong to a team!"
				redirect_to @problem
			end
		end

		def user_logged_in
			unless logged_in?
				store_location
				flash[:danger] = "Please log in."
				redirect_to login_url
			end
		end
		

end<commit_msg>bugfix: redirecting to problems page on submit<commit_after>class SubmissionsController < ApplicationController
	before_action :user_logged_in, only: [:create, :new]
	before_action :belong_to_team, only: [:index]
	before_action :competition_active, only: [:create, :new]

	def new
	end

	def create
		correct = false
		points = 0
		solution = params[:submission][:value]
		@problem = Problem.find(params[:submission][:id])

		# If the solution is correct
		if solution == @problem.solution
			correct = true

			# And it has not already been solved
			if @problem.solved_by?(current_user.team_id)
				flash[:warning] = "Your team has already solved this!"
				redirect_to controller: 'problems', action: 'index', problem_id: @problem.id
			else
				flash[:success] = @problem.correct_message
				points = @problem.points
				redirect_to controller: 'problems', action: 'index', problem_id: @problem.id
			end

		# Or the answer has already been guessed
		elsif ( Submission.find_by(team_id: current_user.team_id,
														 	submission: solution) )
			flash[:warning] = "Your team has already guessed that!"
			redirect_to controller: 'problems', action: 'index', problem_id: @problem.id
		else
			flash[:danger] = @problem.false_message
			redirect_to controller: 'problems', action: 'index', problem_id: @problem.id
		end
		Submission.create(team_id:  current_user.team_id,
					 						user_id: current_user.id,
					 						problem_id: @problem.id,
					 						submission: solution,
					 						correct: correct,
					 						points:	points)
	end

	private
		def competition_active
			start_time = Time.parse(Setting.find_by(name: 'start_time').value)
			end_time = Time.parse(Setting.find_by(name: 'end_time').value)

			unless (start_time < Time.zone.now && Time.zone.now < end_time)
				flash[:danger] = "The competition isn't active!"
				redirect_to root_url
			end
		end

		def belong_to_team
			unless current_user.team_id
				flash[:danger] = "You cannot solve problems unless you belong to a team!"
				redirect_to @problem
			redirect_to controller: 'problems', action: 'index', problem_id: @problem.id
			end
		end

		def user_logged_in
			unless logged_in?
				store_location
				flash[:danger] = "Please log in."
				redirect_to login_url
			end
		end
		

end
{'fraction_non_alphanumeric': 0.09557605867045185, 'fraction_numerical': 0.0004731488052992666, 'mean_word_length': 3.5658747300215983, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2388520', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1331, 'n_words': 358}