Skip to content

Commit

Permalink
Merge branch 'email_2fa_fix_setting_init_nil' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyranthes03 committed Feb 3, 2025
2 parents 045c6f4 + 3722de3 commit e3ad1d7
Showing 1 changed file with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,39 @@ defmodule RecognizerWeb.Accounts.UserTwoFactorController do
current_user_id = get_session(conn, :two_factor_user_id)
current_user = Accounts.get_user!(current_user_id)
current_time = System.system_time(:second)
%{notification_preference: %{two_factor: two_factor_method}} = Accounts.load_notification_preferences(current_user)

conn =
if get_session(conn, :two_factor_issue_time) == nil do
conn
|> put_session(:two_factor_issue_time, current_time)
else
conn
end
current_user = Accounts.load_notification_preferences(current_user)
case current_user do
{:error, _} ->
conn.redirect(to: Routes.user_session_path(conn, :new))
{:error, _} ->
conn.redirect(to: Routes.user_session_path(conn, :new))
{:ok, current_user} ->
%{notification_preference: %{two_factor: two_factor_method}} = current_user
conn =
if get_session(conn, :two_factor_issue_time) == nil do
conn
|> put_session(:two_factor_issue_time, current_time)
else
conn
end

two_factor_sent = get_session(conn, :two_factor_sent)

conn =
if two_factor_sent == false do
conn
|> maybe_send_two_factor_notification(current_user, two_factor_method)

conn
|> put_session(:two_factor_sent, true)
|> put_session(:two_factor_issue_time, current_time)
else
conn
end

two_factor_sent = get_session(conn, :two_factor_sent)

conn =
if two_factor_sent == false do
conn
|> maybe_send_two_factor_notification(current_user, two_factor_method)

conn
|> put_session(:two_factor_sent, true)
|> put_session(:two_factor_issue_time, current_time)
else
conn
end

conn
|> render("new.html", two_factor_method: two_factor_method)
|> render("new.html", two_factor_method: two_factor_method)
end
end

@doc """
Expand Down

0 comments on commit e3ad1d7

Please sign in to comment.