<commit_before>class UsersController < Devise::SessionsController
  require 'new_user_mailer'
  
  def new_user
    if User.count == 0
      return redirect_to :init
    end
    @user = User.new
  end

  def create_user
    authorize! :edit, current_user.current_provider

    #this user might already be a member of the site, but not of this
    #provider, in which case we ought to just set up the role
    user = User.where(:email=>params[:user][:email]).first
    if not user
      user = User.new(params[:user])
      user.password = user.password_confirmation = Devise.friendly_token[0..8]
      user.save!
      NewUserMailer.new_user_email(user, user.password).deliver
    end

    Role.new(:user_id=>user.id, 
             :provider_id=>current_user.current_provider_id, 
             :admin=>params[:user][:admin]).save!

    flash[:notice] = "%s has been added and a password has been emailed" % user.email
    redirect_to provider_path(current_user.current_provider)
  end
<commit_msg>make initial user creation work better (?)<commit_after>class UsersController < Devise::SessionsController
  require 'new_user_mailer'
  
  def new
    #hooked up to sign_in
    if User.count == 0
      return redirect_to :action=>:show_init
    end
  end

  def new_user
    if User.count == 0
      return redirect_to :init
    end
    @user = User.new
  end

  def create_user
    authorize! :edit, current_user.current_provider

    #this user might already be a member of the site, but not of this
    #provider, in which case we ought to just set up the role
    user = User.where(:email=>params[:user][:email]).first
    if not user
      user = User.new(params[:user])
      user.password = user.password_confirmation = Devise.friendly_token[0..8]
      user.save!
      NewUserMailer.new_user_email(user, user.password).deliver
    end

    Role.new(:user_id=>user.id, 
             :provider_id=>current_user.current_provider_id, 
             :admin=>params[:user][:admin]).save!

    flash[:notice] = "%s has been added and a password has been emailed" % user.email
    redirect_to provider_path(current_user.current_provider)
  end

{'fraction_non_alphanumeric': 0.09570494864612512, 'fraction_numerical': 0.0032679738562091504, 'mean_word_length': 3.185546875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '5506994', 'n_tokens_mistral': 667, 'n_tokens_neox': 648, 'n_words': 180}