rails_authentication 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -7
  3. data/lib/generators/authentication/authentication_generator.rb +70 -8
  4. data/lib/generators/authentication/features/confirmable.rb +5 -5
  5. data/lib/generators/authentication/features/invitable.rb +5 -5
  6. data/lib/generators/authentication/features/lockable.rb +5 -5
  7. data/lib/generators/authentication/features/magic_link.rb +5 -5
  8. data/lib/generators/authentication/features/ott.rb +5 -5
  9. data/lib/generators/authentication/features/recoverable.rb +8 -6
  10. data/lib/generators/authentication/features/rememberable.rb +8 -3
  11. data/lib/generators/authentication/templates/app/controllers/concerns/authentication.rb.tt +61 -14
  12. data/lib/generators/authentication/templates/app/controllers/confirmations_controller.rb.tt +9 -5
  13. data/lib/generators/authentication/templates/app/controllers/invitations_controller.rb.tt +13 -4
  14. data/lib/generators/authentication/templates/app/controllers/magic_links_controller.rb.tt +9 -7
  15. data/lib/generators/authentication/templates/app/controllers/otts_controller.rb.tt +12 -9
  16. data/lib/generators/authentication/templates/app/controllers/passkey_sessions_controller.rb.tt +9 -7
  17. data/lib/generators/authentication/templates/app/controllers/passwords_controller.rb.tt +21 -8
  18. data/lib/generators/authentication/templates/app/controllers/registrations_controller.rb.tt +7 -5
  19. data/lib/generators/authentication/templates/app/controllers/sessions_controller.rb.tt +9 -7
  20. data/lib/generators/authentication/templates/app/controllers/unlocks_controller.rb.tt +7 -5
  21. data/lib/generators/authentication/templates/app/controllers/webauthn_credentials_controller.rb.tt +7 -3
  22. data/lib/generators/authentication/templates/app/mailers/confirmations_mailer.rb.tt +4 -2
  23. data/lib/generators/authentication/templates/app/mailers/invitations_mailer.rb.tt +3 -1
  24. data/lib/generators/authentication/templates/app/mailers/magic_links_mailer.rb.tt +3 -1
  25. data/lib/generators/authentication/templates/app/mailers/otts_mailer.rb.tt +3 -1
  26. data/lib/generators/authentication/templates/app/mailers/passwords_mailer.rb.tt +3 -1
  27. data/lib/generators/authentication/templates/app/mailers/unlocks_mailer.rb.tt +3 -1
  28. data/lib/generators/authentication/templates/app/models/concerns/confirmable_concern.rb.tt +7 -2
  29. data/lib/generators/authentication/templates/app/models/concerns/invitable_concern.rb.tt +12 -1
  30. data/lib/generators/authentication/templates/app/models/concerns/lockable_concern.rb.tt +8 -0
  31. data/lib/generators/authentication/templates/app/models/concerns/magic_link_concern.rb.tt +2 -0
  32. data/lib/generators/authentication/templates/app/models/concerns/ott_concern.rb.tt +2 -0
  33. data/lib/generators/authentication/templates/app/models/concerns/passkey_concern.rb.tt +2 -0
  34. data/lib/generators/authentication/templates/app/models/concerns/recoverable_concern.rb.tt +8 -0
  35. data/lib/generators/authentication/templates/app/models/concerns/timeoutable_concern.rb.tt +2 -0
  36. data/lib/generators/authentication/templates/app/models/concerns/trackable_concern.rb.tt +2 -0
  37. data/lib/generators/authentication/templates/app/models/concerns/validatable_concern.rb.tt +5 -3
  38. data/lib/generators/authentication/templates/app/models/session.rb.tt +45 -0
  39. data/lib/generators/authentication/templates/app/models/user_auth.rb.tt +5 -3
  40. data/lib/generators/authentication/templates/app/models/webauthn_credential.rb.tt +2 -0
  41. data/lib/generators/authentication/templates/app/views/confirmations/new.html.erb.tt +3 -3
  42. data/lib/generators/authentication/templates/app/views/confirmations_mailer/confirmation_instructions.html.erb.tt +3 -3
  43. data/lib/generators/authentication/templates/app/views/confirmations_mailer/confirmation_instructions.text.erb.tt +2 -2
  44. data/lib/generators/authentication/templates/app/views/invitations/edit.html.erb.tt +4 -4
  45. data/lib/generators/authentication/templates/app/views/invitations/new.html.erb.tt +3 -3
  46. data/lib/generators/authentication/templates/app/views/invitations_mailer/invitation_instructions.html.erb.tt +3 -3
  47. data/lib/generators/authentication/templates/app/views/invitations_mailer/invitation_instructions.text.erb.tt +2 -2
  48. data/lib/generators/authentication/templates/app/views/magic_links/new.html.erb.tt +4 -4
  49. data/lib/generators/authentication/templates/app/views/magic_links_mailer/magic_link.html.erb.tt +3 -3
  50. data/lib/generators/authentication/templates/app/views/magic_links_mailer/magic_link.text.erb.tt +2 -3
  51. data/lib/generators/authentication/templates/app/views/otts/edit.html.erb.tt +7 -7
  52. data/lib/generators/authentication/templates/app/views/otts_mailer/ott.html.erb.tt +3 -3
  53. data/lib/generators/authentication/templates/app/views/otts_mailer/ott.text.erb.tt +3 -3
  54. data/lib/generators/authentication/templates/app/views/passwords/edit.html.erb.tt +9 -0
  55. data/lib/generators/authentication/templates/app/views/passwords/new.html.erb.tt +8 -0
  56. data/lib/generators/authentication/templates/app/views/passwords_mailer/reset.html.erb.tt +3 -3
  57. data/lib/generators/authentication/templates/app/views/passwords_mailer/reset.text.erb.tt +2 -2
  58. data/lib/generators/authentication/templates/app/views/registrations/edit.html.erb.tt +6 -6
  59. data/lib/generators/authentication/templates/app/views/registrations/new.html.erb.tt +6 -6
  60. data/lib/generators/authentication/templates/app/views/sessions/new.html.erb.tt +20 -16
  61. data/lib/generators/authentication/templates/app/views/unlocks/new.html.erb.tt +3 -3
  62. data/lib/generators/authentication/templates/app/views/unlocks_mailer/unlock_instructions.html.erb.tt +3 -3
  63. data/lib/generators/authentication/templates/app/views/unlocks_mailer/unlock_instructions.text.erb.tt +3 -3
  64. data/lib/generators/authentication/templates/app/views/webauthn_credentials/index.html.erb.tt +5 -5
  65. data/lib/generators/authentication/templates/app/views/webauthn_credentials/new.html.erb.tt +12 -6
  66. data/lib/generators/authentication/templates/config/initializers/webauthn.rb.tt +2 -0
  67. data/lib/generators/authentication/templates/config/locales/authentication.en.yml.tt +421 -0
  68. data/lib/generators/authentication/templates/db/migrate/add_rememberable_to_sessions.rb.tt +5 -0
  69. data/lib/generators/authentication/templates/db/migrate/remove_remember_created_at_from_users.rb.tt +11 -0
  70. data/lib/rails_authentication/version.rb +1 -1
  71. metadata +8 -3
  72. data/lib/generators/authentication/templates/app/models/concerns/rememberable_concern.rb.tt +0 -15
  73. data/lib/generators/authentication/templates/db/migrate/add_rememberable_to_users.rb.tt +0 -5
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UserAuth < ApplicationRecord
2
4
  # user is optional so failed attempts against unknown email addresses still get recorded
3
5
  belongs_to :user, optional: true
@@ -8,9 +10,9 @@ class UserAuth < ApplicationRecord
8
10
  def self.record(user, request, success:, failure_reason: nil)
9
11
  create!(
10
12
  user: user,
11
- ip: request.remote_ip,
12
- user_agent: request.user_agent,
13
- referrer: request.referer,
13
+ ip: request&.remote_ip || "",
14
+ user_agent: request&.user_agent || "",
15
+ referrer: request&.referer || "",
14
16
  success: success,
15
17
  failure_reason: failure_reason
16
18
  )
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class WebauthnCredential < ApplicationRecord
2
4
  belongs_to :user
3
5
 
@@ -1,8 +1,8 @@
1
- <h1>Resend confirmation instructions</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
 
5
5
  <%%= form_with url: confirmations_path do |form| %>
6
- <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
7
- <%%= form.submit "Resend confirmation instructions" %>
6
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: params[:email_address] %><br>
7
+ <%%= form.submit t('.form.button.submit') %>
8
8
  <%% end %>
@@ -1,6 +1,6 @@
1
1
  <p>
2
- You can confirm your email address on
3
- <%%= link_to "this confirmation page", confirmation_url(@user.confirmation_token) %>.
2
+ <%%= t('.confirm_on') %>
3
+ <%%= link_to t('.confirmation_page'), confirmation_url(@user.confirmation_token) %>.
4
4
 
5
- This link will expire in <%%= distance_of_time_in_words(0, ConfirmableConcern::CONFIRMATION_TOKEN_EXPIRES_IN) %>.
5
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, ConfirmableConcern::CONFIRMATION_TOKEN_EXPIRES_IN)) %>
6
6
  </p>
@@ -1,4 +1,4 @@
1
- You can confirm your email address on
1
+ <%%= t('.confirm_on') %>
2
2
  <%%= confirmation_url(@user.confirmation_token) %>
3
3
 
4
- This link will expire in <%%= distance_of_time_in_words(0, ConfirmableConcern::CONFIRMATION_TOKEN_EXPIRES_IN) %>.
4
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, ConfirmableConcern::CONFIRMATION_TOKEN_EXPIRES_IN)) %>
@@ -1,9 +1,9 @@
1
- <h1>Accept your invitation</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
 
5
5
  <%%= form_with url: invitation_path(params[:token]), method: :patch do |form| %>
6
- <%%= form.password_field :password, required: true, autofocus: true, autocomplete: "new-password", placeholder: "Choose a password", maxlength: 72 %><br>
7
- <%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat the password", maxlength: 72 %><br>
8
- <%%= form.submit "Set my password" %>
6
+ <%%= form.password_field :password, required: true, autofocus: true, autocomplete: "new-password", placeholder: t('.form.input.password.placeholder'), maxlength: <%= password_maxlength %> %><br>
7
+ <%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: t('.form.input.password_confirmation.placeholder'), maxlength: <%= password_maxlength %> %><br>
8
+ <%%= form.submit t('.form.button.submit') %>
9
9
  <%% end %>
@@ -1,9 +1,9 @@
1
- <h1>Invite someone</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
  <%%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
5
5
 
6
6
  <%%= form_with url: invitations_path do |form| %>
7
- <%%= form.email_field :email_address, required: true, autofocus: true, placeholder: "Enter their email address" %><br>
8
- <%%= form.submit "Send invitation" %>
7
+ <%%= form.email_field :email_address, required: true, autofocus: true, placeholder: t('.form.input.email.placeholder') %><br>
8
+ <%%= form.submit t('.form.button.submit') %>
9
9
  <%% end %>
@@ -1,6 +1,6 @@
1
1
  <p>
2
- You have been invited. Set your password and activate your account on
3
- <%%= link_to "this invitation page", edit_invitation_url(@user.invitation_token) %>.
2
+ <%%= t('.activate_on') %>
3
+ <%%= link_to t('.invitation_page'), edit_invitation_url(@user.invitation_token) %>.
4
4
 
5
- This link will expire in <%%= distance_of_time_in_words(0, InvitableConcern::INVITATION_TOKEN_EXPIRES_IN) %>.
5
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, InvitableConcern::INVITATION_TOKEN_EXPIRES_IN)) %>
6
6
  </p>
@@ -1,4 +1,4 @@
1
- You have been invited. Set your password and activate your account on
1
+ <%%= t('.activate_on') %>
2
2
  <%%= edit_invitation_url(@user.invitation_token) %>
3
3
 
4
- This link will expire in <%%= distance_of_time_in_words(0, InvitableConcern::INVITATION_TOKEN_EXPIRES_IN) %>.
4
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, InvitableConcern::INVITATION_TOKEN_EXPIRES_IN)) %>
@@ -1,12 +1,12 @@
1
- <h1>Sign in with magic link</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
  <%%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
5
5
 
6
6
  <%%= form_with url: magic_links_path do |form| %>
7
- <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
8
- <%%= form.submit "Email me a sign-in link" %>
7
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: params[:email_address] %><br>
8
+ <%%= form.submit t('.form.button.submit') %>
9
9
  <%% end %>
10
10
  <br>
11
11
 
12
- <%%= link_to "Sign in with password", new_session_path %>
12
+ <%%= link_to t('.links.session'), new_session_path %>
@@ -1,6 +1,6 @@
1
1
  <p>
2
- You can sign in to your account by following
3
- <%%= link_to "this sign-in link", magic_link_url(@user.magic_link_token) %>.
2
+ <%%= t('.sign_in_on') %>
3
+ <%%= link_to t('.magic_link_page'), magic_link_url(@user.magic_link_token) %>.
4
4
 
5
- This link will expire in <%%= distance_of_time_in_words(0, MagicLinkConcern::MAGIC_LINK_EXPIRES_IN) %> and can only be used once.
5
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, MagicLinkConcern::MAGIC_LINK_EXPIRES_IN)) %>
6
6
  </p>
@@ -1,5 +1,4 @@
1
- You can sign in to your account by following the link below:
2
-
1
+ <%%= t('.sign_in_on') %>
3
2
  <%%= magic_link_url(@user.magic_link_token) %>
4
3
 
5
- This link will expire in <%%= distance_of_time_in_words(0, MagicLinkConcern::MAGIC_LINK_EXPIRES_IN) %> and can only be used once.
4
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, MagicLinkConcern::MAGIC_LINK_EXPIRES_IN)) %>
@@ -1,11 +1,11 @@
1
- <h1>Enter your sign-in code</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
  <%%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
5
5
 
6
6
  <p>
7
- We emailed a <%%= OttConcern::OTT_CODE_LENGTH %>-digit code to <%%= session[:ott_email_address] %>.
8
- It expires in <%%= distance_of_time_in_words(0, OttConcern::OTT_EXPIRES_IN) %>.
7
+ <%%= t('.emailed_code_to', digit_count: OttConcern::OTT_CODE_LENGTH, email: session[:ott_email_address]) %>
8
+ <%%= t('.expires_in', expires_in: distance_of_time_in_words(0, OttConcern::OTT_EXPIRES_IN)) %>
9
9
  </p>
10
10
 
11
11
  <%%= form_with url: ott_path, method: :patch do |form| %>
@@ -14,19 +14,19 @@
14
14
  <%% OttConcern::OTT_CODE_LENGTH.times do |i| %>
15
15
  <input type="text" inputmode="numeric" pattern="[0-9]*" maxlength="<%%= OttConcern::OTT_CODE_LENGTH %>" required
16
16
  autocomplete="<%%= i.zero? ? "one-time-code" : "off" %>"
17
- aria-label="Digit <%%= i + 1 %>" <%%= "autofocus" if i.zero? %>
17
+ aria-label="<%%= t('.form.input.digit.aria', digit: i + 1) %>" <%%= "autofocus" if i.zero? %>
18
18
  style="width:2em;text-align:center;font-size:1.5em">
19
19
  <%% end %>
20
20
  </div>
21
21
  <br>
22
22
  <% if rememberable? -%>
23
- <%%= form.check_box :remember_me %> <%%= form.label :remember_me, "Remember me" %><br>
23
+ <%%= form.check_box :remember_me %> <%%= form.label :remember_me, t('.form.input.remember.label') %><br>
24
24
  <% end -%>
25
- <%%= form.submit "Sign in" %>
25
+ <%%= form.submit t('.form.button.submit') %>
26
26
  <%% end %>
27
27
  <br>
28
28
 
29
- <%%= button_to "Resend code", ott_path, method: :post %>
29
+ <%%= button_to t('.buttons.resend'), ott_path, method: :post %>
30
30
 
31
31
  <script>
32
32
  (function() {
@@ -1,8 +1,8 @@
1
- <p>Your sign-in code is:</p>
1
+ <p><%%= t('.sign_in_code') %></p>
2
2
 
3
3
  <p><strong><%%= @user.ott_code %></strong></p>
4
4
 
5
5
  <p>
6
- This code will expire in <%%= distance_of_time_in_words(0, OttConcern::OTT_EXPIRES_IN) %> and can only be used once.
7
- If you didn't request it, you can ignore this email.
6
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, OttConcern::OTT_EXPIRES_IN)) %>
7
+ <%%= t('.ignore') %>
8
8
  </p>
@@ -1,6 +1,6 @@
1
- Your sign-in code is:
1
+ <%%= t('.sign_in_code') %>
2
2
 
3
3
  <%%= @user.ott_code %>
4
4
 
5
- This code will expire in <%%= distance_of_time_in_words(0, OttConcern::OTT_EXPIRES_IN) %> and can only be used once.
6
- If you didn't request it, you can ignore this email.
5
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, OttConcern::OTT_EXPIRES_IN)) %>
6
+ <%%= t('.ignore') %>
@@ -0,0 +1,9 @@
1
+ <h1><%%= t('.heading') %></h1>
2
+
3
+ <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
+
5
+ <%%= form_with url: password_path(params[:token]), method: :put do |form| %>
6
+ <%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: t('.form.input.password.placeholder'), maxlength: <%= password_maxlength %> %><br>
7
+ <%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: t('.form.input.password_confirmation.placeholder'), maxlength: <%= password_maxlength %> %><br>
8
+ <%%= form.submit t('.form.button.submit') %>
9
+ <%% end %>
@@ -0,0 +1,8 @@
1
+ <h1><%%= t('.heading') %></h1>
2
+
3
+ <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
+
5
+ <%%= form_with url: passwords_path do |form| %>
6
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: params[:email_address] %><br>
7
+ <%%= form.submit t('.form.button.submit') %>
8
+ <%% end %>
@@ -1,6 +1,6 @@
1
1
  <p>
2
- You can reset your password on
3
- <%%= link_to "this password reset page", edit_password_url(@user.reset_password_token) %>.
2
+ <%%= t('.reset_on') %>
3
+ <%%= link_to t('.reset_page'), edit_password_url(@user.reset_password_token) %>.
4
4
 
5
- This link will expire in <%%= distance_of_time_in_words(0, RecoverableConcern::RESET_PASSWORD_TOKEN_EXPIRES_IN) %>.
5
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, RecoverableConcern::RESET_PASSWORD_TOKEN_EXPIRES_IN)) %>
6
6
  </p>
@@ -1,4 +1,4 @@
1
- You can reset your password on
1
+ <%%= t('.reset_on') %>
2
2
  <%%= edit_password_url(@user.reset_password_token) %>
3
3
 
4
- This link will expire in <%%= distance_of_time_in_words(0, RecoverableConcern::RESET_PASSWORD_TOKEN_EXPIRES_IN) %>.
4
+ <%%= t('.expire_in', ttl: distance_of_time_in_words(0, RecoverableConcern::RESET_PASSWORD_TOKEN_EXPIRES_IN)) %>
@@ -1,4 +1,4 @@
1
- <h1>Your account</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
  <%%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
@@ -13,14 +13,14 @@
13
13
 
14
14
  <%%= form_with url: registration_path, method: :patch do |form| %>
15
15
  <%%= form.email_field :email_address, required: true, autocomplete: "username", value: @user.email_address %><br>
16
- <%%= form.password_field :password, autocomplete: "new-password", placeholder: "New password (leave blank to keep current)", maxlength: 72 %><br>
17
- <%%= form.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Repeat new password", maxlength: 72 %><br>
18
- <%%= form.submit "Update" %>
16
+ <%%= form.password_field :password, autocomplete: "new-password", placeholder: t('.form.input.password.placeholder'), maxlength: <%= password_maxlength %> %><br>
17
+ <%%= form.password_field :password_confirmation, autocomplete: "new-password", placeholder: t('.form.input.password_confirmation.placeholder'), maxlength: <%= password_maxlength %> %><br>
18
+ <%%= form.submit t('.form.button.submit') %>
19
19
  <%% end %>
20
20
  <br>
21
21
 
22
22
  <% if passkey? -%>
23
- <%%= link_to "Manage your passkeys", webauthn_credentials_path %>
23
+ <%%= link_to t('.links.passkeys'), webauthn_credentials_path %>
24
24
  <br><br>
25
25
  <% end -%>
26
- <%%= button_to "Delete my account", registration_path, method: :delete, data: { turbo_confirm: "Are you sure?" } %>
26
+ <%%= button_to t('.links.delete'), registration_path, method: :delete, data: { turbo_confirm: t('.confirmation.delete') } %>
@@ -1,4 +1,4 @@
1
- <h1>Sign up</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
 
@@ -11,11 +11,11 @@
11
11
  <%% end %>
12
12
 
13
13
  <%%= form_with url: registration_path do |form| %>
14
- <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: @user.email_address %><br>
15
- <%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: "Enter a password", maxlength: 72 %><br>
16
- <%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: "Repeat the password", maxlength: 72 %><br>
17
- <%%= form.submit "Sign up" %>
14
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: @user.email_address %><br>
15
+ <%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: t('.form.input.password.placeholder'), maxlength: <%= password_maxlength %> %><br>
16
+ <%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: t('.form.input.password_confirmation.placeholder'), maxlength: <%= password_maxlength %> %><br>
17
+ <%%= form.submit t('.form.button.submit') %>
18
18
  <%% end %>
19
19
  <br>
20
20
 
21
- <%%= link_to "Sign in", new_session_path %>
21
+ <%%= link_to t('.links.sign_in'), new_session_path %>
@@ -4,34 +4,34 @@
4
4
  <% if ott? -%>
5
5
  <%% if params[:with_password].blank? %>
6
6
  <%%= form_with url: ott_path do |form| %>
7
- <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
8
- <%%= form.submit "Email me a sign-in code" %>
7
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t('.ott.form.input.email.placeholder'), value: params[:email_address] %><br>
8
+ <%%= form.submit t('.ott.form.button.submit') %>
9
9
  <%% end %>
10
10
  <br>
11
11
 
12
- <br><%%= link_to "Sign in with password instead", new_session_path(with_password: 1) %>
12
+ <br><%%= link_to t('.links.session'), new_session_path(with_password: 1) %>
13
13
  <%% else %>
14
14
  <% end -%>
15
15
  <%%= form_with url: session_path do |form| %>
16
- <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
17
- <%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: "Enter your password", maxlength: 72 %><br>
16
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t('.session.form.input.email.placeholder'), value: params[:email_address] %><br>
17
+ <%%= form.password_field :password, required: true, autocomplete: "current-password", placeholder: t('.session.form.input.password.placeholder'), maxlength: ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED %><br>
18
18
  <% if rememberable? -%>
19
- <%%= form.check_box :remember_me %> <%%= form.label :remember_me, "Remember me" %><br>
19
+ <%%= form.check_box :remember_me %> <%%= form.label :remember_me, t('.session.form.input.remember.label') %><br>
20
20
  <% end -%>
21
- <%%= form.submit "Sign in" %>
21
+ <%%= form.submit t('.session.form.button.submit') %>
22
22
  <%% end %>
23
23
  <br>
24
24
  <% if ott? -%>
25
25
 
26
- <br><%%= link_to "Sign in with a one-time code instead", new_session_path %>
26
+ <br><%%= link_to t('.links.ott'), new_session_path %>
27
27
  <%% end %>
28
28
  <% end -%>
29
29
 
30
30
  <% if magic_link? -%>
31
- <br><%%= link_to "Sign in with magic link", new_magic_link_path %>
31
+ <br><%%= link_to t('.links.magic_link'), new_magic_link_path %>
32
32
  <% end -%>
33
33
  <% if passkey? -%>
34
- <br><%%= button_tag "Sign in with a passkey", type: "button", id: "passkey-sign-in-button" %>
34
+ <br><%%= button_tag t('.links.passkey'), type: "button", id: "passkey-sign-in-button" %>
35
35
  <%%= tag.span "", id: "passkey-sign-in-error", style: "color:red" %>
36
36
 
37
37
  <%%= javascript_tag do %>
@@ -62,7 +62,11 @@
62
62
  try {
63
63
  credential = await navigator.credentials.get({ publicKey: options });
64
64
  } catch (error) {
65
- document.getElementById("passkey-sign-in-error").textContent = error.message;
65
+ // The browser's own message is technical, so show a translated one and log the original.
66
+ console.error(error);
67
+ document.getElementById("passkey-sign-in-error").textContent = error.name === "NotAllowedError"
68
+ ? "<%%= j t('.error.cancelled') %>"
69
+ : "<%%= j t('.error.passkey') %>";
66
70
  return;
67
71
  }
68
72
 
@@ -89,19 +93,19 @@
89
93
  if (response.ok) {
90
94
  window.location.href = result.redirect_to;
91
95
  } else {
92
- document.getElementById("passkey-sign-in-error").textContent = result.error || "Could not sign in with passkey.";
96
+ document.getElementById("passkey-sign-in-error").textContent = result.error || "<%%= j t('.error.passkey') %>";
93
97
  }
94
98
  });
95
99
  })();
96
100
  <%% end %>
97
101
  <% end -%>
98
- <br><%%= link_to "Forgot password?", new_password_path %>
102
+ <br><%%= link_to t('.links.forgot_password'), new_password_path %>
99
103
  <% if registerable? -%>
100
- <br><%%= link_to "Sign up", new_registration_path %>
104
+ <br><%%= link_to t('.links.sign_up'), new_registration_path %>
101
105
  <% end -%>
102
106
  <% if confirmable? -%>
103
- <br><%%= link_to "Resend confirmation instructions", new_confirmation_path %>
107
+ <br><%%= link_to t('.links.resend_confirmation'), new_confirmation_path %>
104
108
  <% end -%>
105
109
  <% if lockable? -%>
106
- <br><%%= link_to "Resend unlock instructions", new_unlock_path %>
110
+ <br><%%= link_to t('.links.resend_unlock'), new_unlock_path %>
107
111
  <% end -%>
@@ -1,8 +1,8 @@
1
- <h1>Resend unlock instructions</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
 
5
5
  <%%= form_with url: unlocks_path do |form| %>
6
- <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: "Enter your email address", value: params[:email_address] %><br>
7
- <%%= form.submit "Resend unlock instructions" %>
6
+ <%%= form.email_field :email_address, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: params[:email_address] %><br>
7
+ <%%= form.submit t('.form.button.submit') %>
8
8
  <%% end %>
@@ -1,6 +1,6 @@
1
1
  <p>
2
- Your account has been locked due to too many failed sign-in attempts.
2
+ <%%= t('.attempts') %>
3
3
 
4
- You can unlock it now on <%%= link_to "this unlock page", unlock_url(@user.unlock_token) %>,
5
- or wait <%%= distance_of_time_in_words(0, LockableConcern::UNLOCK_IN) %> for the lock to expire on its own.
4
+ <%%= t('.unlock_on') %> <%%= link_to t('.unlock_page'), unlock_url(@user.unlock_token) %>,
5
+ <%%= t('.or_wait', ttl: distance_of_time_in_words(0, LockableConcern::UNLOCK_IN)) %>
6
6
  </p>
@@ -1,6 +1,6 @@
1
- Your account has been locked due to too many failed sign-in attempts.
1
+ <%%= t('.attempts') %>
2
2
 
3
- You can unlock it now on
3
+ <%%= t('.unlock_on') %>
4
4
  <%%= unlock_url(@user.unlock_token) %>
5
5
 
6
- or wait <%%= distance_of_time_in_words(0, LockableConcern::UNLOCK_IN) %> for the lock to expire on its own.
6
+ <%%= t('.or_wait', ttl: distance_of_time_in_words(0, LockableConcern::UNLOCK_IN)) %>
@@ -1,19 +1,19 @@
1
- <h1>Your passkeys</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
  <%%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
5
5
 
6
6
  <%% if @webauthn_credentials.empty? %>
7
- <p>You haven't added a passkey yet.</p>
7
+ <p><%%= t('.none') %></p>
8
8
  <%% else %>
9
9
  <ul>
10
10
  <%% @webauthn_credentials.each do |credential| %>
11
11
  <li>
12
- <%%= credential.nickname %> &mdash; added <%%= credential.created_at.to_date %>
13
- <%%= button_to "Remove", webauthn_credential_path(credential), method: :delete, data: { turbo_confirm: "Remove this passkey?" } %>
12
+ <%%= t('.account_added', nickname: credential.nickname, date_added: credential.created_at.to_date) %>
13
+ <%%= button_to t('.buttons.remove'), webauthn_credential_path(credential), method: :delete, data: { turbo_confirm: t('.confirmations.remove') } %>
14
14
  </li>
15
15
  <%% end %>
16
16
  </ul>
17
17
  <%% end %>
18
18
 
19
- <br><%%= link_to "Add a passkey", new_webauthn_credential_path %>
19
+ <br><%%= link_to t('.links.add'), new_webauthn_credential_path %>
@@ -1,12 +1,12 @@
1
- <h1>Add a passkey</h1>
1
+ <h1><%%= t('.heading') %></h1>
2
2
 
3
3
  <%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
4
4
  <%%= tag.span "", id: "passkey-error", style: "color:red" %>
5
5
 
6
- <%%= label_tag :passkey_nickname, "Name this passkey (e.g. \"MacBook\" or \"iPhone\")" %>
7
- <%%= text_field_tag :passkey_nickname, nil, placeholder: "Passkey" %><br><br>
6
+ <%%= label_tag :passkey_nickname, t('.form.input.nickname.label') %>
7
+ <%%= text_field_tag :passkey_nickname, nil, placeholder: t('.form.input.nickname.placeholder') %><br><br>
8
8
 
9
- <%%= button_tag "Create passkey", type: "button", id: "create-passkey-button" %>
9
+ <%%= button_tag t('.form.button.submit'), type: "button", id: "create-passkey-button" %>
10
10
 
11
11
  <%%= javascript_tag do %>
12
12
  (function () {
@@ -38,7 +38,13 @@
38
38
  try {
39
39
  credential = await navigator.credentials.create({ publicKey: options });
40
40
  } catch (error) {
41
- document.getElementById("passkey-error").textContent = error.message;
41
+ // The browser's own message is technical, so show a translated one and log the original.
42
+ console.error(error);
43
+ const messages = {
44
+ InvalidStateError: "<%%= j t('.error.already_registered') %>",
45
+ NotAllowedError: "<%%= j t('.error.cancelled') %>"
46
+ };
47
+ document.getElementById("passkey-error").textContent = messages[error.name] || "<%%= j t('.error.save') %>";
42
48
  return;
43
49
  }
44
50
 
@@ -64,7 +70,7 @@
64
70
  if (response.ok) {
65
71
  window.location.href = result.redirect_to;
66
72
  } else {
67
- document.getElementById("passkey-error").textContent = result.error || "Could not save passkey.";
73
+ document.getElementById("passkey-error").textContent = result.error || "<%%= j t('.error.save') %>";
68
74
  }
69
75
  });
70
76
  })();
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  WebAuthn.configure do |config|
2
4
  # This value needs to match `window.location.hostname` where the API is called from in
3
5
  # your client-side (front-end) code.