Implement login endpoint
This commit is contained in:
parent
7c73c2c424
commit
5fe604c5a2
6 changed files with 148 additions and 21 deletions
42
lib/matrix_server_web/api/login.ex
Normal file
42
lib/matrix_server_web/api/login.ex
Normal file
|
@ -0,0 +1,42 @@
|
|||
# https://gist.github.com/char0n/6fca76e886a2cfbd3aaa05526f287728
|
||||
defmodule MatrixServerWeb.API.Login do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
defmodule MatrixServerWeb.API.Login.Identifier do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field :type, :string
|
||||
field :user, :string
|
||||
end
|
||||
|
||||
def changeset(identifier, attrs) do
|
||||
identifier
|
||||
|> cast(attrs, [:type, :user])
|
||||
|> validate_required([:type, :user])
|
||||
end
|
||||
end
|
||||
|
||||
alias MatrixServerWeb.API.Login.Identifier
|
||||
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field :type, :string
|
||||
field :password, :string
|
||||
field :device_id, :string
|
||||
field :initial_device_display_name, :string
|
||||
embeds_one :identifier, Identifier
|
||||
end
|
||||
|
||||
def changeset(attrs) do
|
||||
%__MODULE__{}
|
||||
|> cast(attrs, [:type, :password, :device_id, :initial_device_display_name])
|
||||
|> cast_embed(:identifier, with: &Identifier.changeset/2, required: true)
|
||||
|> validate_required([:type, :password])
|
||||
end
|
||||
end
|
|
@ -4,9 +4,9 @@ defmodule MatrixServerWeb.API.Register do
|
|||
import Ecto.Changeset
|
||||
import MatrixServerWeb.Plug.Error
|
||||
|
||||
alias __MODULE__
|
||||
alias Ecto.Changeset
|
||||
|
||||
@primary_key false
|
||||
embedded_schema do
|
||||
field :device_id, :string
|
||||
field :initial_device_display_name, :string
|
||||
|
@ -16,7 +16,7 @@ defmodule MatrixServerWeb.API.Register do
|
|||
end
|
||||
|
||||
def changeset(params) do
|
||||
%Register{}
|
||||
%__MODULE__{}
|
||||
|> cast(params, [
|
||||
:device_id,
|
||||
:initial_device_display_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue