<commit_before>class EventsController < ApplicationController
  include Gultalks::Commentable
  # helper_method :event, :events
  respond_to :html, :json, :xml

  def new
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end
  end

  def new_basic
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    @form = BasicEventForm.new(Event.new)
  end

  def create_basic
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    event = Event.new
    event.conference_id = @conference.id
    # Event verification is disabled by default
    event.shown = true
    event.verified = true

    @form = BasicEventForm.new(event)
    if @form.validate(params[:basic_event]) && verify_recaptcha
      @form.save
      render "thanks"
    else
      render :new_basic
    end
  end

  def new_detailed
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    event = Event.new
    5.times { event.speakers.build }

    @form = DetailedEventForm.new(event)
  end

  def create_detailed
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    event = Event.new
    event.conference_id = @conference.id
    5.times { event.speakers.build }

    @form = DetailedEventForm.new(event)

    total_speakers = 0
    params[:detailed_event]["speakers_attributes"].each do |key, sp|
      if sp["name"].present?
        total_speakers += 1
      end
    end

    if @form.validate(params[:detailed_event]) && total_speakers > 0 && total_speakers < 6 && verify_recaptcha
      @form.save do |nested|
        # Save event and tags
        new_event = Event.new(nested.except("speakers"))
        new_event.conference_id = @conference.id
        # Event verification is disabled by default
        new_event.shown = true
        new_event.verified = true<commit_msg>Only check for a maximum of 5 speakers (prevent DoS)<commit_after>class EventsController < ApplicationController
  include Gultalks::Commentable
  # helper_method :event, :events
  respond_to :html, :json, :xml

  def new
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end
  end

  def new_basic
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    @form = BasicEventForm.new(Event.new)
  end

  def create_basic
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    event = Event.new
    event.conference_id = @conference.id
    # Event verification is disabled by default
    event.shown = true
    event.verified = true

    @form = BasicEventForm.new(event)
    if @form.validate(params[:basic_event]) && verify_recaptcha
      @form.save
      render "thanks"
    else
      render :new_basic
    end
  end

  def new_detailed
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    event = Event.new
    5.times { event.speakers.build }

    @form = DetailedEventForm.new(event)
  end

  def create_detailed
    @conference = Conference.friendly.find(params[:conference_id])
    if !@conference.call_for_papers_enabled
      redirect_to conference_path(@conference)
    end

    event = Event.new
    event.conference_id = @conference.id
    5.times { event.speakers.build }

    @form = DetailedEventForm.new(event)

    total_speakers = 0
    5.times do |i|
      if params[:detailed_event]["speakers_attributes"]["#{i}"]["name"].present?
        total_speakers += 1
      end
    end

    if @form.validate(params[:detailed_event]) && total_speakers > 0 && total_speakers < 6 && verify_recaptcha
      @form.save do |nested|
        # Save event and tags
        new_event = Event.new(nested.except("speakers"))
        new_event.conference_id = @conference.id
        # Event verification is disabled by default
        new_event.shown = true
        new_event.verified = true
{'fraction_non_alphanumeric': 0.0926839733962669, 'fraction_numerical': 0.003003647285990131, 'mean_word_length': 3.3610851262862487, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4721844', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1415, 'n_words': 293}