<commit_before>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class InvitationsController < Devise::InvitationsController

  before_filter :check_token, :only => [:edit]

  def new
    @sent_invitations = current_user.invitations_from_me.includes(:recipient)
    render :layout => false
  end

  def create
    if !AppConfig[:open_invitations] && current_user.invites == 0
        flash[:error] = I18n.t 'invitations.create.no_more'
        redirect_to :back
        return
      end
      aspect = params[:user].delete(:aspects)
      message = params[:user].delete(:invite_messages)
      emails = params[:user][:email].to_s.gsub(/\s/, '').split(/, */)

      good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}

      if good_emails.include?(current_user.email)
        if good_emails.length == 1
          flash[:error] = I18n.t 'invitations.create.own_address'
          redirect_to :back
          return
        else
          bad_emails.push(current_user.email)
          good_emails.delete(current_user.email)
        end
      end

      good_emails.each{|e| Resque.enqueue(Job::InviteUserByEmail, current_user.id, e, aspect, message)}

      if bad_emails.any?
        flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
      else
        flash[:notice] = I18n.t('invitations.create.sent') + good_emails.join(', ')
      end

    redirect_to :back
  end

  def update
    begin
      invitation_token = params[:user][:invitation_token]
      if invitation_token.nil? || invitation_token.blank?
        raise I18n.t('invitations.check_token.not_found')
      end
      user = User.find_by_invitation_token(params[:user][:invitation_token])
      user.accept_invitation!(params[:user])
      user.seed_aspects
    rescue Exception => e #What exception is this trying to rescue?  If it is ActiveRecord::NotFound, we should say so.
      user = nil
      record = e.record
      record.errors.delete(:person)

      flash[:error] = record.errors.full_messages.join(", ")
    end
<commit_msg>InvitationsController update has an error, and our non-specific error catching is messing up knowing what our problems are<commit_after>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class InvitationsController < Devise::InvitationsController

  before_filter :check_token, :only => [:edit]

  def new
    @sent_invitations = current_user.invitations_from_me.includes(:recipient)
    render :layout => false
  end

  def create
    if !AppConfig[:open_invitations] && current_user.invites == 0
        flash[:error] = I18n.t 'invitations.create.no_more'
        redirect_to :back
        return
      end
      aspect = params[:user].delete(:aspects)
      message = params[:user].delete(:invite_messages)
      emails = params[:user][:email].to_s.gsub(/\s/, '').split(/, */)

      good_emails, bad_emails = emails.partition{|e| e.try(:match, Devise.email_regexp)}

      if good_emails.include?(current_user.email)
        if good_emails.length == 1
          flash[:error] = I18n.t 'invitations.create.own_address'
          redirect_to :back
          return
        else
          bad_emails.push(current_user.email)
          good_emails.delete(current_user.email)
        end
      end

      good_emails.each{|e| Resque.enqueue(Job::InviteUserByEmail, current_user.id, e, aspect, message)}

      if bad_emails.any?
        flash[:error] = I18n.t('invitations.create.sent') + good_emails.join(', ') + " "+ I18n.t('invitations.create.rejected') + bad_emails.join(', ')
      else
        flash[:notice] = I18n.t('invitations.create.sent') + good_emails.join(', ')
      end

    redirect_to :back
  end

  def update
    begin
      invitation_token = params[:user][:invitation_token]
      if invitation_token.nil? || invitation_token.blank?
        raise I18n.t('invitations.check_token.not_found')
      end
      user = User.find_by_invitation_token(params[:user][:invitation_token])
      user.accept_invitation!(params[:user])
      user.seed_aspects
    rescue Exception => e #What exception is this trying to rescue?  If it is ActiveRecord::NotFound, we should say so.
      raise e unless e.respond_to?(:record)
      user = nil
      record = e.record
      record.errors.delete(:person)

      flash[:error] = record.errors.full_messages.join(", ")
    end

{'fraction_non_alphanumeric': 0.11814437459353999, 'fraction_numerical': 0.008237589421200954, 'mean_word_length': 3.097690941385435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6634002', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1445, 'n_words': 305}