<commit_before># frozen_string_literal: true

class RegistrationsController < Devise::RegistrationsController
  permits :username, :email, :password, model_name: "User"

  def new
    @user = User.new_with_session({}, session)
  end

  def create(user)
    @user = User.new(user).build_relations
    @user.time_zone = cookies["ann_time_zone"].presence || "Asia/Tokyo"
    @user.locale = locale

    return render(:new) unless @user.valid?

    ActiveRecord::Base.transaction do
      @user.save!
      ga_client.user = @user
      ga_client.events.create(:users, :create)
      keen_client.publish(
        "create_users",
        user: @user,
        via: "web",
        via_oauth: false
      )
    end

    bypass_sign_in(@user)

    flash[:notice] = t("messages.registrations.create.confirmation_mail_has_sent")
    redirect_to after_sign_in_path_for(@user)
  end
end<commit_msg>Display error messages when users can’t sign up<commit_after># frozen_string_literal: true

class RegistrationsController < Devise::RegistrationsController
  permits :username, :email, :password, model_name: "User"

  def new
    @new_user = User.new_with_session({}, session)
  end

  def create(user)
    @new_user = User.new(user).build_relations
    @new_user.time_zone = cookies["ann_time_zone"].presence || "Asia/Tokyo"
    @new_user.locale = locale

    return render(:new) unless @new_user.valid?

    ActiveRecord::Base.transaction do
      @new_user.save!
      ga_client.user = @new_user
      ga_client.events.create(:users, :create)
      keen_client.publish(
        "create_users",
        user: @new_user,
        via: "web",
        via_oauth: false
      )
    end

    bypass_sign_in(@new_user)

    flash[:notice] = t("messages.registrations.create.confirmation_mail_has_sent")
    redirect_to after_sign_in_path_for(@new_user)
  end
end
{'fraction_non_alphanumeric': 0.11141304347826086, 'fraction_numerical': 0.0, 'mean_word_length': 3.5569306930693068, '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': '4218522', 'n_tokens_mistral': 616, 'n_tokens_neox': 601, 'n_words': 114}