comfycamp/lib/comfycamp_web/controllers/oidc_app_controller.ex

76 lines
2 KiB
Elixir

defmodule ComfycampWeb.OIDCAppController do
use ComfycampWeb, :controller
alias Comfycamp.SSO
alias Comfycamp.SSO.OIDCApp
def index(conn, _params) do
oidc_apps = SSO.list_oidc_apps()
conn
|> put_layout(html: :admin)
|> render(:index, oidc_apps: oidc_apps)
end
def new(conn, _params) do
changeset = SSO.change_oidc_app(%OIDCApp{})
conn
|> put_layout(html: :admin)
|> render(:new, changeset: changeset)
end
def create(conn, %{"oidc_app" => oidc_app_params}) do
case SSO.create_oidc_app(oidc_app_params) do
{:ok, oidc_app} ->
conn
|> put_flash(:info, "Oidc app created successfully.")
|> redirect(to: ~p"/admin/oidc_apps/#{oidc_app}")
{:error, %Ecto.Changeset{} = changeset} ->
conn
|> put_layout(html: :admin)
|> render(:new, changeset: changeset)
end
end
def show(conn, %{"id" => client_id}) do
oidc_app = SSO.get_oidc_app!(client_id)
conn
|> put_layout(html: :admin)
|> render(:show, oidc_app: oidc_app)
end
def edit(conn, %{"id" => client_id}) do
oidc_app = SSO.get_oidc_app!(client_id)
changeset = SSO.change_oidc_app(oidc_app)
conn
|> put_layout(html: :admin)
|> render(:edit, oidc_app: oidc_app, changeset: changeset)
end
def update(conn, %{"id" => client_id, "oidc_app" => oidc_app_params}) do
oidc_app = SSO.get_oidc_app!(client_id)
case SSO.update_oidc_app(oidc_app, oidc_app_params) do
{:ok, oidc_app} ->
conn
|> put_flash(:info, "Oidc app updated successfully.")
|> redirect(to: ~p"/admin/oidc_apps/#{oidc_app}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :edit, oidc_app: oidc_app, changeset: changeset)
end
end
def delete(conn, %{"id" => client_id}) do
oidc_app = SSO.get_oidc_app!(client_id)
{:ok, _oidc_app} = SSO.delete_oidc_app(oidc_app)
conn
|> put_flash(:info, "Oidc app deleted successfully.")
|> redirect(to: ~p"/admin/oidc_apps")
end
end