frenzy/lib/frenzy_web/controllers/fervor/misc_controller.ex

38 lines
1.1 KiB
Elixir

defmodule FrenzyWeb.Fervor.MiscController do
use FrenzyWeb, :controller
alias Frenzy.{Repo, FervorClient}
plug Plug.Parsers, parsers: [:urlencoded, :multipart]
def register(conn, _params) do
%{"client_name" => client_name, "redirect_uri" => redirect_uri} = conn.body_params
website = Map.get(conn.body_params, "website")
changeset =
FervorClient.changeset(
%FervorClient{},
%{
"client_name" => client_name,
"website" => website,
"redirect_uri" => redirect_uri,
"client_id" => :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false),
"client_secret" => :crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
}
)
{:ok, client} = Repo.insert(changeset)
json(conn, FervorClient.to_fervor(client))
end
def instance(conn, _params) do
json(conn, %{
name: "Frenzy",
url: Application.get_env(:frenzy, :base_url),
version: "0.1.0",
implementation_name: "Frenzy",
implementation_version: "0.1.0"
})
end
end