From d9f764b29ca50e7467ee541b213ae6817bbefcd0 Mon Sep 17 00:00:00 2001 From: Toby Archer Date: Fri, 25 Aug 2023 16:11:26 +0200 Subject: [PATCH] implement initial account settings flow --- .../controllers/account_controller.ex | 25 +++++++++++++++++++ .../example_web/controllers/account_html.ex | 5 ++++ .../account_html/settings.html.heex | 13 ++++++++++ .../account_html/verification.html.heex | 1 + .../controllers/page_html/home.html.heex | 12 ++++----- elixir-ory-network/lib/example_web/router.ex | 7 +++++- 6 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 elixir-ory-network/lib/example_web/controllers/account_controller.ex create mode 100644 elixir-ory-network/lib/example_web/controllers/account_html.ex create mode 100644 elixir-ory-network/lib/example_web/controllers/account_html/settings.html.heex create mode 100644 elixir-ory-network/lib/example_web/controllers/account_html/verification.html.heex diff --git a/elixir-ory-network/lib/example_web/controllers/account_controller.ex b/elixir-ory-network/lib/example_web/controllers/account_controller.ex new file mode 100644 index 00000000..efab545d --- /dev/null +++ b/elixir-ory-network/lib/example_web/controllers/account_controller.ex @@ -0,0 +1,25 @@ +defmodule ExampleWeb.AccountController do + use ExampleWeb, :controller + + import ExampleWeb.Helpers, only: [cookies: 1] + + alias Ory.Api.Frontend + + 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)) + + {:ok, settings_flow} = + Frontend.get_settings_flow(Ory.Connection.new(), id, Cookie: cookies(conn)) + + IO.inspect(settings_flow) + render(conn, :settings, flow: settings_flow, logout_url: logout_url) + end + + def settings(conn, _params) do + {:ok, %{url: url} = settings_flow} = + Frontend.create_browser_settings_flow(Ory.Connection.new(), Cookie: cookies(conn)) + + redirect(conn, external: url) + end +end diff --git a/elixir-ory-network/lib/example_web/controllers/account_html.ex b/elixir-ory-network/lib/example_web/controllers/account_html.ex new file mode 100644 index 00000000..1ead375e --- /dev/null +++ b/elixir-ory-network/lib/example_web/controllers/account_html.ex @@ -0,0 +1,5 @@ +defmodule ExampleWeb.AccountHTML do + use ExampleWeb, :html + + embed_templates "account_html/*" +end 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 new file mode 100644 index 00000000..72353e75 --- /dev/null +++ b/elixir-ory-network/lib/example_web/controllers/account_html/settings.html.heex @@ -0,0 +1,13 @@ +

+ <%= gettext("Settings") %> +

+ + + +<.button> + <:inner_block> + <.link navigate={@logout_url} class="text-white text-sm font-semibold leading-6"> + Log out + + + diff --git a/elixir-ory-network/lib/example_web/controllers/account_html/verification.html.heex b/elixir-ory-network/lib/example_web/controllers/account_html/verification.html.heex new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/elixir-ory-network/lib/example_web/controllers/account_html/verification.html.heex @@ -0,0 +1 @@ + diff --git a/elixir-ory-network/lib/example_web/controllers/page_html/home.html.heex b/elixir-ory-network/lib/example_web/controllers/page_html/home.html.heex index d6d7ec1f..e3fbd00d 100644 --- a/elixir-ory-network/lib/example_web/controllers/page_html/home.html.heex +++ b/elixir-ory-network/lib/example_web/controllers/page_html/home.html.heex @@ -56,6 +56,12 @@

Successfully logged in. Hello <%= @session.identity.traits["email"] %>!

+ + <.link navigate={~p"/account/settings"} class="text-sm font-semibold leading-6"> +

+ Go to account settings -> +

+ <% else %>

Peace of mind from prototype to production. @@ -85,12 +91,6 @@ - <% else %> - <.button> - <:inner_block> - <%= Phoenix.HTML.Link.link("Log out", to: @logout_url) %> - - <% end %> diff --git a/elixir-ory-network/lib/example_web/router.ex b/elixir-ory-network/lib/example_web/router.ex index 76dc8014..e801695f 100644 --- a/elixir-ory-network/lib/example_web/router.ex +++ b/elixir-ory-network/lib/example_web/router.ex @@ -20,7 +20,6 @@ defmodule ExampleWeb.Router do pipe_through(:browser) get("/", PageController, :home) - end scope "/auth", ExampleWeb do @@ -30,6 +29,12 @@ defmodule ExampleWeb.Router do get "/register", AuthController, :registration end + scope "/account", ExampleWeb do + pipe_through [:browser] + + get "/settings", AccountController, :settings + end + # Other scopes may use custom stacks. # scope "/api", ExampleWeb do # pipe_through :api