Skip to content

Commit f9f22cf

Browse files
feat: add two-factor view helpers and locale strings
Add two_factor_method_links helper to DeviseHelper for rendering switch links between 2FA methods. Add locale strings for session expired, sign-in not initiated, and password reset 2FA required.
1 parent 7bc147d commit f9f22cf

4 files changed

Lines changed: 12 additions & 0 deletions

File tree

app/helpers/devise_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
# Keeping the helper around for backward compatibility.
44
module DeviseHelper
5+
def two_factor_method_links(resource, current_method)
6+
methods = resource.enabled_two_factors - [current_method]
7+
safe_join(methods.map { |method| render "devise/two_factor/#{method}_link" })
8+
end
59
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<%= form_tag(two_factor_path(resource_name), method: :post) do %>
2+
<%= text_field_tag :otp_attempt %>
3+
<%= submit_tag "Verify" %>
4+
<% end %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= link_to "Use OTP instead", new_two_factor_challenge_path(resource_name, :test_otp) %>

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ en:
1616
timeout: "Your session expired. Please sign in again to continue."
1717
unauthenticated: "You need to sign in or sign up before continuing."
1818
unconfirmed: "You have to confirm your email address before continuing."
19+
two_factor_session_expired: "Your two-factor authentication session has expired. Please sign in again."
20+
sign_in_not_initiated: "Please sign in first."
1921
mailer:
2022
confirmation_instructions:
2123
subject: "Confirmation instructions"
@@ -36,6 +38,7 @@ en:
3638
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
3739
updated: "Your password has been changed successfully. You are now signed in."
3840
updated_not_active: "Your password has been changed successfully."
41+
updated_two_factor_required: "Your password has been changed successfully. Please complete two-factor authentication."
3942
registrations:
4043
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
4144
signed_up: "Welcome! You have signed up successfully."

0 commit comments

Comments
 (0)