diff --git a/lib/bullhorn/emails/user_emails.ex b/lib/bullhorn/emails/user_emails.ex index 5213679..c006c77 100644 --- a/lib/bullhorn/emails/user_emails.ex +++ b/lib/bullhorn/emails/user_emails.ex @@ -42,6 +42,23 @@ defmodule Bullhorn.Emails.UserEmails do |> MailgunHelper.substitute_variables("first_name", first_name) end + def deliver_email_two_factor_token(%{email: email, first_name: first_name} = user, token) do + spaced_out_token = + token + |> String.upcase() + |> String.split("") + |> Enum.join(". ") + + new_email() + |> to({full_name(user), email}) + |> from("no-reply@system76.com") + |> subject("Your System76 verification code") + |> MailgunHelper.template("deliver_email_two_factor_token") + |> MailgunHelper.substitute_variables("first_name", first_name) + |> MailgunHelper.substitute_variables("two_factor_token", spaced_out_token) + end + + def recovery_code_used(%{email: email, first_name: first_name} = user, used_code, codes_remaining) do new_email() |> to({full_name(user), email}) diff --git a/lib/bullhorn/users.ex b/lib/bullhorn/users.ex index ee1fcc4..9f0234a 100644 --- a/lib/bullhorn/users.ex +++ b/lib/bullhorn/users.ex @@ -43,6 +43,12 @@ defmodule Bullhorn.Users do Twilio.deliver_voice_two_factor_token(user, token) end + def two_factor_requested(%TwoFactorRequested{token: token, user: user, method: :TWO_FACTOR_METHOD_EMAIL}) do + user + |> UserEmails.deliver_email_two_factor_token(user, token) + |> send_user_email() + end + def recovery_code_used(%TwoFactorRecoveryCodeUsed{codes_remaining: remaining, recovery_code: used_code, user: user}) do user |> UserEmails.recovery_code_used(used_code, remaining)