frenzy/lib/frenzy_web/controllers/fervor_controller.ex

31 lines
959 B
Elixir

defmodule FrenzyWeb.FervorController do
use FrenzyWeb, :controller
alias Frenzy.{Repo, FervorClient, Group, Feed, Filter, Item}
alias FrenzyWeb.Router.Helpers, as: Routes
alias FrenzyWeb.Endpoint
import Ecto.Query
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
end