<commit_before>##
# Customized version of Devise::InvitationsController.
# It has been customized to better work with AJAX requests.

class Devise::FriendInvitationsController < Devise::InvitationsController

  respond_to :json, only: [:create]
  respond_to :html, only: [:edit, :update, :destroy]

  prepend_before_filter :authenticate_inviter!, :only => [:create]
  prepend_before_filter :has_invitations_left?, :only => [:create]
  prepend_before_filter :require_no_authentication, :only => [:edit, :update, :destroy]
  prepend_before_filter :resource_from_invitation_token, :only => [:edit, :destroy]
  helper_method :after_sign_in_path_for

  ##
  # Send an invitation email to the passed email address.
  def create
    # TODO after beta stage remove this to allow anyone to invite friends
    if !current_user.admin
      head status: 403
      return
    end

    # Create record for the invited user
    @invited_user = invite_user
    # If the created user is invalid, this will raise an error
    @invited_user.save!
    Rails.logger.info "User #{current_user.id} - #{current_user.email} sent invitation to join Feedbunch to user #{@invited_user.id} - #{@invited_user.email}"
    head status: :ok
  rescue => e
    handle_error e
  end

  # GET /resource/invitation/accept?invitation_token=abcdef
  def edit
    resource.invitation_token = params[:invitation_token]
    render :edit
  end

  # PUT /resource/invitation
  def update
    self.resource = accept_resource

    if resource.errors.empty?
      yield resource if block_given?
      flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
      set_flash_message :notice, flash_message
      sign_in(resource_name, resource)
      respond_with resource, :location => after_accept_path_for(resource)<commit_msg>Finish the change started in e9f960b72b56e72844fd27bab412a6f77c9a4ce8<commit_after>##
# Customized version of Devise::InvitationsController.
# It has been customized to better work with AJAX requests.

class Devise::FriendInvitationsController < Devise::InvitationsController

  respond_to :json, only: [:create]
  respond_to :html, only: [:edit, :update, :destroy]

  prepend_before_filter :authenticate_inviter!, :only => [:create]
  prepend_before_filter :has_invitations_left?, :only => [:create]
  prepend_before_filter :require_no_authentication, :only => [:edit, :update, :destroy]
  prepend_before_filter :resource_from_invitation_token, :only => [:edit, :destroy]
  helper_method :after_sign_in_path_for

  ##
  # Send an invitation email to the passed email address.
  def create
    # TODO after beta stage remove this to allow anyone to invite friends
    if !current_inviter.admin
      head status: 403
      return
    end

    # Create record for the invited user
    @invited_user = invite_user
    # If the created user is invalid, this will raise an error
    @invited_user.save!
    Rails.logger.info "User #{current_inviter.id} - #{current_inviter.email} sent invitation to join Feedbunch to user #{@invited_user.id} - #{@invited_user.email}"
    head status: :ok
  rescue => e
    handle_error e
  end

  # GET /resource/invitation/accept?invitation_token=abcdef
  def edit
    resource.invitation_token = params[:invitation_token]
    render :edit
  end

  # PUT /resource/invitation
  def update
    self.resource = accept_resource

    if resource.errors.empty?
      yield resource if block_given?
      flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
      set_flash_message :notice, flash_message
      sign_in(resource_name, resource)
      respond_with resource, :location => after_accept_path_for(resource)
{'fraction_non_alphanumeric': 0.0847135487374423, 'fraction_numerical': 0.008145533532446375, 'mean_word_length': 4.370262390670554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '5008329', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1107, 'n_words': 312}