<commit_before>defmodule Leather.User do
  @moduledoc "The User model for Leather."

  alias Leather.User
  import Ecto.Changeset
  use Ecto.Schema

  schema "users" do
    field :password, :string, virtual: true
    field :password_hash, :string
    field :email, :string
    timestamps()
    has_many :accounts, Leather.Account
  end

  @doc false
  def changeset(%User{} = user, attrs \\ :invalid) do
    user
    |> cast(attrs, [:email])
    |> validate_length(:email, min: 1, max: 20)
  end


  @doc false
  def registration_changeset(%User{} = user, attrs \\ :invalid) do
    user
    |> changeset(attrs)
    |> cast(attrs, [:password])
    |> validate_format(:email, ~r/@/)
    |> validate_length(:password, min: 6, max: 100)
    |> validate_confirmation(:password)
    |> unique_constraint(:email)
    |> put_pass_hash()
  end


  defp put_pass_hash(changeset) do
    case changeset do
      %Ecto.Changeset{valid?: true, changes: %{password: <PASSWORD>}} ->
        put_change changeset, :password_hash, <PASSWORD>(<PASSWORD>)

      _ ->
        changeset
    end
  end<commit_msg>Validate email length.<commit_after>defmodule Leather.User do
  @moduledoc "The User model for Leather."

  alias Leather.User
  import Ecto.Changeset
  use Ecto.Schema

  schema "users" do
    field :password, :string, virtual: true
    field :password_hash, :string
    field :email, :string
    timestamps()
    has_many :accounts, Leather.Account
  end

  @doc false
  def changeset(%User{} = user, attrs \\ :invalid) do
    user
    |> cast(attrs, [:email])
    |> validate_length(:email, min: 5, max: 100)
  end


  @doc false
  def registration_changeset(%User{} = user, attrs \\ :invalid) do
    user
    |> changeset(attrs)
    |> cast(attrs, [:password])
    |> validate_format(:email, ~r/@/)
    |> validate_length(:password, min: 6, max: 100)
    |> validate_confirmation(:password)
    |> unique_constraint(:email)
    |> put_pass_hash()
  end


  defp put_pass_hash(changeset) do
    case changeset do
      %Ecto.Changeset{valid?: true, changes: %{password: pass}} ->
        put_change changeset, :password_hash, Comeonin.Bcrypt.hashpwsalt(pass)

      _ ->
        changeset
    end
  end
{'fraction_non_alphanumeric': 0.127959927140255, 'fraction_numerical': 0.006830601092896175, 'mean_word_length': 3.2088122605363987, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 28, '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': '5424937', 'n_tokens_mistral': 772, 'n_tokens_neox': 719, 'n_words': 185}