Skip to content

Commit

Permalink
Implement verification flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Archer committed Aug 25, 2023
1 parent 223c753 commit 2e7bc08
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2 class="font-semibold text-xl">
<h2 class="font-semibold text-xl">
<%= gettext("Settings") %>
</h2>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h2 class="font-semibold text-xl">
<%= gettext("Verify") %>
</h2>

<ExampleWeb.Flow.flow flow={@flow} />
1 change: 1 addition & 0 deletions elixir-ory-network/lib/example_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defmodule ExampleWeb.Router do
pipe_through [:browser]

get "/settings", AccountController, :settings
get "/verify", AccountController, :verify
end

# Other scopes may use custom stacks.
Expand Down

0 comments on commit 2e7bc08

Please sign in to comment.