<commit_before>class AccountsController < ApplicationController
  filter_parameter_logging :password

  before_filter :check_ssl, :except => [:verify]
  skip_before_filter :authenticate_user, :except => %w(edit update)

  cache_sweeper :person_sweeper, :family_sweeper, :only => %w(create update)

  def show
    if params[:person_id]
      redirect_to person_account_path(params[:person_id])
    else
      redirect_to new_account_path
    end
  end

  def new
    if params[:email]
      render :action => 'new_by_email'
    elsif params[:mobile]
      render :action => 'new_by_mobile'
    elsif params[:birthday]
      render :action => 'new_by_birthday'
    elsif Setting.get(:features, :sign_up)
      @person = Person.new
    end
  end

  def create
    if params[:person] and Setting.get(:features, :sign_up) and params[:phone].blank? # phone is to catch bots (hidden field)
      if Person.find_by_email(params[:person][:email])
        params[:email] = params[:person][:email]
        create_by_email
      else
        attributes = {:can_sign_in => false, :full_access => false, :visible_to_everyone => false}
        attributes.merge! params[:person].reject { |k, v| !%w(email first_name last_name gender birthday).include?(k) }
        @person = Person.new(attributes)
        if @person.adult?
          if @person.save
            @person.family = Family.create(:name => @person.name, :last_name => @person.last_name)
            if Setting.get(:features, :sign_up_approval_email).to_s.any?
              @person.save
              Notifier.deliver_pending_sign_up(@person)
              render :text => I18n.t('accounts.pending_approval'), :layout => true
            else
              @person.update_attributes!(:can_sign_in => true, :full_access => true, :visible_to_everyone => true, :visible_on_printed_directory => true)
              params[:email] = @person.email
              create_by_email
            end
          else
            render :action => 'new'
          end
        else
          @person.errors.add_to_base(I18n.t('accounts.must_be_of_age'), :years => Setting.get(:system, :adult_age))
          render :action => 'new'
        end
      end
    elsif params[:name].to_s.any? and params[:email].to_s.any? and params[:phone].to_s.any? and params[:birthday].to_s.any? and params[:notes].to_s.any?
      create_by_birthday
    elsif params[:mobile].to_s.any? and params[:carrier].to_s.any?
      create_by_mobile
    elsif params[:email].to_s.any?
      create_by_email
    else
      flash[:warning] = I18n.t('accounts.fill_required_fields')
      render :action => 'new'
    end
  end

  private

    def create_by_email
      person = Person.find_by_email(params[:email])<commit_msg>Fix bug when displaying error message for underage users.<commit_after>class AccountsController < ApplicationController
  filter_parameter_logging :password

  before_filter :check_ssl, :except => [:verify]
  skip_before_filter :authenticate_user, :except => %w(edit update)

  cache_sweeper :person_sweeper, :family_sweeper, :only => %w(create update)

  def show
    if params[:person_id]
      redirect_to person_account_path(params[:person_id])
    else
      redirect_to new_account_path
    end
  end

  def new
    if params[:email]
      render :action => 'new_by_email'
    elsif params[:mobile]
      render :action => 'new_by_mobile'
    elsif params[:birthday]
      render :action => 'new_by_birthday'
    elsif Setting.get(:features, :sign_up)
      @person = Person.new
    end
  end

  def create
    if params[:person] and Setting.get(:features, :sign_up) and params[:phone].blank? # phone is to catch bots (hidden field)
      if Person.find_by_email(params[:person][:email])
        params[:email] = params[:person][:email]
        create_by_email
      else
        attributes = {:can_sign_in => false, :full_access => false, :visible_to_everyone => false}
        attributes.merge! params[:person].reject { |k, v| !%w(email first_name last_name gender birthday).include?(k) }
        @person = Person.new(attributes)
        if @person.adult?
          if @person.save
            @person.family = Family.create(:name => @person.name, :last_name => @person.last_name)
            if Setting.get(:features, :sign_up_approval_email).to_s.any?
              @person.save
              Notifier.deliver_pending_sign_up(@person)
              render :text => I18n.t('accounts.pending_approval'), :layout => true
            else
              @person.update_attributes!(:can_sign_in => true, :full_access => true, :visible_to_everyone => true, :visible_on_printed_directory => true)
              params[:email] = @person.email
              create_by_email
            end
          else
            render :action => 'new'
          end
        else
          @person.errors.add_to_base(I18n.t('accounts.must_be_of_age', :years => Setting.get(:system, :adult_age)))
          render :action => 'new'
        end
      end
    elsif params[:name].to_s.any? and params[:email].to_s.any? and params[:phone].to_s.any? and params[:birthday].to_s.any? and params[:notes].to_s.any?
      create_by_birthday
    elsif params[:mobile].to_s.any? and params[:carrier].to_s.any?
      create_by_mobile
    elsif params[:email].to_s.any?
      create_by_email
    else
      flash[:warning] = I18n.t('accounts.fill_required_fields')
      render :action => 'new'
    end
  end

  private

    def create_by_email
      person = Person.find_by_email(params[:email])
{'fraction_non_alphanumeric': 0.11776483436476155, 'fraction_numerical': 0.002184200946487077, 'mean_word_length': 2.9475574712643677, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, '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': '7304980', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1703, 'n_words': 355}