<commit_before>class GrownupsController < ApplicationController
  before_action :set_grownup, only: [:show, :edit, :update, :destroy]

  def login
    redirect_to '/'
  end

  def index
    @grownups = Grownup.all
  end

  def show
  end

  def new
    @parent = Grownup.new
    @kid = Kid.new
    @hide_menu = true
  end

  def edit
  end

  def create
    #"grownup"=>{"fname"=>"wefefw", "lname"=>"wfwef", "email"=>"wefwef", "dob(1i)"=>"1999", "dob(2i)"=>"2", "dob(3i)"=>"5"}
    c = Customer.find_by_email(params[:grownup][:email])
    if c
      flash[:notice] = 'Please just login with that email.'
      redirect_to '/sessions/new'
      return
    end

    flp = params[:grownup][:fname] #first last parent
    ptokens = flp.split(' ')
    flk = params[:grownup][:lname] #first last kid
    ktokens = flk.split(' ')

    c = Customer.create(fname: ptokens.first, lname: ptokens[1..-1].join(' '), email: params[:grownup][:email], dob: 18.years.ago)

    etokens = c.email.split('@')
    momdadplus = "#{etokens.first}+#{rand(999999999999)}@#{etokens.last}"

    dob=Date.parse(params[:grownup]['dob(1i)']+'-'+ params[:grownup]['dob(2i)'] + '-'+ params[:grownup]['dob(3i)'])
    kid=Kid.create(email: momdadplus, dob: dob, fname: ktokens.first, lname: ktokens[1..-1].join(' '))
    KidGrownup.create(kid_id: kid.id, grownup_id: c.id)

    session[:person_id] = c.id
    redirect_to '/'
  end

  def update
    respond_to do |format|
      if @grownup.update(grownup_params)
        format.html { redirect_to @grownup, notice: 'Grownup was successfully updated.' }
        format.json { render :show, status: :ok, location: @grownup }
      else
        format.html { render :edit }
        format.json { render json: @grownup.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /grownups/1
  # DELETE /grownups/1.json
  def destroy
    @grownup.destroy
    respond_to do |format|
      format.html { redirect_to grownups_url, notice: 'Grownup was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private<commit_msg>sort of helps with #6 but needs more work<commit_after>class GrownupsController < ApplicationController
  before_action :set_grownup, only: [:show, :edit, :update, :destroy]

  def login
    redirect_to '/'
  end

  def index
    @grownups = Grownup.all
  end

  def show
  end

  def new
    @parent = Grownup.new
    @kid = Kid.new
    @hide_menu = true
  end

  def edit
  end

  def create
    #"grownup"=>{"fname"=>"wefefw", "lname"=>"wfwef", "email"=>"wefwef", "dob(1i)"=>"1999", "dob(2i)"=>"2", "dob(3i)"=>"5"}
    c = Customer.find_by_email(params[:grownup][:email])
    if c
      flash[:notice] = 'Please just login with that email.'
      redirect_to '/sessions/new'
      return
    end

    flp = params[:grownup][:fname] #first last parent
    ptokens = flp.split(' ')
    flk = params[:grownup][:lname] #first last kid
    ktokens = flk.split(' ')

    c = Customer.create(fname: ptokens.first, lname: ptokens[1..-1].join(' '), email: params[:grownup][:email], dob: 18.years.ago)

    etokens = c.email.split('@')
    momdadplus = "#{etokens.first}+#{rand(999999999999)}@#{etokens.last}"

    dob=Date.parse(params[:grownup]['dob(1i)']+'-'+ params[:grownup]['dob(2i)'] + '-'+ params[:grownup]['dob(3i)'])
    kid=Kid.create(email: momdadplus, dob: dob, fname: ktokens.first, lname: ktokens[1..-1].join(' '))
    KidGrownup.create(kid_id: kid.id, grownup_id: c.id)

    session[:person_id] = c.id
    redirect_to '/'
  rescue
    flash[:notice] = 'Please check what you entered and try again.'
    redirect_to '/grownups/new'
  end

  def update
    respond_to do |format|
      if @grownup.update(grownup_params)
        format.html { redirect_to @grownup, notice: 'Grownup was successfully updated.' }
        format.json { render :show, status: :ok, location: @grownup }
      else
        format.html { render :edit }
        format.json { render json: @grownup.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /grownups/1
  # DELETE /grownups/1.json
  def destroy
    @grownup.destroy
    respond_to do |format|
      format.html { redirect_to grownups_url, notice: 'Grownup was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
{'fraction_non_alphanumeric': 0.15606801770323783, 'fraction_numerical': 0.015140927090612625, 'mean_word_length': 3.2472799208704255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '3816543', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1553, 'n_words': 343}