Scaffhold token interface
This commit is contained in:
parent
529cde4836
commit
2a406ef236
|
@ -7,6 +7,9 @@ defmodule Hostas.Denizen do
|
||||||
field :name, :string
|
field :name, :string
|
||||||
field :password, :string
|
field :password, :string
|
||||||
|
|
||||||
|
# Links entries in the "tokens" table to denizens
|
||||||
|
has_many(:tokens, Hostas.Token)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,16 +3,19 @@ defmodule Hostas.Token do
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
schema "tokens" do
|
schema "tokens" do
|
||||||
field :id, :integer
|
field :denizen_id, :integer
|
||||||
field :expires, :utc_datetime
|
field :expires, :utc_datetime
|
||||||
|
|
||||||
|
# Link tokens to denizens
|
||||||
|
belongs_to :denizens, Hostas.Denizen
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def changeset(token, attrs) do
|
def changeset(token, attrs) do
|
||||||
token
|
token
|
||||||
|> cast(attrs, [:id, :expires])
|
|> cast(attrs, [:denizen_id, :expires])
|
||||||
|> validate_required([:id, :expires])
|
|> validate_required([:denizen_id, :expires])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule HostasWeb.Auth.TokenController do
|
||||||
|
use HostasWeb, :controller
|
||||||
|
|
||||||
|
def index(_conn, _params) do
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,7 +0,0 @@
|
||||||
defmodule HostasWeb.AuthenticationController do
|
|
||||||
use HostasWeb, :controller
|
|
||||||
|
|
||||||
def join(conn, _params) do
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -23,7 +23,7 @@ defmodule HostasWeb.Router do
|
||||||
scope "/hostapi/", HostasWeb do
|
scope "/hostapi/", HostasWeb do
|
||||||
pipe_through :api
|
pipe_through :api
|
||||||
|
|
||||||
post "/auth/register", AuthenticationController, :register
|
resources "/auth/token", Auth.TokenController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Enable LiveDashboard and Swoosh mailbox preview in development
|
# Enable LiveDashboard and Swoosh mailbox preview in development
|
||||||
|
|
|
@ -3,7 +3,7 @@ defmodule Hostas.Repo.Migrations.CreateTokens do
|
||||||
|
|
||||||
def change do
|
def change do
|
||||||
create table(:tokens) do
|
create table(:tokens) do
|
||||||
add :id, :integer
|
add :denizen_id, :integer
|
||||||
add :expires, :utc_datetime
|
add :expires, :utc_datetime
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
Loading…
Reference in New Issue