rails_authentication 0.6.0 → 0.8.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +100 -10
  3. data/lib/generators/authentication/authentication_generator.rb +135 -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 +67 -15
  12. data/lib/generators/authentication/templates/app/controllers/confirmations_controller.rb.tt +11 -7
  13. data/lib/generators/authentication/templates/app/controllers/invitations_controller.rb.tt +14 -5
  14. data/lib/generators/authentication/templates/app/controllers/magic_links_controller.rb.tt +10 -8
  15. data/lib/generators/authentication/templates/app/controllers/otts_controller.rb.tt +18 -15
  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 +22 -9
  18. data/lib/generators/authentication/templates/app/controllers/registrations_controller.rb.tt +8 -6
  19. data/lib/generators/authentication/templates/app/controllers/sessions_controller.rb.tt +11 -9
  20. data/lib/generators/authentication/templates/app/controllers/unlocks_controller.rb.tt +8 -6
  21. data/lib/generators/authentication/templates/app/controllers/webauthn_credentials_controller.rb.tt +8 -4
  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 +16 -11
  29. data/lib/generators/authentication/templates/app/models/concerns/invitable_concern.rb.tt +13 -2
  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 +6 -4
  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 +7 -7
  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_confirmable_to_users.rb.tt +1 -1
  69. data/lib/generators/authentication/templates/db/migrate/add_rememberable_to_sessions.rb.tt +5 -0
  70. data/lib/generators/authentication/templates/db/migrate/remove_remember_created_at_from_users.rb.tt +11 -0
  71. data/lib/rails_authentication/version.rb +1 -1
  72. metadata +8 -3
  73. data/lib/generators/authentication/templates/app/models/concerns/rememberable_concern.rb.tt +0 -15
  74. 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 WebauthnCredentialsController < ApplicationController
2
4
  before_action :set_webauthn_credential, only: :destroy
3
5
 
@@ -7,7 +9,7 @@ class WebauthnCredentialsController < ApplicationController
7
9
 
8
10
  def new
9
11
  @webauthn_credential_options = WebAuthn::Credential.options_for_create(
10
- user: { id: current_user.webauthn_id, name: current_user.email_address },
12
+ user: { id: current_user.webauthn_id, name: current_user[authentication_email_column_name] },
11
13
  exclude: current_user.webauthn_credentials.pluck(:external_id)
12
14
  )
13
15
  session[:webauthn_registration_challenge] = @webauthn_credential_options.challenge
@@ -21,18 +23,20 @@ class WebauthnCredentialsController < ApplicationController
21
23
  external_id: webauthn_credential.id,
22
24
  public_key: webauthn_credential.public_key,
23
25
  sign_count: webauthn_credential.sign_count,
24
- nickname: params[:nickname].presence || "Passkey"
26
+ nickname: params[:nickname].presence || t("webauthn_credentials.create.default_nickname")
25
27
  )
26
28
  session.delete(:webauthn_registration_challenge)
27
29
 
28
30
  render json: { redirect_to: webauthn_credentials_path }
29
31
  rescue WebAuthn::Error => e
30
- render json: { error: e.message }, status: :unprocessable_content
32
+ # The gem's message is technical and English-only, so log it and show a translated one.
33
+ logger.info "Passkey registration failed: #{e.message}"
34
+ render json: { error: t("json.webauthn_credentials.create.alert.save_failed") }, status: :unprocessable_content
31
35
  end
32
36
 
33
37
  def destroy
34
38
  @webauthn_credential.destroy
35
- redirect_to webauthn_credentials_path, notice: "Passkey removed."
39
+ redirect_to webauthn_credentials_path, notice: t("flash.webauthn_credentials.destroy.notice")
36
40
  end
37
41
 
38
42
  private
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ConfirmationsMailer < ApplicationMailer
2
4
  def confirmation_instructions(user)
3
5
  @user = user
4
6
  <% if reconfirmable? -%>
5
- mail subject: "Confirm your email address", to: user.unconfirmed_email.presence || user.email_address
7
+ mail subject: t('confirmations_mailer.confirmation_instructions.subject'), to: user.<%= unconfirmed_email_attribute %>.presence || user[User.authentication_email_column_name]
6
8
  <% else -%>
7
- mail subject: "Confirm your email address", to: user.email_address
9
+ mail subject: t('confirmations_mailer.confirmation_instructions.subject'), to: user[User.authentication_email_column_name]
8
10
  <% end -%>
9
11
  end
10
12
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class InvitationsMailer < ApplicationMailer
2
4
  def invitation_instructions(user)
3
5
  @user = user
4
- mail subject: "You have been invited", to: user.email_address
6
+ mail subject: t('invitations_mailer.invitation_instructions.subject'), to: user[User.authentication_email_column_name]
5
7
  end
6
8
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MagicLinksMailer < ApplicationMailer
2
4
  def magic_link(user)
3
5
  @user = user
4
- mail subject: "Your sign-in link", to: user.email_address
6
+ mail subject: t('magic_links_mailer.magic_link.subject'), to: user[User.authentication_email_column_name]
5
7
  end
6
8
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class OttsMailer < ApplicationMailer
2
4
  def ott(user)
3
5
  @user = user
4
- mail subject: "Your sign-in code", to: user.email_address
6
+ mail subject: t('otts_mailer.ott.subject'), to: user[User.authentication_email_column_name]
5
7
  end
6
8
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PasswordsMailer < ApplicationMailer
2
4
  def reset(user)
3
5
  @user = user
4
- mail subject: "Reset your password", to: user.email_address
6
+ mail subject: t('passwords_mailer.reset.subject'), to: user[User.authentication_email_column_name]
5
7
  end
6
8
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UnlocksMailer < ApplicationMailer
2
4
  def unlock_instructions(user)
3
5
  @user = user
4
- mail subject: "Unlock your account", to: user.email_address
6
+ mail subject: t('unlocks_mailer.unlock_instructions.subject'), to: user[User.authentication_email_column_name]
5
7
  end
6
8
  end
@@ -1,14 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ConfirmableConcern
2
4
  extend ActiveSupport::Concern
3
5
 
4
6
  CONFIRMATION_TOKEN_EXPIRES_IN = 24.hours
5
- <% if reconfirmable? -%>
6
7
 
7
8
  included do
8
- before_update :postpone_email_address_change, if: :postponing_email_address_change?
9
- after_update_commit :deliver_reconfirmation_instructions, if: -> { saved_change_to_unconfirmed_email? && unconfirmed_email.present? }
10
- end
9
+ <% if reconfirmable? -%>
10
+ before_update :postpone_email_change, if: :postponing_email_change?
11
+ after_update_commit :deliver_reconfirmation_instructions, if: -> { saved_change_to_<%= unconfirmed_email_attribute %>? && <%= unconfirmed_email_attribute %>.present? }
12
+
11
13
  <% end -%>
14
+ scope :confirmed, -> { where.not(confirmed_at: nil) }
15
+ scope :unconfirmed, -> { where(confirmed_at: nil) }
16
+ end
12
17
 
13
18
  class_methods do
14
19
  def find_by_valid_confirmation_token(token)
@@ -26,8 +31,8 @@ module ConfirmableConcern
26
31
  def confirm!
27
32
  <% if reconfirmable? -%>
28
33
  @confirming = true
29
- self.email_address = unconfirmed_email if unconfirmed_email.present?
30
- self.unconfirmed_email = nil
34
+ self[self.class.authentication_email_column_name] = <%= unconfirmed_email_attribute %> if <%= unconfirmed_email_attribute %>.present?
35
+ self.<%= unconfirmed_email_attribute %> = nil
31
36
  self.confirmed_at = Time.current
32
37
  self.confirmation_token = nil
33
38
  self.confirmation_sent_at = nil
@@ -57,13 +62,13 @@ module ConfirmableConcern
57
62
 
58
63
  private
59
64
 
60
- def postponing_email_address_change?
61
- !@confirming && email_address_changed? && confirmed?
65
+ def postponing_email_change?
66
+ !@confirming && attribute_changed?(self.class.authentication_email_column_name) && confirmed?
62
67
  end
63
68
 
64
- def postpone_email_address_change
65
- self.unconfirmed_email = email_address
66
- self.email_address = email_address_in_database
69
+ def postpone_email_change
70
+ self.<%= unconfirmed_email_attribute %> = self[self.class.authentication_email_column_name]
71
+ self[self.class.authentication_email_column_name] = attribute_in_database(self.class.authentication_email_column_name)
67
72
  self.confirmation_token = generate_confirmable_token
68
73
  self.confirmation_sent_at = Time.current
69
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InvitableConcern
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -5,12 +7,21 @@ module InvitableConcern
5
7
 
6
8
  included do
7
9
  belongs_to :invited_by, polymorphic: true, optional: true
10
+
11
+ # has_secure_password treats a blank password as "unchanged", so without this a blank
12
+ # acceptance would accept the invitation while keeping the generated temporary password.
13
+ validates :password, presence: true, on: :invitation_acceptance
14
+
15
+ # Match invitation_pending?: a user who signed up without an invitation is neither.
16
+ scope :accepted, -> { where.not(invitation_accepted_at: nil) }
17
+ scope :pending, -> { where.not(invitation_token: nil).where(invitation_accepted_at: nil) }
18
+ scope :not_pending, -> { where(invitation_token: nil).or(where.not(invitation_accepted_at: nil)) }
8
19
  end
9
20
 
10
21
  class_methods do
11
22
  def invite!(attributes, invited_by: nil)
12
23
  attributes = attributes.to_h.symbolize_keys
13
- user = find_by(email_address: attributes[:email_address])
24
+ user = find_by(authentication_email_column_name => attributes[authentication_email_column_name])
14
25
 
15
26
  if user
16
27
  # Re-inviting an existing pending invitee refreshes their token; anyone else
@@ -82,6 +93,6 @@ module InvitableConcern
82
93
  <% if confirmable? -%>
83
94
  self.confirmed_at ||= Time.current # accepting the invite proves the email address
84
95
  <% end -%>
85
- save
96
+ save(context: :invitation_acceptance)
86
97
  end
87
98
  end
@@ -1,9 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LockableConcern
2
4
  extend ActiveSupport::Concern
3
5
 
4
6
  MAXIMUM_ATTEMPTS = 5
5
7
  UNLOCK_IN = 1.hour
6
8
 
9
+ included do
10
+ # Match locked?: a lock expires on its own after UNLOCK_IN.
11
+ scope :locked, -> { where(locked_at: UNLOCK_IN.ago..) }
12
+ scope :not_locked, -> { where(locked_at: nil).or(where(locked_at: ...UNLOCK_IN.ago)) }
13
+ end
14
+
7
15
  class_methods do
8
16
  def find_by_valid_unlock_token(token)
9
17
  return if token.blank?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MagicLinkConcern
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module OttConcern
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PasskeyConcern
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -1,8 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RecoverableConcern
2
4
  extend ActiveSupport::Concern
3
5
 
4
6
  RESET_PASSWORD_TOKEN_EXPIRES_IN = 4.hours
5
7
 
8
+ included do
9
+ # has_secure_password treats a blank password as "unchanged", so without this a blank reset
10
+ # form would "succeed" (token cleared, sessions ended) while keeping the old password.
11
+ validates :password, presence: true, on: :password_reset
12
+ end
13
+
6
14
  class_methods do
7
15
  def find_by_valid_reset_password_token(token)
8
16
  return if token.blank?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TimeoutableConcern
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TrackableConcern
2
4
  extend ActiveSupport::Concern
3
5
 
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ValidatableConcern
2
4
  extend ActiveSupport::Concern
3
5
 
4
6
  EMAIL_ADDRESS_REGEXP = /\A[^@\s]+@[^@\s]+\z/
5
- PASSWORD_LENGTH = 6..72
7
+ PASSWORD_LENGTH = 6..ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED # bcrypt can't hash more than 72 bytes
6
8
  PASSWORD_DIGIT_REGEXP = /\d+/
7
9
  PASSWORD_UPPER_REGEXP = /[A-Z]+/
8
10
  PASSWORD_LOWER_REGEXP = /[a-z]+/
9
11
  PASSWORD_SPECIAL_REGEXP = /[^a-zA-Z\d\s]+/
10
- PASSWORD_MINIMUM_COMPLEXITY = 2 # Minumum number of complexities to match to be valid
12
+ PASSWORD_MINIMUM_COMPLEXITY = 2 # Minimum number of complexities to match to be valid
11
13
 
12
14
  included do
13
- validates :email_address, presence: true,
15
+ validates authentication_email_column_name, presence: true,
14
16
  format: { with: EMAIL_ADDRESS_REGEXP },
15
17
  uniqueness: { case_sensitive: false }
16
18
  validates :password, length: { in: PASSWORD_LENGTH }, allow_nil: true
@@ -23,7 +25,7 @@ module ValidatableConcern
23
25
  def password_complexity
24
26
  return if password.blank? || valid_password_complexity?
25
27
 
26
- errors.add(:password, "must meet password complexity standards")
28
+ errors.add(:password, :complexity)
27
29
  end
28
30
 
29
31
  def valid_password_complexity?
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Session < ApplicationRecord
4
+ <% if rememberable? -%>
5
+ # How long a browser session lasts without activity even when it's remembered (the cookie is permanent)
6
+ REMEMBERED_TIMEOUT_IN = 90.days
7
+
8
+ <% end -%>
9
+ belongs_to :user
10
+ <% if timeoutable? && rememberable? -%>
11
+
12
+ scope :expired, lambda {
13
+ where(updated_at: ...REMEMBERED_TIMEOUT_IN.ago)
14
+ .or(where(remembered_at: nil, updated_at: ...TimeoutableConcern::TIMEOUT_IN.ago))
15
+ }
16
+
17
+ def remembered?
18
+ remembered_at.present?
19
+ end
20
+
21
+ def expired?
22
+ return false if updated_at.blank?
23
+
24
+ updated_at.before?(REMEMBERED_TIMEOUT_IN.ago) || (!remembered? && user.timedout?(updated_at))
25
+ end
26
+ <% elsif timeoutable? -%>
27
+
28
+ scope :expired, -> { where(updated_at: ...TimeoutableConcern::TIMEOUT_IN.ago) }
29
+
30
+ def expired?
31
+ user.timedout?(updated_at)
32
+ end
33
+ <% elsif rememberable? -%>
34
+
35
+ scope :expired, -> { where(updated_at: ...REMEMBERED_TIMEOUT_IN.ago) }
36
+
37
+ def remembered?
38
+ remembered_at.present?
39
+ end
40
+
41
+ def expired?
42
+ updated_at.present? && updated_at.before?(REMEMBERED_TIMEOUT_IN.ago)
43
+ end
44
+ <% end -%>
45
+ end
@@ -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 authentication_email_column_name, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: params[authentication_email_column_name] %><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 authentication_email_column_name, 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 authentication_email_column_name, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: params[authentication_email_column_name] %><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]) %>
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 authentication_email_column_name, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: params[authentication_email_column_name] %><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)) %>