This repository has been archived on 2026-05-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
vishnya/lib/vishnya/accounts/user.ex
2026-02-17 03:56:54 +01:00

26 lines
690 B
Elixir

defmodule Vishnya.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
schema "users" do
field :username, :string
field :password_hash, :string
field :user_id, :string
field :token, :string
timestamps()
end
@doc false
def changeset(user, attrs) do
user
|> cast(attrs, [:username, :password_hash, :user_id, :token])
|> validate_required([:username, :password_hash, :user_id, :token])
|> validate_length(:username, max: 12)
|> validate_format(:username, ~r/^[a-z0-9]+$/, message: "must be lowercase letters and numbers")
|> unique_constraint(:username)
|> unique_constraint(:user_id)
|> unique_constraint(:token)
end
end