defmodule DrainCloudCore.Auth.Users do use Ecto.Schema import Ecto.Changeset import Ecto.Query alias DrainCloudCore.Repo, as: Repo schema "users" do field :login, :string field :password, :string, redact: true field :created_at, :utc_datetime field :updated_at, :utc_datetime field :deleted_at, :utc_datetime end def changeset(user, params \\ %{}) do user |> cast(params, [:id, :login, :password, :updated_at, :deleted_at]) |> validate_required([:id]) end def add_user(user) do Repo.insert(user) end def password_by_login(login) do Repo.all(from u in "users", where: u.login == ^login, select: u.password, limit: 1) end end