Scaffhold token interface

This commit is contained in:
Nat 2023-06-06 09:38:52 -07:00
parent 529cde4836
commit 2a406ef236
Signed by: nat
GPG Key ID: B53AB05285D710D6
6 changed files with 18 additions and 12 deletions

View File

@ -7,6 +7,9 @@ defmodule Hostas.Denizen do
field :name, :string
field :password, :string
# Links entries in the "tokens" table to denizens
has_many(:tokens, Hostas.Token)
timestamps()
end

View File

@ -3,16 +3,19 @@ defmodule Hostas.Token do
import Ecto.Changeset
schema "tokens" do
field :id, :integer
field :denizen_id, :integer
field :expires, :utc_datetime
# Link tokens to denizens
belongs_to :denizens, Hostas.Denizen
timestamps()
end
@doc false
def changeset(token, attrs) do
token
|> cast(attrs, [:id, :expires])
|> validate_required([:id, :expires])
|> cast(attrs, [:denizen_id, :expires])
|> validate_required([:denizen_id, :expires])
end
end

View File

@ -0,0 +1,7 @@
defmodule HostasWeb.Auth.TokenController do
use HostasWeb, :controller
def index(_conn, _params) do
:ok
end
end

View File

@ -1,7 +0,0 @@
defmodule HostasWeb.AuthenticationController do
use HostasWeb, :controller
def join(conn, _params) do
:ok
end
end

View File

@ -23,7 +23,7 @@ defmodule HostasWeb.Router do
scope "/hostapi/", HostasWeb do
pipe_through :api
post "/auth/register", AuthenticationController, :register
resources "/auth/token", Auth.TokenController
end
# Enable LiveDashboard and Swoosh mailbox preview in development

View File

@ -3,7 +3,7 @@ defmodule Hostas.Repo.Migrations.CreateTokens do
def change do
create table(:tokens) do
add :id, :integer
add :denizen_id, :integer
add :expires, :utc_datetime
timestamps()