2021-08-14 13:20:42 +00:00
|
|
|
defmodule MatrixServerWeb.Client.Request.Login do
|
2021-06-27 15:28:28 +00:00
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
embedded_schema do
|
|
|
|
field :type, :string
|
|
|
|
field :password, :string
|
|
|
|
field :device_id, :string
|
|
|
|
field :initial_device_display_name, :string
|
2021-07-13 15:08:07 +00:00
|
|
|
|
|
|
|
embeds_one :identifier, Identifier, primary_key: false do
|
|
|
|
field :type, :string
|
|
|
|
field :user, :string
|
|
|
|
end
|
2021-06-27 15:28:28 +00:00
|
|
|
end
|
|
|
|
|
2021-07-10 21:16:00 +00:00
|
|
|
def changeset(params) do
|
2021-06-27 15:28:28 +00:00
|
|
|
%__MODULE__{}
|
2021-07-10 21:16:00 +00:00
|
|
|
|> cast(params, [:type, :password, :device_id, :initial_device_display_name])
|
2021-07-13 15:08:07 +00:00
|
|
|
|> cast_embed(:identifier, with: &identifier_changeset/2, required: true)
|
2021-06-27 15:28:28 +00:00
|
|
|
|> validate_required([:type, :password])
|
|
|
|
end
|
2021-07-13 15:08:07 +00:00
|
|
|
|
|
|
|
def identifier_changeset(identifier, params) do
|
|
|
|
identifier
|
|
|
|
|> cast(params, [:type, :user])
|
|
|
|
|> validate_required([:type, :user])
|
|
|
|
end
|
2021-06-27 15:28:28 +00:00
|
|
|
end
|