Skip to content

Commit

Permalink
Update email 2fa
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyranthes03 committed Jan 13, 2025
1 parent 9f085e3 commit ff68cf4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/bullhorn/emails/user_emails.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]")
|> 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})
Expand Down
6 changes: 6 additions & 0 deletions lib/bullhorn/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ff68cf4

Please sign in to comment.