<commit_before>class UsersController < ApplicationController
  skip_before_action :authorize, only: [:new, :create]

  before_action :set_user, only: [:update, :destroy]
  before_action :ensure_permission, only: [:update, :destroy]

  def new
    @user = User.new
    if params[:coupon].present?
      @coupon = Coupon.find_by(coupon_code: params[:coupon])
      @coupon_valid = @coupon.present? && !@coupon.redeemed
      @user.coupon_code = params[:coupon]
    end
    if !ENV['STRIPE_API_KEY'] || params[:coupon]
      @user.plan_id = Plan.find_by_stripe_id('free').id
    else
      @user.plan_id = Plan.find_by_stripe_id('trial').id
    end
  end

  def create
    @user = User.new(user_params)
    @user.update_auth_token = true
    @user.mark_as_read_confirmation = 1
    @user.hide_tagged_feeds = 1

    coupon_valid = false
    if user_params['coupon_code']
      coupon = Coupon.find_by_coupon_code(user_params['coupon_code'])
      coupon_valid = (coupon.present? && !coupon.redeemed)
    end

    if coupon_valid || !ENV['STRIPE_API_KEY']
      @user.free_ok = true
      @user.plan = Plan.find_by_stripe_id('free')
    else
      @user.plan = Plan.find_by_stripe_id('trial')
    end

    if params[:user] && params[:user][:password]
      @user.password_confirmation = params[:user][:password]
    end

    if @user.save
      if @user.plan.stripe_id != 'free'
        schedule_trial_jobs
      end
      Librato.increment('user.trial.signup')<commit_msg>Default theme settings.<commit_after>class UsersController < ApplicationController
  skip_before_action :authorize, only: [:new, :create]

  before_action :set_user, only: [:update, :destroy]
  before_action :ensure_permission, only: [:update, :destroy]

  def new
    @user = User.new
    if params[:coupon].present?
      @coupon = Coupon.find_by(coupon_code: params[:coupon])
      @coupon_valid = @coupon.present? && !@coupon.redeemed
      @user.coupon_code = params[:coupon]
    end
    if !ENV['STRIPE_API_KEY'] || params[:coupon]
      @user.plan_id = Plan.find_by_stripe_id('free').id
    else
      @user.plan_id = Plan.find_by_stripe_id('trial').id
    end
  end

  def create
    @user = User.new(user_params)
    @user.update_auth_token = true
    @user.mark_as_read_confirmation = 1
    @user.hide_tagged_feeds = 1
    @user.theme = "sunset"
    @user.font = "serif-2"
    @user.font_size = 7

    coupon_valid = false
    if user_params['coupon_code']
      coupon = Coupon.find_by_coupon_code(user_params['coupon_code'])
      coupon_valid = (coupon.present? && !coupon.redeemed)
    end

    if coupon_valid || !ENV['STRIPE_API_KEY']
      @user.free_ok = true
      @user.plan = Plan.find_by_stripe_id('free')
    else
      @user.plan = Plan.find_by_stripe_id('trial')
    end

    if params[:user] && params[:user][:password]
      @user.password_confirmation = params[:user][:password]
    end

    if @user.save
      if @user.plan.stripe_id != 'free'
        schedule_trial_jobs
      end
      Librato.increment('user.trial.signup')
{'fraction_non_alphanumeric': 0.12863756613756613, 'fraction_numerical': 0.001984126984126984, 'mean_word_length': 3.403202328966521, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5697391', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1105, 'n_words': 183}