Skip to content

Commit

Permalink
implement initial account settings flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Archer committed Aug 25, 2023
1 parent 05efa59 commit d9f764b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule ExampleWeb.AccountHTML do
use ExampleWeb, :html

embed_templates "account_html/*"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h2 class="font-semibold text-xl">
<%= gettext("Settings") %>
</h2>

<ExampleWeb.Flow.flow flow={@flow} />

<.button>
<:inner_block>
<.link navigate={@logout_url} class="text-white text-sm font-semibold leading-6">
<span>Log out</span>
</.link>
</:inner_block>
</.button>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-zinc-900">
Successfully logged in. Hello <%= @session.identity.traits["email"] %>!
</p>

<.link navigate={~p"/account/settings"} class="text-sm font-semibold leading-6">
<p class="text-xl mt-4 leading-10 tracking-tighter text-blue-800">
Go to account settings ->
</p>
</.link>
<% else %>
<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-zinc-900">
Peace of mind from prototype to production.
Expand Down Expand Up @@ -85,12 +91,6 @@
</.link>
</:inner_block>
</.button>
<% else %>
<.button>
<:inner_block>
<%= Phoenix.HTML.Link.link("Log out", to: @logout_url) %>
</:inner_block>
</.button>
<% end %>
</div>
</div>
7 changes: 6 additions & 1 deletion elixir-ory-network/lib/example_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ defmodule ExampleWeb.Router do
pipe_through(:browser)

get("/", PageController, :home)

end

scope "/auth", ExampleWeb do
Expand All @@ -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
Expand Down

0 comments on commit d9f764b

Please sign in to comment.