diff --git a/elixir-ory-network/lib/example_web/controllers/account_controller.ex b/elixir-ory-network/lib/example_web/controllers/account_controller.ex index efab545..3391f30 100644 --- a/elixir-ory-network/lib/example_web/controllers/account_controller.ex +++ b/elixir-ory-network/lib/example_web/controllers/account_controller.ex @@ -5,6 +5,64 @@ defmodule ExampleWeb.AccountController do alias Ory.Api.Frontend + @doc """ + Verify page from flow parameters with optional code pre-filling + """ + + def verify(conn, %{"flow" => flow, "code" => code}) do + case Frontend.get_verification_flow(Ory.Connection.new(), flow, cookie: cookies(conn)) do + {:ok, %Ory.Model.VerificationFlow{} = flow} -> + render(conn, :verify, flow: flow) + + {:ok, %Ory.Model.ErrorGeneric{} = error} -> + IO.inspect(error) + render(conn, :verify, flow: nil) + + _ -> + IO.puts("oops") + end + end + + def verify(conn, %{"flow" => id}) do + case Frontend.get_verification_flow(Ory.Connection.new(), id, cookie: cookies(conn)) do + {:ok, %Ory.Model.VerificationFlow{} = flow} -> + render(conn, :verify, flow: flow) + + {:ok, %Ory.Model.ErrorGeneric{}} -> + render(conn, :verify, flow: nil) + + _ -> + IO.puts("oops") + end + end + + def verify(%{assigns: %{session: session}} = conn, %{return_to: return_to}) do + IO.inspect(session) + + {:ok, %{url: url}} = + Frontend.create_browser_verification_flow(Ory.Connection.new(), return_to: return_to) + + redirect(conn, external: url) + end + + def verify(%{assigns: %{session: session}} = conn, _params) do + IO.inspect(session) + + # TODO(@tobbbles): Check for verified session(s) + + {:ok, %{url: url}} = Frontend.create_browser_verification_flow(Ory.Connection.new()) + redirect(conn, external: url) + end + + # Redirect on no-session + def verify(conn, _params) do + redirect(conn, to: ~p"/account/settings") + end + + @doc """ + Settings controller + """ + def settings(conn, %{"flow" => id}) do {:ok, %Ory.Model.LogoutFlow{logout_url: logout_url}} = Frontend.create_browser_logout_flow(Ory.Connection.new(), cookie: cookies(conn)) diff --git a/elixir-ory-network/lib/example_web/controllers/account_html/settings.html.heex b/elixir-ory-network/lib/example_web/controllers/account_html/settings.html.heex index 72353e7..cc4aa58 100644 --- a/elixir-ory-network/lib/example_web/controllers/account_html/settings.html.heex +++ b/elixir-ory-network/lib/example_web/controllers/account_html/settings.html.heex @@ -1,4 +1,4 @@ -