<commit_before>class RegistrationsController < Devise::RegistrationsController
  skip_before_filter :check_organization, :only => [:destroy]

  respond_to :json, :only => [:create, :update, :destroy]

  def create
    if Settings.invitations
      token = params[:token]
      if token.blank?
        build_resource(strong_params)
        resource.errors.add(:base, 'You can sign up by invitation only! Invitation token is required.')
        render :action => :new
        return
      end

      invitation = Invitation.where(:email => params[:user][:email]).first
      unless invitation && invitation.token == params[:token].strip.downcase
        build_resource(strong_params)
        resource.errors.add(:base, 'Invalid invitation token.')
        render :action => :new
        return
      end
    end

    ok = false
    User.transaction do
      super
      ok = resource && resource.persisted?
      raise ActiveRecord::Rollback unless ok
      invitation.destroy if invitation
    end

    if ok
      session[:omniauth] = nil unless resource.new_record?
      flash.now[:notice] = "Signed up successfully."
    else
      flash.now[:error] = "Failed to sign up."
    end
  end

  def edit
    @authentications = current_user.authentications if current_user
    super
  end

  def destroy
    user = User.find(params[:id])
    unless user.id == current_user.id
      user.destroy
      flash[:notice] = "User #{user.username} has been deleted."
    end
    index
  end

  def lookup<commit_msg>Added json responder for user sign-up API.<commit_after>class RegistrationsController < Devise::RegistrationsController
  skip_before_filter :check_organization, :only => [:destroy]

  respond_to :json, :only => [:create, :update, :destroy]

  def create
    if Settings.invitations
      token = params[:token]
      if token.blank?
        build_resource(strong_params)
        resource.errors.add(:base, 'You can sign up by invitation only! Invitation token is required.')
        render :action => :new
        return
      end

      invitation = Invitation.where(:email => params[:user][:email]).first
      unless invitation && invitation.token == params[:token].strip.downcase
        build_resource(strong_params)
        resource.errors.add(:base, 'Invalid invitation token.')
        render :action => :new
        return
      end
    end

    ok = false
    User.transaction do
      super
      ok = resource && resource.persisted?
      raise ActiveRecord::Rollback unless ok
      invitation.destroy if invitation
    end

    respond_to do |format|
      format.html do
        if ok
          session[:omniauth] = nil unless resource.new_record?
          flash.now[:notice] = "Signed up successfully."
        else
          flash.now[:error] = "Failed to sign up."
        end
      end

      format.json { render_json_ci_response(ok, resource)}
    end
  end

  def edit
    @authentications = current_user.authentications if current_user
    super
  end

  def destroy
    user = User.find(params[:id])
    unless user.id == current_user.id
      user.destroy
      flash[:notice] = "User #{user.username} has been deleted."
    end
    index
  end

  def lookup
{'fraction_non_alphanumeric': 0.09495455969915387, 'fraction_numerical': 0.0, 'mean_word_length': 2.648, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3214626', 'n_tokens_mistral': 894, 'n_tokens_neox': 872, 'n_words': 251}