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

38 lines
1.1 KiB
Elixir
Raw Normal View History

2019-03-31 14:52:56 +00:00
defmodule FrenzyWeb.Fervor.MiscController do
2019-03-28 21:11:25 +00:00
use FrenzyWeb, :controller
2019-03-31 14:52:56 +00:00
alias Frenzy.{Repo, FervorClient}
2019-03-28 21:11:25 +00:00
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
2019-03-31 14:52:56 +00:00
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
2019-03-28 21:11:25 +00:00
end