Skip to content

Commit

Permalink
Merge branch 'ah/backup-codes' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-s76 committed Mar 4, 2024
2 parents 9046565 + c423e72 commit 9bb1a1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,22 @@ defmodule RecognizerWeb.Accounts.UserSettingsController do

def review(conn, _params) do
user = Authentication.fetch_current_user(conn)
{:ok, %{recovery_codes: recovery_codes}} = Accounts.get_new_two_factor_settings(user)

recovery_block =
recovery_codes
|> Enum.map(& &1.code)
|> Enum.map(& &1 <> "\n")
case Accounts.get_new_two_factor_settings(user) do
{:ok, %{recovery_codes: recovery_codes}} ->
recovery_block =
recovery_codes
|> Enum.map(& &1.code)
|> Enum.map(&(&1 <> "\n"))

conn
|> render("recovery_codes.html", recovery_block: recovery_block)
conn
|> render("recovery_codes.html", recovery_block: recovery_block)

_ ->
conn
|> put_flash(:error, "Two factor setup not yet initiated")
|> redirect(to: Routes.user_settings_path(conn, :edit))
end
end

defp assign_email_and_password_changesets(conn, _opts) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,18 @@ defmodule RecognizerWeb.Accounts.UserSettingsControllerTest do
assert response =~ "must not contain special characters"
end
end

describe "GET /users/settings/two-factor/review (backup codes)" do
test "gets review page after 2fa setup", %{conn: conn, user: user} do
Recognizer.Accounts.generate_and_cache_new_two_factor_settings(user, "app")
conn = get(conn, Routes.user_settings_path(conn, :review))
_response = html_response(conn, 200)
end

test "review 2fa without setup is ?", %{conn: conn} do
conn = get(conn, Routes.user_settings_path(conn, :review))
_response = html_response(conn, 302)
assert get_flash(conn, :error) == "Two factor setup not yet initiated"
end
end
end

0 comments on commit 9bb1a1a

Please sign in to comment.