rails_authentication 0.7.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 +27 -3
- data/lib/generators/authentication/authentication_generator.rb +67 -2
- data/lib/generators/authentication/templates/app/controllers/concerns/authentication.rb.tt +6 -1
- data/lib/generators/authentication/templates/app/controllers/confirmations_controller.rb.tt +2 -2
- data/lib/generators/authentication/templates/app/controllers/invitations_controller.rb.tt +2 -2
- data/lib/generators/authentication/templates/app/controllers/magic_links_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/controllers/otts_controller.rb.tt +6 -6
- data/lib/generators/authentication/templates/app/controllers/passwords_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/controllers/registrations_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/controllers/sessions_controller.rb.tt +2 -2
- data/lib/generators/authentication/templates/app/controllers/unlocks_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/controllers/webauthn_credentials_controller.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/mailers/confirmations_mailer.rb.tt +2 -2
- data/lib/generators/authentication/templates/app/mailers/invitations_mailer.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/mailers/magic_links_mailer.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/mailers/otts_mailer.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/mailers/passwords_mailer.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/mailers/unlocks_mailer.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/models/concerns/confirmable_concern.rb.tt +9 -9
- data/lib/generators/authentication/templates/app/models/concerns/invitable_concern.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/models/concerns/validatable_concern.rb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/confirmations/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/invitations/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/magic_links/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/otts/edit.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/passwords/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/registrations/edit.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/registrations/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/app/views/sessions/new.html.erb.tt +2 -2
- data/lib/generators/authentication/templates/app/views/unlocks/new.html.erb.tt +1 -1
- data/lib/generators/authentication/templates/config/locales/authentication.en.yml.tt +1 -1
- data/lib/generators/authentication/templates/db/migrate/add_confirmable_to_users.rb.tt +1 -1
- data/lib/rails_authentication/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e22bc37be667fc7d313ce7dbd03fa15af737e2db2b970d278d22dfe08de0d104
|
|
4
|
+
data.tar.gz: 002c05612493987e996f05f7619eefb1ad35af7e9d1e3200bae1a2ab6ab3762c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3424cdf674403e45779bd49fce73bd28936e479d61a69ef6b104f6532dbcaf7168272ceeef7e2c2831d6b8995b94380d08a3f9389fa17cc1dd74be4ae559c627
|
|
7
|
+
data.tar.gz: 265cebd163520740f80e04006c67641c24f879d35b574678a0a82d0b5ee6bcabc479396cbe173e5525cd58678a159061d8a38145f7db8f3b81fcbf7ce2a48e55
|
data/README.md
CHANGED
|
@@ -58,6 +58,29 @@ Available flags: `--skip-confirmable`, `--skip-recoverable`, `--skip-registerabl
|
|
|
58
58
|
`--skip-lockable`, `--skip-invitable`, and `--reconfirmable` (Confirmable: postpone email address
|
|
59
59
|
changes until the new address is confirmed, via an `unconfirmed_email` column).
|
|
60
60
|
|
|
61
|
+
To call the email column something other than Rails' `email_address`, pass `--email-attribute`:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
bin/rails generate authentication --email-attribute=email
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The name goes into the `users` migration, fixtures, and tests from Rails' own generator, and into
|
|
68
|
+
one method at the top of `User`:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
class User < ApplicationRecord
|
|
72
|
+
def self.authentication_email_column_name = :email
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Every controller, view, mailer, and concern this gem generates reads the column name from there
|
|
76
|
+
instead of naming it: controllers and views through `authentication_email_column_name` on the
|
|
77
|
+
`Authentication` concern, models and mailers through `User.authentication_email_column_name`. To
|
|
78
|
+
rename the column later, change that line and write the migration; Rails' own generated tests and
|
|
79
|
+
fixtures, and its password-reset files if you `--skip-recoverable`, name the column directly and
|
|
80
|
+
need updating by hand. Reconfirmable's column is named once, at generation time, as
|
|
81
|
+
`unconfirmed_<name>` with a trailing `_address` dropped (`email` and `email_address` both give
|
|
82
|
+
`unconfirmed_email`; `login_email` gives `unconfirmed_login_email`).
|
|
83
|
+
|
|
61
84
|
MagicLink, Ott, and Passkey are **opt-in** features — they change the sign-in UX, so you have to
|
|
62
85
|
ask for them:
|
|
63
86
|
|
|
@@ -167,7 +190,8 @@ User.invite!({ email_address: "new@example.com" }, invited_by: Current.user)
|
|
|
167
190
|
User.invite!({ email_address: "new@example.com", name: "Ada Lovelace" }, invited_by: Current.user)
|
|
168
191
|
```
|
|
169
192
|
|
|
170
|
-
|
|
193
|
+
The examples use the default `email_address` column; with `--email-attribute`, use your column's
|
|
194
|
+
name. `invite!` accepts symbol or string keys, or permitted `ActionController::Parameters`. It
|
|
171
195
|
returns the user either way, so check `persisted?` and `errors` to see whether it worked.
|
|
172
196
|
|
|
173
197
|
- **New email address**: the user is built from the attributes and gets a random temporary
|
|
@@ -188,14 +212,14 @@ permitted. Never pass raw `params`.
|
|
|
188
212
|
a hash: `User.invite!({ email_address: email_address }, invited_by: ...)`.
|
|
189
213
|
|
|
190
214
|
**Requiring more than an email address.** The generated `InvitationsController` passes
|
|
191
|
-
`invitation_params` (`params.permit(
|
|
215
|
+
`invitation_params` (`params.permit(authentication_email_column_name)`) to `invite!`. To collect more fields, add
|
|
192
216
|
them in three places: the `permit` list, the inputs in `app/views/invitations/new.html.erb`, and
|
|
193
217
|
the validations on your model:
|
|
194
218
|
|
|
195
219
|
```ruby
|
|
196
220
|
# app/controllers/invitations_controller.rb
|
|
197
221
|
def invitation_params
|
|
198
|
-
params.permit(
|
|
222
|
+
params.permit(authentication_email_column_name, :name)
|
|
199
223
|
end
|
|
200
224
|
```
|
|
201
225
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "rails/generators"
|
|
4
4
|
require "rails/generators/active_record"
|
|
5
|
+
require "active_support/core_ext/string/indent"
|
|
5
6
|
require_relative "features/confirmable"
|
|
6
7
|
require_relative "features/recoverable"
|
|
7
8
|
require_relative "features/registerable"
|
|
@@ -55,6 +56,11 @@ module RailsAuthentication
|
|
|
55
56
|
class_option :"skip_#{feature}", type: :boolean, default: false, desc: "Skip #{feature}"
|
|
56
57
|
end
|
|
57
58
|
|
|
59
|
+
# Rails' base generator calls the column email_address; this renames it everywhere: in
|
|
60
|
+
# the base generator's files (by word-boundary substitution) and in this gem's templates.
|
|
61
|
+
class_option :email_attribute, type: :string, default: "email_address",
|
|
62
|
+
desc: "Name of the users table's email column"
|
|
63
|
+
|
|
58
64
|
class_option :reconfirmable, type: :boolean, default: false,
|
|
59
65
|
desc: "Confirmable: postpone email address changes until reconfirmed (opt-in)"
|
|
60
66
|
|
|
@@ -73,11 +79,29 @@ module RailsAuthentication
|
|
|
73
79
|
class_option :passkey, type: :boolean, default: false,
|
|
74
80
|
desc: "Add WebAuthn passkey sign-in (opt-in; requires the webauthn gem)"
|
|
75
81
|
|
|
82
|
+
# Checked before anything is written: the value becomes a column and method names.
|
|
83
|
+
def validate_email_attribute
|
|
84
|
+
return if email_attribute.match?(/\A[a-z_][a-z0-9_]*\z/)
|
|
85
|
+
|
|
86
|
+
raise Thor::Error, "--email-attribute must be a lowercase Ruby identifier, got #{email_attribute.inspect}"
|
|
87
|
+
end
|
|
88
|
+
|
|
76
89
|
def install_base_authentication
|
|
77
90
|
say "Running Rails' built-in authentication generator", :green
|
|
78
91
|
Rails::Generators.invoke("rails:authentication", [], behavior: behavior, destination_root: destination_root)
|
|
79
92
|
end
|
|
80
93
|
|
|
94
|
+
# Renames the base generator's email_address in the files it wrote (model, create_users
|
|
95
|
+
# migration, fixtures, tests, and the controllers/views/mailer that later steps may or may
|
|
96
|
+
# not replace). Runs before any feature step, so injections see the renamed attribute.
|
|
97
|
+
def rename_email_attribute
|
|
98
|
+
return if email_attribute == "email_address"
|
|
99
|
+
|
|
100
|
+
base_files_with_email_attribute.each do |path|
|
|
101
|
+
gsub_file path, /\bemail_address\b/, email_attribute
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
81
105
|
def install_validatable
|
|
82
106
|
generate_validatable if validatable?
|
|
83
107
|
end
|
|
@@ -126,6 +150,20 @@ module RailsAuthentication
|
|
|
126
150
|
generate_passkey if passkey?
|
|
127
151
|
end
|
|
128
152
|
|
|
153
|
+
# User.authentication_email_column_name is the one place generated code reads the email column's
|
|
154
|
+
# name from. Injected after the feature steps so it lands above their concern includes:
|
|
155
|
+
# Validatable's `validates` runs at include time and needs it. normalizes uses it too.
|
|
156
|
+
def add_authentication_email_column_name
|
|
157
|
+
inject_into_class "app/models/user.rb", "User", <<~RUBY.indent(2)
|
|
158
|
+
# The users table's email column, read by every authentication flow. Defined before
|
|
159
|
+
# the concerns, which use it when they're included.
|
|
160
|
+
def self.authentication_email_column_name = :#{email_attribute}
|
|
161
|
+
|
|
162
|
+
RUBY
|
|
163
|
+
gsub_file "app/models/user.rb", /^ normalizes :#{email_attribute},/,
|
|
164
|
+
" normalizes authentication_email_column_name,"
|
|
165
|
+
end
|
|
166
|
+
|
|
129
167
|
# Runs after every feature install so the blank line separates the concern
|
|
130
168
|
# includes (if any) from the rest of the class body, no matter which features
|
|
131
169
|
# are enabled.
|
|
@@ -148,13 +186,13 @@ module RailsAuthentication
|
|
|
148
186
|
end
|
|
149
187
|
|
|
150
188
|
# The instance-level counterparts of User.available / User.unavailable, from the same
|
|
151
|
-
# enabled features, placed after the base generator's `normalizes
|
|
189
|
+
# enabled features, placed after the base generator's `normalizes` line.
|
|
152
190
|
# active_for_authentication? is Devise's name for the same check.
|
|
153
191
|
def add_user_availability_predicates
|
|
154
192
|
return if availability_checks.empty?
|
|
155
193
|
|
|
156
194
|
inject_into_file "app/models/user.rb", "\n#{user_availability_predicates}",
|
|
157
|
-
after: /^ normalizes
|
|
195
|
+
after: /^ normalizes authentication_email_column_name, .*\n/, force: true
|
|
158
196
|
end
|
|
159
197
|
|
|
160
198
|
# Confirmable, Rememberable, Trackable, Timeoutable, and Lockable all hook into the
|
|
@@ -186,6 +224,33 @@ module RailsAuthentication
|
|
|
186
224
|
"ActiveModel::SecurePassword::MAX_PASSWORD_LENGTH_ALLOWED"
|
|
187
225
|
end
|
|
188
226
|
|
|
227
|
+
def email_attribute
|
|
228
|
+
options[:email_attribute]
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# Reconfirmable's pending-address column. A trailing _address is dropped, so the default
|
|
232
|
+
# email_address (like Devise's email) pairs with unconfirmed_email.
|
|
233
|
+
def unconfirmed_email_attribute
|
|
234
|
+
"unconfirmed_#{email_attribute.delete_suffix('_address')}"
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# The base generator's files that name email_address, relative to destination_root.
|
|
238
|
+
def base_files_with_email_attribute
|
|
239
|
+
paths = %w[
|
|
240
|
+
app/models/user.rb
|
|
241
|
+
app/controllers/sessions_controller.rb
|
|
242
|
+
app/controllers/passwords_controller.rb
|
|
243
|
+
app/mailers/passwords_mailer.rb
|
|
244
|
+
app/views/sessions/new.html.erb
|
|
245
|
+
app/views/passwords/new.html.erb
|
|
246
|
+
test/fixtures/users.yml
|
|
247
|
+
test/models/user_test.rb
|
|
248
|
+
test/controllers/sessions_controller_test.rb
|
|
249
|
+
test/controllers/passwords_controller_test.rb
|
|
250
|
+
] + Dir.glob("db/migrate/*_create_users.rb", base: destination_root)
|
|
251
|
+
paths.select { |path| File.exist?(File.join(destination_root, path)) }
|
|
252
|
+
end
|
|
253
|
+
|
|
189
254
|
def reconfirmable?
|
|
190
255
|
confirmable? && options[:reconfirmable]
|
|
191
256
|
end
|
|
@@ -5,7 +5,7 @@ module Authentication
|
|
|
5
5
|
|
|
6
6
|
included do
|
|
7
7
|
before_action :require_authentication
|
|
8
|
-
helper_method :authenticated?, :current_user
|
|
8
|
+
helper_method :authenticated?, :current_user, :authentication_email_column_name
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
# Every controller requires a signed-in user by default (the before_action above).
|
|
@@ -41,6 +41,11 @@ module Authentication
|
|
|
41
41
|
Current.user
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# The users table's email column, for params, lookups, and form fields. Defined on User.
|
|
45
|
+
def authentication_email_column_name
|
|
46
|
+
User.authentication_email_column_name
|
|
47
|
+
end
|
|
48
|
+
|
|
44
49
|
def require_authentication
|
|
45
50
|
resume_session || request_authentication
|
|
46
51
|
end
|
|
@@ -10,9 +10,9 @@ class ConfirmationsController < ApplicationController
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def create
|
|
13
|
-
user = User.find_by(
|
|
13
|
+
user = User.find_by(authentication_email_column_name => params[authentication_email_column_name])
|
|
14
14
|
<% if reconfirmable? -%>
|
|
15
|
-
user.send_confirmation_instructions if user && (!user.confirmed? || user
|
|
15
|
+
user.send_confirmation_instructions if user && (!user.confirmed? || user.<%= unconfirmed_email_attribute %>.present?)
|
|
16
16
|
<% else -%>
|
|
17
17
|
user.send_confirmation_instructions if user && !user.confirmed?
|
|
18
18
|
<% end -%>
|
|
@@ -11,7 +11,7 @@ class InvitationsController < ApplicationController
|
|
|
11
11
|
user = User.invite!(invitation_params, invited_by: Current.user)
|
|
12
12
|
|
|
13
13
|
if user.persisted?
|
|
14
|
-
redirect_to new_invitation_path, notice: t("flash.invitations.create.notice",
|
|
14
|
+
redirect_to new_invitation_path, notice: t("flash.invitations.create.notice", email: user[authentication_email_column_name])
|
|
15
15
|
else
|
|
16
16
|
redirect_to new_invitation_path, alert: user.errors.full_messages.to_sentence
|
|
17
17
|
end
|
|
@@ -33,7 +33,7 @@ class InvitationsController < ApplicationController
|
|
|
33
33
|
|
|
34
34
|
# Add any other attributes your User requires (e.g. :name) here and to the invitation form.
|
|
35
35
|
def invitation_params
|
|
36
|
-
params.permit(
|
|
36
|
+
params.permit(authentication_email_column_name)
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def set_user_by_token
|
|
@@ -8,7 +8,7 @@ class MagicLinksController < ApplicationController
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def create
|
|
11
|
-
user = User.find_by(
|
|
11
|
+
user = User.find_by(authentication_email_column_name => params[authentication_email_column_name])
|
|
12
12
|
user&.send_magic_link
|
|
13
13
|
|
|
14
14
|
redirect_to new_session_path, notice: t("flash.magic_links.create.notice")
|
|
@@ -6,20 +6,20 @@ class OttsController < ApplicationController
|
|
|
6
6
|
rate_limit to: 10, within: 3.minutes, only: :update, with: -> { redirect_to new_session_path, alert: t("flash.otts.update.alert.rate_limited") }
|
|
7
7
|
|
|
8
8
|
def create
|
|
9
|
-
|
|
10
|
-
user = User.find_by(
|
|
9
|
+
email = params[authentication_email_column_name].presence || session[:ott_email]
|
|
10
|
+
user = User.find_by(authentication_email_column_name => email)
|
|
11
11
|
user&.send_ott
|
|
12
|
-
session[:
|
|
12
|
+
session[:ott_email] = email
|
|
13
13
|
|
|
14
14
|
redirect_to edit_ott_path, notice: t("flash.otts.create.notice")
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def edit
|
|
18
|
-
redirect_to new_session_path if session[:
|
|
18
|
+
redirect_to new_session_path if session[:ott_email].blank?
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def update
|
|
22
|
-
user = User.find_by(
|
|
22
|
+
user = User.find_by(authentication_email_column_name => session[:ott_email])
|
|
23
23
|
|
|
24
24
|
case user && user.verify_ott(params[:code])
|
|
25
25
|
when nil, :expired
|
|
@@ -75,7 +75,7 @@ class OttsController < ApplicationController
|
|
|
75
75
|
# end
|
|
76
76
|
|
|
77
77
|
user.consume_ott!
|
|
78
|
-
session.delete(:
|
|
78
|
+
session.delete(:ott_email)
|
|
79
79
|
<% if lockable? -%>
|
|
80
80
|
user.reset_failed_attempts!
|
|
81
81
|
<% end -%>
|
|
@@ -9,7 +9,7 @@ class PasswordsController < ApplicationController
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
def create
|
|
12
|
-
if user = User.find_by(
|
|
12
|
+
if user = User.find_by(authentication_email_column_name => params[authentication_email_column_name])
|
|
13
13
|
user.send_reset_password_instructions
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -47,7 +47,7 @@ class RegistrationsController < ApplicationController
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
49
|
def user_params
|
|
50
|
-
params.permit(
|
|
50
|
+
params.permit(authentication_email_column_name, :password, :password_confirmation)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def user_params_for_update
|
|
@@ -12,11 +12,11 @@ class SessionsController < ApplicationController
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def create
|
|
15
|
-
user = User.authenticate_by(params.permit(
|
|
15
|
+
user = User.authenticate_by(params.permit(authentication_email_column_name, :password))
|
|
16
16
|
|
|
17
17
|
if user.nil?
|
|
18
18
|
<% if lockable? || trackable? -%>
|
|
19
|
-
account = User.find_by(
|
|
19
|
+
account = User.find_by(authentication_email_column_name => params[authentication_email_column_name])
|
|
20
20
|
<% end -%>
|
|
21
21
|
<% if lockable? -%>
|
|
22
22
|
account&.register_failed_attempt!
|
|
@@ -8,7 +8,7 @@ class UnlocksController < ApplicationController
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def create
|
|
11
|
-
user = User.find_by(
|
|
11
|
+
user = User.find_by(authentication_email_column_name => params[authentication_email_column_name])
|
|
12
12
|
user.send_unlock_instructions if user&.locked?
|
|
13
13
|
|
|
14
14
|
redirect_to new_session_path, notice: t("flash.unlocks.create.notice")
|
data/lib/generators/authentication/templates/app/controllers/webauthn_credentials_controller.rb.tt
CHANGED
|
@@ -9,7 +9,7 @@ class WebauthnCredentialsController < ApplicationController
|
|
|
9
9
|
|
|
10
10
|
def new
|
|
11
11
|
@webauthn_credential_options = WebAuthn::Credential.options_for_create(
|
|
12
|
-
user: { id: current_user.webauthn_id, name: current_user
|
|
12
|
+
user: { id: current_user.webauthn_id, name: current_user[authentication_email_column_name] },
|
|
13
13
|
exclude: current_user.webauthn_credentials.pluck(:external_id)
|
|
14
14
|
)
|
|
15
15
|
session[:webauthn_registration_challenge] = @webauthn_credential_options.challenge
|
|
@@ -4,9 +4,9 @@ class ConfirmationsMailer < ApplicationMailer
|
|
|
4
4
|
def confirmation_instructions(user)
|
|
5
5
|
@user = user
|
|
6
6
|
<% if reconfirmable? -%>
|
|
7
|
-
mail subject: t('confirmations_mailer.confirmation_instructions.subject'), to: user
|
|
7
|
+
mail subject: t('confirmations_mailer.confirmation_instructions.subject'), to: user.<%= unconfirmed_email_attribute %>.presence || user[User.authentication_email_column_name]
|
|
8
8
|
<% else -%>
|
|
9
|
-
mail subject: t('confirmations_mailer.confirmation_instructions.subject'), to: user.
|
|
9
|
+
mail subject: t('confirmations_mailer.confirmation_instructions.subject'), to: user[User.authentication_email_column_name]
|
|
10
10
|
<% end -%>
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
class InvitationsMailer < ApplicationMailer
|
|
4
4
|
def invitation_instructions(user)
|
|
5
5
|
@user = user
|
|
6
|
-
mail subject: t('invitations_mailer.invitation_instructions.subject'), to: user.
|
|
6
|
+
mail subject: t('invitations_mailer.invitation_instructions.subject'), to: user[User.authentication_email_column_name]
|
|
7
7
|
end
|
|
8
8
|
end
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
class MagicLinksMailer < ApplicationMailer
|
|
4
4
|
def magic_link(user)
|
|
5
5
|
@user = user
|
|
6
|
-
mail subject: t('magic_links_mailer.magic_link.subject'), to: user.
|
|
6
|
+
mail subject: t('magic_links_mailer.magic_link.subject'), to: user[User.authentication_email_column_name]
|
|
7
7
|
end
|
|
8
8
|
end
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
class UnlocksMailer < ApplicationMailer
|
|
4
4
|
def unlock_instructions(user)
|
|
5
5
|
@user = user
|
|
6
|
-
mail subject: t('unlocks_mailer.unlock_instructions.subject'), to: user.
|
|
6
|
+
mail subject: t('unlocks_mailer.unlock_instructions.subject'), to: user[User.authentication_email_column_name]
|
|
7
7
|
end
|
|
8
8
|
end
|
|
@@ -7,8 +7,8 @@ module ConfirmableConcern
|
|
|
7
7
|
|
|
8
8
|
included do
|
|
9
9
|
<% if reconfirmable? -%>
|
|
10
|
-
before_update :
|
|
11
|
-
after_update_commit :deliver_reconfirmation_instructions, if: -> {
|
|
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
12
|
|
|
13
13
|
<% end -%>
|
|
14
14
|
scope :confirmed, -> { where.not(confirmed_at: nil) }
|
|
@@ -31,8 +31,8 @@ module ConfirmableConcern
|
|
|
31
31
|
def confirm!
|
|
32
32
|
<% if reconfirmable? -%>
|
|
33
33
|
@confirming = true
|
|
34
|
-
self.
|
|
35
|
-
self
|
|
34
|
+
self[self.class.authentication_email_column_name] = <%= unconfirmed_email_attribute %> if <%= unconfirmed_email_attribute %>.present?
|
|
35
|
+
self.<%= unconfirmed_email_attribute %> = nil
|
|
36
36
|
self.confirmed_at = Time.current
|
|
37
37
|
self.confirmation_token = nil
|
|
38
38
|
self.confirmation_sent_at = nil
|
|
@@ -62,13 +62,13 @@ module ConfirmableConcern
|
|
|
62
62
|
|
|
63
63
|
private
|
|
64
64
|
|
|
65
|
-
def
|
|
66
|
-
!@confirming &&
|
|
65
|
+
def postponing_email_change?
|
|
66
|
+
!@confirming && attribute_changed?(self.class.authentication_email_column_name) && confirmed?
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
def
|
|
70
|
-
self
|
|
71
|
-
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)
|
|
72
72
|
self.confirmation_token = generate_confirmable_token
|
|
73
73
|
self.confirmation_sent_at = Time.current
|
|
74
74
|
end
|
|
@@ -21,7 +21,7 @@ module InvitableConcern
|
|
|
21
21
|
class_methods do
|
|
22
22
|
def invite!(attributes, invited_by: nil)
|
|
23
23
|
attributes = attributes.to_h.symbolize_keys
|
|
24
|
-
user = find_by(
|
|
24
|
+
user = find_by(authentication_email_column_name => attributes[authentication_email_column_name])
|
|
25
25
|
|
|
26
26
|
if user
|
|
27
27
|
# Re-inviting an existing pending invitee refreshes their token; anyone else
|
|
@@ -12,7 +12,7 @@ module ValidatableConcern
|
|
|
12
12
|
PASSWORD_MINIMUM_COMPLEXITY = 2 # Minimum number of complexities to match to be valid
|
|
13
13
|
|
|
14
14
|
included do
|
|
15
|
-
validates
|
|
15
|
+
validates authentication_email_column_name, presence: true,
|
|
16
16
|
format: { with: EMAIL_ADDRESS_REGEXP },
|
|
17
17
|
uniqueness: { case_sensitive: false }
|
|
18
18
|
validates :password, length: { in: PASSWORD_LENGTH }, allow_nil: true
|
|
@@ -3,6 +3,6 @@
|
|
|
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
|
|
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
7
|
<%%= form.submit t('.form.button.submit') %>
|
|
8
8
|
<%% end %>
|
|
@@ -4,6 +4,6 @@
|
|
|
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
|
|
7
|
+
<%%= form.email_field authentication_email_column_name, required: true, autofocus: true, placeholder: t('.form.input.email.placeholder') %><br>
|
|
8
8
|
<%%= form.submit t('.form.button.submit') %>
|
|
9
9
|
<%% end %>
|
|
@@ -4,7 +4,7 @@
|
|
|
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
|
|
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
8
|
<%%= form.submit t('.form.button.submit') %>
|
|
9
9
|
<%% end %>
|
|
10
10
|
<br>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<%%= tag.div(flash[:notice], style: "color:green") if flash[:notice] %>
|
|
5
5
|
|
|
6
6
|
<p>
|
|
7
|
-
<%%= t('.emailed_code_to', digit_count: OttConcern::OTT_CODE_LENGTH, email: session[:
|
|
7
|
+
<%%= t('.emailed_code_to', digit_count: OttConcern::OTT_CODE_LENGTH, email: session[:ott_email]) %>
|
|
8
8
|
<%%= t('.expires_in', expires_in: distance_of_time_in_words(0, OttConcern::OTT_EXPIRES_IN)) %>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
<%%= tag.div(flash[:alert], style: "color:red") if flash[:alert] %>
|
|
4
4
|
|
|
5
5
|
<%%= form_with url: passwords_path do |form| %>
|
|
6
|
-
<%%= form.email_field
|
|
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
7
|
<%%= form.submit t('.form.button.submit') %>
|
|
8
8
|
<%% end %>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<%% end %>
|
|
13
13
|
|
|
14
14
|
<%%= form_with url: registration_path, method: :patch do |form| %>
|
|
15
|
-
<%%= form.email_field
|
|
15
|
+
<%%= form.email_field authentication_email_column_name, required: true, autocomplete: "username", value: @user[authentication_email_column_name] %><br>
|
|
16
16
|
<%%= form.password_field :password, autocomplete: "new-password", placeholder: t('.form.input.password.placeholder'), maxlength: <%= password_maxlength %> %><br>
|
|
17
17
|
<%%= form.password_field :password_confirmation, autocomplete: "new-password", placeholder: t('.form.input.password_confirmation.placeholder'), maxlength: <%= password_maxlength %> %><br>
|
|
18
18
|
<%%= form.submit t('.form.button.submit') %>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<%% end %>
|
|
12
12
|
|
|
13
13
|
<%%= form_with url: registration_path do |form| %>
|
|
14
|
-
<%%= form.email_field
|
|
14
|
+
<%%= form.email_field authentication_email_column_name, required: true, autofocus: true, autocomplete: "username", placeholder: t('.form.input.email.placeholder'), value: @user[authentication_email_column_name] %><br>
|
|
15
15
|
<%%= form.password_field :password, required: true, autocomplete: "new-password", placeholder: t('.form.input.password.placeholder'), maxlength: <%= password_maxlength %> %><br>
|
|
16
16
|
<%%= form.password_field :password_confirmation, required: true, autocomplete: "new-password", placeholder: t('.form.input.password_confirmation.placeholder'), maxlength: <%= password_maxlength %> %><br>
|
|
17
17
|
<%%= form.submit t('.form.button.submit') %>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<% if ott? -%>
|
|
5
5
|
<%% if params[:with_password].blank? %>
|
|
6
6
|
<%%= form_with url: ott_path do |form| %>
|
|
7
|
-
<%%= form.email_field
|
|
7
|
+
<%%= form.email_field authentication_email_column_name, required: true, autofocus: true, autocomplete: "username", placeholder: t('.ott.form.input.email.placeholder'), value: params[authentication_email_column_name] %><br>
|
|
8
8
|
<%%= form.submit t('.ott.form.button.submit') %>
|
|
9
9
|
<%% end %>
|
|
10
10
|
<br>
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
<%% else %>
|
|
14
14
|
<% end -%>
|
|
15
15
|
<%%= form_with url: session_path do |form| %>
|
|
16
|
-
<%%= form.email_field
|
|
16
|
+
<%%= form.email_field authentication_email_column_name, required: true, autofocus: true, autocomplete: "username", placeholder: t('.session.form.input.email.placeholder'), value: params[authentication_email_column_name] %><br>
|
|
17
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
19
|
<%%= form.check_box :remember_me %> <%%= form.label :remember_me, t('.session.form.input.remember.label') %><br>
|
|
@@ -3,6 +3,6 @@
|
|
|
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
|
|
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
7
|
<%%= form.submit t('.form.button.submit') %>
|
|
8
8
|
<%% end %>
|
|
@@ -4,7 +4,7 @@ class AddConfirmableToUsers < ActiveRecord::Migration<%= migration_version %>
|
|
|
4
4
|
add_column :users, :confirmed_at, :datetime
|
|
5
5
|
add_column :users, :confirmation_sent_at, :datetime
|
|
6
6
|
<% if reconfirmable? -%>
|
|
7
|
-
add_column :users,
|
|
7
|
+
add_column :users, :<%= unconfirmed_email_attribute %>, :string
|
|
8
8
|
<% end -%>
|
|
9
9
|
|
|
10
10
|
add_index :users, :confirmation_token, unique: true
|