2024-09-08 12:35:20 +00:00
|
|
|
defmodule DrainCloudCore.Auth.Users do
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2024-09-17 21:13:39 +00:00
|
|
|
import Ecto.Query
|
|
|
|
|
|
|
|
alias DrainCloudCore.Repo, as: Repo
|
2024-09-08 12:35:20 +00:00
|
|
|
|
|
|
|
schema "users" do
|
|
|
|
field :login, :string
|
2024-09-08 22:16:48 +00:00
|
|
|
field :password, :string, redact: true
|
|
|
|
field :created_at, :utc_datetime
|
2024-09-08 12:35:20 +00:00
|
|
|
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
|
2024-09-17 21:13:39 +00:00
|
|
|
|
|
|
|
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
|
2024-09-08 12:35:20 +00:00
|
|
|
end
|