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.
- checksums.yaml +4 -4
- data/README.md +100 -10
- data/lib/generators/authentication/authentication_generator.rb +135 -8
- data/lib/generators/authentication/features/confirmable.rb +5 -5
- data/lib/generators/authentication/features/invitable.rb +5 -5
- data/lib/generators/authentication/features/lockable.rb +5 -5
- data/lib/generators/authentication/features/magic_link.rb +5 -5
- data/lib/generators/authentication/features/ott.rb +5 -5
- data/lib/generators/authentication/features/recoverable.rb +8 -6
- data/lib/generators/authentication/features/rememberable.rb +8 -3
- data/lib/generators/authentication/templates/app/controllers/concerns/authentication.rb.tt +67 -15
- data/lib/generators/authentication/templates/app/controllers/confirmations_controller.rb.tt +11 -7
- data/lib/generators/authentication/templates/app/controllers/invitations_controller.rb.tt +14 -5
- data/lib/generators/authentication/templates/app/controllers/magic_links_controller.rb.tt +10 -8
- data/lib/generators/authentication/templates/app/controllers/otts_controller.rb.tt +18 -15
- data/lib/generators/authentication/templates/app/controllers/passkey_sessions_controller.rb.tt +9 -7
- data/lib/generators/authentication/templates/app/controllers/passwords_controller.rb.tt +22 -9
- data/lib/generators/authentication/templates/app/controllers/registrations_controller.rb.tt +8 -6
- data/lib/generators/authentication/templates/app/controllers/sessions_controller.rb.tt +11 -9
- data/lib/generators/authentication/templates/app/controllers/unlocks_controller.rb.tt +8 -6
- data/lib/generators/authentication/templates/app/controllers/webauthn_credentials_controller.rb.tt +8 -4
- data/lib/generators/authentication/templates/app/mailers/confirmations_mailer.rb.tt +4 -2
- data/lib/generators/authentication/templates/app/mailers/invitations_mailer.rb.tt +3 -1
- data/lib/generators/authentication/templates/app/mailers/magic_links_mailer.rb.tt +3 -1
- data/lib/generators/authentication/templates/app/mailers/otts_mailer.rb.tt +3 -1
- data/lib/generators/authentication/templates/app/mailers/passwords_mailer.rb.tt +3 -1
- data/lib/generators/authentication/templates/app/mailers/unlocks_mailer.rb.tt +3 -1
- data/lib/generators/authentication/templates/app/models/concerns/confirmable_concern.rb.tt +16 -11
- data/lib/generators/authentication/templates/app/models/concerns/invitable_concern.rb.tt +13 -2
- data/lib/generators/authentication/templates/app/models/concerns/lockable_concern.rb.tt +8 -0
- data/lib/generators/authentication/templates/app/models/concerns/magic_link_concern.rb.tt +2 -0
- data/lib/generators/authentication/templates/app/models/concerns/ott_concern.rb.tt +2 -0
- data/lib/generators/authentication/templates/app/models/concerns/passkey_concern.rb.tt +2 -0
- data/lib/generators/authentication/templates/app/models/concerns/recoverable_concern.rb.tt +8 -0
- data/lib/generators/authentication/templates/app/models/concerns/timeoutable_concern.rb.tt +2 -0
- data/lib/generators/authentication/templates/app/models/concerns/trackable_concern.rb.tt +2 -0
- data/lib/generators/authentication/templates/app/models/concerns/validatable_concern.rb.tt +6 -4
- data/lib/generators/authentication/templates/app/models/session.rb.tt +45 -0
- data/lib/generators/authentication/templates/app/models/user_auth.rb.tt +5 -3
- data/lib/generators/authentication/templates/app/models/webauthn_credential.rb.tt +2 -0
- data/lib/generators/authentication/templates/app/views/confirmations/new.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/confirmations_mailer/confirmation_instructions.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/confirmations_mailer/confirmation_instructions.text.erb.tt +2 -2
- data/lib/generators/authentication/templates/app/views/invitations/edit.html.erb.tt +4 -4
- data/lib/generators/authentication/templates/app/views/invitations/new.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/invitations_mailer/invitation_instructions.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/invitations_mailer/invitation_instructions.text.erb.tt +2 -2
- data/lib/generators/authentication/templates/app/views/magic_links/new.html.erb.tt +4 -4
- data/lib/generators/authentication/templates/app/views/magic_links_mailer/magic_link.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/magic_links_mailer/magic_link.text.erb.tt +2 -3
- data/lib/generators/authentication/templates/app/views/otts/edit.html.erb.tt +7 -7
- data/lib/generators/authentication/templates/app/views/otts_mailer/ott.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/otts_mailer/ott.text.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/passwords/edit.html.erb.tt +9 -0
- data/lib/generators/authentication/templates/app/views/passwords/new.html.erb.tt +8 -0
- data/lib/generators/authentication/templates/app/views/passwords_mailer/reset.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/passwords_mailer/reset.text.erb.tt +2 -2
- data/lib/generators/authentication/templates/app/views/registrations/edit.html.erb.tt +7 -7
- data/lib/generators/authentication/templates/app/views/registrations/new.html.erb.tt +6 -6
- data/lib/generators/authentication/templates/app/views/sessions/new.html.erb.tt +20 -16
- data/lib/generators/authentication/templates/app/views/unlocks/new.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/unlocks_mailer/unlock_instructions.html.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/unlocks_mailer/unlock_instructions.text.erb.tt +3 -3
- data/lib/generators/authentication/templates/app/views/webauthn_credentials/index.html.erb.tt +5 -5
- data/lib/generators/authentication/templates/app/views/webauthn_credentials/new.html.erb.tt +12 -6
- data/lib/generators/authentication/templates/config/initializers/webauthn.rb.tt +2 -0
- data/lib/generators/authentication/templates/config/locales/authentication.en.yml.tt +421 -0
- data/lib/generators/authentication/templates/db/migrate/add_confirmable_to_users.rb.tt +1 -1
- data/lib/generators/authentication/templates/db/migrate/add_rememberable_to_sessions.rb.tt +5 -0
- data/lib/generators/authentication/templates/db/migrate/remove_remember_created_at_from_users.rb.tt +11 -0
- data/lib/rails_authentication/version.rb +1 -1
- metadata +8 -3
- data/lib/generators/authentication/templates/app/models/concerns/rememberable_concern.rb.tt +0 -15
- data/lib/generators/authentication/templates/db/migrate/add_rememberable_to_users.rb.tt +0 -5
data/lib/generators/authentication/templates/app/controllers/webauthn_credentials_controller.rb.tt
CHANGED
|
@@ -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
|
|
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 || "
|
|
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
|
-
|
|
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: "
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.
|
|
30
|
-
self
|
|
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
|
|
61
|
-
!@confirming &&
|
|
65
|
+
def postponing_email_change?
|
|
66
|
+
!@confirming && attribute_changed?(self.class.authentication_email_column_name) && confirmed?
|
|
62
67
|
end
|
|
63
68
|
|
|
64
|
-
def
|
|
65
|
-
self
|
|
66
|
-
self.
|
|
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(
|
|
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,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,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 #
|
|
12
|
+
PASSWORD_MINIMUM_COMPLEXITY = 2 # Minimum number of complexities to match to be valid
|
|
11
13
|
|
|
12
14
|
included do
|
|
13
|
-
validates
|
|
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,
|
|
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
|
|
12
|
-
user_agent: request
|
|
13
|
-
referrer: request
|
|
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,8 +1,8 @@
|
|
|
1
|
-
<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
|
|
7
|
-
<%%= form.submit
|
|
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
|
-
|
|
3
|
-
<%%= link_to
|
|
2
|
+
<%%= t('.confirm_on') %>
|
|
3
|
+
<%%= link_to t('.confirmation_page'), confirmation_url(@user.confirmation_token) %>.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<%%= t('.expire_in', ttl: distance_of_time_in_words(0, ConfirmableConcern::CONFIRMATION_TOKEN_EXPIRES_IN)) %>
|
|
6
6
|
</p>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
<%%= t('.confirm_on') %>
|
|
2
2
|
<%%= confirmation_url(@user.confirmation_token) %>
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
<%%= t('.expire_in', ttl: distance_of_time_in_words(0, ConfirmableConcern::CONFIRMATION_TOKEN_EXPIRES_IN)) %>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
<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:
|
|
7
|
-
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder:
|
|
8
|
-
<%%= form.submit
|
|
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
|
|
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
|
|
8
|
-
<%%= form.submit
|
|
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
|
-
|
|
3
|
-
<%%= link_to
|
|
2
|
+
<%%= t('.activate_on') %>
|
|
3
|
+
<%%= link_to t('.invitation_page'), edit_invitation_url(@user.invitation_token) %>.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<%%= t('.expire_in', ttl: distance_of_time_in_words(0, InvitableConcern::INVITATION_TOKEN_EXPIRES_IN)) %>
|
|
6
6
|
</p>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
<%%= t('.activate_on') %>
|
|
2
2
|
<%%= edit_invitation_url(@user.invitation_token) %>
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
<%%= t('.expire_in', ttl: distance_of_time_in_words(0, InvitableConcern::INVITATION_TOKEN_EXPIRES_IN)) %>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<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
|
|
8
|
-
<%%= form.submit
|
|
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
|
|
12
|
+
<%%= link_to t('.links.session'), new_session_path %>
|
data/lib/generators/authentication/templates/app/views/magic_links_mailer/magic_link.html.erb.tt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p>
|
|
2
|
-
|
|
3
|
-
<%%= link_to
|
|
2
|
+
<%%= t('.sign_in_on') %>
|
|
3
|
+
<%%= link_to t('.magic_link_page'), magic_link_url(@user.magic_link_token) %>.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<%%= t('.expire_in', ttl: distance_of_time_in_words(0, MagicLinkConcern::MAGIC_LINK_EXPIRES_IN)) %>
|
|
6
6
|
</p>
|
data/lib/generators/authentication/templates/app/views/magic_links_mailer/magic_link.text.erb.tt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<%%= t('.sign_in_on') %>
|
|
3
2
|
<%%= magic_link_url(@user.magic_link_token) %>
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
<%%= t('.expire_in', ttl: distance_of_time_in_words(0, MagicLinkConcern::MAGIC_LINK_EXPIRES_IN)) %>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<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
|
-
|
|
8
|
-
|
|
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="
|
|
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,
|
|
23
|
+
<%%= form.check_box :remember_me %> <%%= form.label :remember_me, t('.form.input.remember.label') %><br>
|
|
24
24
|
<% end -%>
|
|
25
|
-
<%%= form.submit
|
|
25
|
+
<%%= form.submit t('.form.button.submit') %>
|
|
26
26
|
<%% end %>
|
|
27
27
|
<br>
|
|
28
28
|
|
|
29
|
-
<%%= button_to
|
|
29
|
+
<%%= button_to t('.buttons.resend'), ott_path, method: :post %>
|
|
30
30
|
|
|
31
31
|
<script>
|
|
32
32
|
(function() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
1
|
+
<%%= t('.sign_in_code') %>
|
|
2
2
|
|
|
3
3
|
<%%= @user.ott_code %>
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
3
|
-
<%%= link_to
|
|
2
|
+
<%%= t('.reset_on') %>
|
|
3
|
+
<%%= link_to t('.reset_page'), edit_password_url(@user.reset_password_token) %>.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
1
|
+
<%%= t('.reset_on') %>
|
|
2
2
|
<%%= edit_password_url(@user.reset_password_token) %>
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
<%%= t('.expire_in', ttl: distance_of_time_in_words(0, RecoverableConcern::RESET_PASSWORD_TOKEN_EXPIRES_IN)) %>
|