rodauth-rails 1.7.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +60 -28
- data/lib/generators/rodauth/install_generator.rb +36 -35
- data/lib/generators/rodauth/migration/active_record/account_expiration.erb +2 -2
- data/lib/generators/rodauth/migration/active_record/active_sessions.erb +4 -4
- data/lib/generators/rodauth/migration/active_record/audit_logging.erb +5 -5
- data/lib/generators/rodauth/migration/active_record/base.erb +1 -1
- data/lib/generators/rodauth/migration/active_record/disallow_password_reuse.erb +2 -2
- data/lib/generators/rodauth/migration/active_record/email_auth.erb +3 -2
- data/lib/generators/rodauth/migration/active_record/jwt_refresh.erb +3 -3
- data/lib/generators/rodauth/migration/active_record/lockout.erb +4 -4
- data/lib/generators/rodauth/migration/active_record/otp.erb +3 -3
- data/lib/generators/rodauth/migration/active_record/password_expiration.erb +3 -3
- data/lib/generators/rodauth/migration/active_record/recovery_codes.erb +2 -2
- data/lib/generators/rodauth/migration/active_record/remember.erb +2 -2
- data/lib/generators/rodauth/migration/active_record/reset_password.erb +3 -3
- data/lib/generators/rodauth/migration/active_record/single_session.erb +2 -2
- data/lib/generators/rodauth/migration/active_record/sms_codes.erb +3 -3
- data/lib/generators/rodauth/migration/active_record/verify_account.erb +4 -4
- data/lib/generators/rodauth/migration/active_record/verify_login_change.erb +2 -2
- data/lib/generators/rodauth/migration/active_record/webauthn.erb +5 -5
- data/lib/generators/rodauth/migration/sequel/account_expiration.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/active_sessions.erb +3 -3
- data/lib/generators/rodauth/migration/sequel/audit_logging.erb +3 -3
- data/lib/generators/rodauth/migration/sequel/base.erb +1 -1
- data/lib/generators/rodauth/migration/sequel/disallow_password_reuse.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/email_auth.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/jwt_refresh.erb +3 -3
- data/lib/generators/rodauth/migration/sequel/lockout.erb +4 -4
- data/lib/generators/rodauth/migration/sequel/otp.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/password_expiration.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/recovery_codes.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/remember.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/reset_password.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/single_session.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/sms_codes.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/verify_account.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/verify_login_change.erb +2 -2
- data/lib/generators/rodauth/migration/sequel/webauthn.erb +5 -5
- data/lib/generators/rodauth/migration_generator.rb +45 -23
- data/lib/generators/rodauth/templates/app/mailers/{rodauth_mailer.rb → rodauth_mailer.rb.tt} +9 -7
- data/lib/generators/rodauth/templates/app/misc/{rodauth_main.rb → rodauth_main.rb.tt} +69 -10
- data/lib/generators/rodauth/templates/app/models/{account.rb → account.rb.tt} +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/login.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/login.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/multi_phase_login.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_autofill.html.erb +10 -0
- data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_remove.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_autofill.html.erb +10 -0
- data/lib/generators/rodauth/templates/app/views/rodauth_mailer/unlock_account.text.erb +1 -1
- data/lib/generators/rodauth/templates/db/migrate/{create_rodauth.rb → create_rodauth.rb.tt} +1 -1
- data/lib/generators/rodauth/templates/test/fixtures/{accounts.yml → accounts.yml.tt} +2 -2
- data/lib/generators/rodauth/views_generator.rb +3 -12
- data/lib/rodauth/rails/app.rb +18 -1
- data/lib/rodauth/rails/feature/base.rb +5 -39
- data/lib/rodauth/rails/feature/render.rb +1 -1
- data/lib/rodauth/rails/railtie.rb +2 -6
- data/lib/rodauth/rails/version.rb +1 -1
- data/lib/rodauth/rails.rb +0 -10
- data/rodauth-rails.gemspec +2 -2
- metadata +17 -18
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb +0 -3
- data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form_header.html.erb +0 -3
- data/lib/generators/rodauth/templates/config/initializers/sequel.rb +0 -4
- /data/lib/generators/rodauth/templates/app/controllers/{rodauth_controller.rb → rodauth_controller.rb.tt} +0 -0
- /data/lib/generators/rodauth/templates/app/misc/{rodauth_app.rb → rodauth_app.rb.tt} +0 -0
- /data/lib/generators/rodauth/templates/config/initializers/{rodauth.rb → rodauth.rb.tt} +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the disallow password reuse feature
|
2
|
-
create_table
|
2
|
+
create_table :<%= table_prefix %>_previous_password_hashes do
|
3
3
|
primary_key :id, type: :Bignum
|
4
|
-
foreign_key
|
4
|
+
foreign_key :<%= table_prefix %>_id, :<%= table_prefix.pluralize %>, type: :Bignum
|
5
5
|
String :password_hash, null: false
|
6
6
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the email auth feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_email_auth_keys do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :key, null: false
|
5
5
|
DateTime :deadline, null: false
|
6
6
|
DateTime :email_last_sent, null: false, default: Sequel::CURRENT_TIMESTAMP
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Used by the jwt refresh feature
|
2
|
-
create_table
|
2
|
+
create_table :<%= table_prefix %>_jwt_refresh_keys do
|
3
3
|
primary_key :id, type: :Bignum
|
4
|
-
foreign_key
|
4
|
+
foreign_key :<%= table_prefix %>_id, :<%= table_prefix.pluralize %>, null: false, type: :Bignum
|
5
5
|
String :key, null: false
|
6
6
|
DateTime :deadline, null: false
|
7
|
-
index
|
7
|
+
index :<%= table_prefix %>_id, name: :<%= table_prefix %>_jwt_rk_<%= table_prefix %>_id_idx
|
8
8
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# Used by the lockout feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_login_failures do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
Integer :number, null: false, default: 1
|
5
5
|
end
|
6
|
-
create_table
|
7
|
-
foreign_key :id,
|
6
|
+
create_table :<%= table_prefix %>_lockouts do
|
7
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
8
8
|
String :key, null: false
|
9
9
|
DateTime :deadline, null: false
|
10
10
|
DateTime :email_last_sent
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the otp feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_otp_keys do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :key, null: false
|
5
5
|
Integer :num_failures, null: false, default: 0
|
6
6
|
Time :last_use, null: false, default: Sequel::CURRENT_TIMESTAMP
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Used by the password expiration feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_password_change_times do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
DateTime :changed_at, null: false, default: Sequel::CURRENT_TIMESTAMP
|
5
5
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the recovery codes feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_recovery_codes do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, type: :Bignum
|
4
4
|
String :code
|
5
5
|
primary_key [:id, :code]
|
6
6
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the remember me feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_remember_keys do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :key, null: false
|
5
5
|
DateTime :deadline, null: false
|
6
6
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the password reset feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_password_reset_keys do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :key, null: false
|
5
5
|
DateTime :deadline, null: false
|
6
6
|
DateTime :email_last_sent, null: false, default: Sequel::CURRENT_TIMESTAMP
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Used by the single session feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_session_keys do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :key, null: false
|
5
5
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the sms codes feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_sms_codes do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :phone_number, null: false
|
5
5
|
Integer :num_failures
|
6
6
|
String :code
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the account verification feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_verification_keys do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :key, null: false
|
5
5
|
DateTime :requested_at, null: false, default: Sequel::CURRENT_TIMESTAMP
|
6
6
|
DateTime :email_last_sent, null: false, default: Sequel::CURRENT_TIMESTAMP
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Used by the verify login change feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_login_change_keys do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :key, null: false
|
5
5
|
String :login, null: false
|
6
6
|
DateTime :deadline, null: false
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# Used by the webauthn feature
|
2
|
-
create_table
|
3
|
-
foreign_key :id,
|
2
|
+
create_table :<%= table_prefix %>_webauthn_user_ids do
|
3
|
+
foreign_key :id, :<%= table_prefix.pluralize %>, primary_key: true, type: :Bignum
|
4
4
|
String :webauthn_id, null: false
|
5
5
|
end
|
6
|
-
create_table
|
7
|
-
foreign_key
|
6
|
+
create_table :<%= table_prefix %>_webauthn_keys do
|
7
|
+
foreign_key :<%= table_prefix %>_id, :<%= table_prefix.pluralize %>, type: :Bignum
|
8
8
|
String :webauthn_id
|
9
9
|
String :public_key, null: false
|
10
10
|
Integer :sign_count, null: false
|
11
11
|
Time :last_use, null: false, default: Sequel::CURRENT_TIMESTAMP
|
12
|
-
primary_key [
|
12
|
+
primary_key [:<%= table_prefix %>_id, :webauthn_id]
|
13
13
|
end
|
@@ -13,6 +13,9 @@ module Rodauth
|
|
13
13
|
desc: "Rodauth features to create tables for (otp, sms_codes, single_session, account_expiration etc.)",
|
14
14
|
default: %w[]
|
15
15
|
|
16
|
+
class_option :prefix, optional: true, type: :string,
|
17
|
+
desc: "Change prefix for generated tables (default: account)"
|
18
|
+
|
16
19
|
class_option :name, optional: true, type: :string,
|
17
20
|
desc: "Name of the generated migration file"
|
18
21
|
|
@@ -22,10 +25,24 @@ module Rodauth
|
|
22
25
|
migration_template "db/migrate/create_rodauth.rb", File.join(db_migrate_path, "#{migration_name}.rb")
|
23
26
|
end
|
24
27
|
|
28
|
+
def show_instructions
|
29
|
+
# skip if called from install generator, it already adds configuration
|
30
|
+
return if current_command_chain.include?(:generate_rodauth_migration)
|
31
|
+
return unless options[:prefix] && behavior == :invoke
|
32
|
+
|
33
|
+
configuration = CONFIGURATION.values_at(*features.map(&:to_sym))
|
34
|
+
.flat_map(&:to_a)
|
35
|
+
.map { |config, format| "#{config} :#{format % { plural: table_prefix.pluralize, singular: table_prefix }}" }
|
36
|
+
.join("\n")
|
37
|
+
.indent(2)
|
38
|
+
|
39
|
+
say "\nAdd the following to your Rodauth configuration:\n\n#{configuration}"
|
40
|
+
end
|
41
|
+
|
25
42
|
private
|
26
43
|
|
27
44
|
def migration_name
|
28
|
-
options[:name] || "
|
45
|
+
options[:name] || ["create_rodauth", *options[:prefix], *features].join("_")
|
29
46
|
end
|
30
47
|
|
31
48
|
def migration_content
|
@@ -64,23 +81,36 @@ module Rodauth
|
|
64
81
|
Dir["#{MIGRATION_DIR}/*.erb"].map { |filename| File.basename(filename, ".erb") }
|
65
82
|
end
|
66
83
|
|
84
|
+
def table_prefix
|
85
|
+
options[:prefix]&.singularize || "account"
|
86
|
+
end
|
87
|
+
|
88
|
+
CONFIGURATION = {
|
89
|
+
base: { accounts_table: "%{plural}" },
|
90
|
+
remember: { remember_table: "%{singular}_remember_keys" },
|
91
|
+
verify_account: { verify_account_table: "%{singular}_verification_keys" },
|
92
|
+
verify_login_change: { verify_login_change_table: "%{singular}_login_change_keys" },
|
93
|
+
reset_password: { reset_password_table: "%{singular}_password_reset_keys" },
|
94
|
+
email_auth: { email_auth_table: "%{singular}_email_auth_keys" },
|
95
|
+
otp: { otp_keys_table: "%{singular}_otp_keys" },
|
96
|
+
sms_codes: { sms_codes_table: "%{singular}_sms_codes" },
|
97
|
+
recovery_codes: { recovery_codes_table: "%{singular}_recovery_codes" },
|
98
|
+
webauthn: { webauthn_keys_table: "%{singular}_webauthn_keys", webauthn_user_ids_table: "%{singular}_webauthn_user_ids", webauthn_keys_account_id_column: "%{singular}_id" },
|
99
|
+
lockout: { account_login_failures_table: "%{singular}_login_failures", account_lockouts_table: "%{singular}_lockouts" },
|
100
|
+
active_sessions: { active_sessions_table: "%{singular}_active_session_keys", active_sessions_account_id_column: "%{singular}_id" },
|
101
|
+
account_expiration: { account_activity_table: "%{singular}_activity_times" },
|
102
|
+
password_expiration: { password_expiration_table: "%{singular}_password_change_times" },
|
103
|
+
single_session: { single_session_table: "%{singular}_session_keys" },
|
104
|
+
audit_logging: { audit_logging_table: "%{singular}_authentication_audit_logs", audit_logging_account_id_column: "%{singular}_id" },
|
105
|
+
disallow_password_reuse: { previous_password_hash_table: "%{singular}_previous_password_hashes", previous_password_account_id_column: "%{singular}_id" },
|
106
|
+
jwt_refresh: { jwt_refresh_token_table: "%{singular}_jwt_refresh_keys", jwt_refresh_token_account_id_column: "%{singular}_id" },
|
107
|
+
}
|
108
|
+
|
67
109
|
if defined?(::ActiveRecord::Railtie) # Active Record
|
68
110
|
include ::ActiveRecord::Generators::Migration
|
69
111
|
|
70
112
|
MIGRATION_DIR = "#{__dir__}/migration/active_record"
|
71
113
|
|
72
|
-
def db_migrate_path
|
73
|
-
return "db/migrate" unless ActiveRecord.version >= Gem::Version.new("5.0")
|
74
|
-
|
75
|
-
super
|
76
|
-
end
|
77
|
-
|
78
|
-
def migration_version
|
79
|
-
return unless ActiveRecord.version >= Gem::Version.new("5.0")
|
80
|
-
|
81
|
-
"[#{ActiveRecord::Migration.current_version}]"
|
82
|
-
end
|
83
|
-
|
84
114
|
def activerecord_adapter
|
85
115
|
if ActiveRecord::Base.respond_to?(:connection_db_config)
|
86
116
|
ActiveRecord::Base.connection_db_config.adapter
|
@@ -108,18 +138,10 @@ module Rodauth
|
|
108
138
|
end
|
109
139
|
end
|
110
140
|
|
111
|
-
def current_timestamp
|
112
|
-
if ActiveRecord.version >= Gem::Version.new("5.0")
|
113
|
-
%(-> { "#{current_timestamp_literal}" })
|
114
|
-
else
|
115
|
-
%(OpenStruct.new(quoted_id: "#{current_timestamp_literal}"))
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
141
|
# Active Record 7+ sets default precision to 6 for timestamp columns,
|
120
142
|
# so we need to ensure we match this when setting the default value.
|
121
|
-
def
|
122
|
-
if ActiveRecord.version >= Gem::Version.new("7.0") &&
|
143
|
+
def current_timestamp
|
144
|
+
if ActiveRecord.version >= Gem::Version.new("7.0") && ["mysql2", "trilogy"].include?(activerecord_adapter) && ActiveRecord::Base.connection.supports_datetime_with_precision?
|
123
145
|
"CURRENT_TIMESTAMP(6)"
|
124
146
|
else
|
125
147
|
"CURRENT_TIMESTAMP"
|
data/lib/generators/rodauth/templates/app/mailers/{rodauth_mailer.rb → rodauth_mailer.rb.tt}
RENAMED
@@ -1,16 +1,18 @@
|
|
1
1
|
class RodauthMailer < ApplicationMailer
|
2
|
+
default to: -> { @rodauth.email_to }, from: -> { @rodauth.email_from }
|
3
|
+
|
2
4
|
def verify_account(name, account_id, key)
|
3
5
|
@rodauth = rodauth(name, account_id) { @verify_account_key_value = key }
|
4
6
|
@account = @rodauth.rails_account
|
5
7
|
|
6
|
-
mail
|
8
|
+
mail subject: @rodauth.email_subject_prefix + @rodauth.verify_account_email_subject
|
7
9
|
end
|
8
10
|
|
9
11
|
def reset_password(name, account_id, key)
|
10
12
|
@rodauth = rodauth(name, account_id) { @reset_password_key_value = key }
|
11
13
|
@account = @rodauth.rails_account
|
12
14
|
|
13
|
-
mail
|
15
|
+
mail subject: @rodauth.email_subject_prefix + @rodauth.reset_password_email_subject
|
14
16
|
end
|
15
17
|
|
16
18
|
def verify_login_change(name, account_id, key)
|
@@ -18,35 +20,35 @@ class RodauthMailer < ApplicationMailer
|
|
18
20
|
@account = @rodauth.rails_account
|
19
21
|
@new_email = @account.login_change_key.login
|
20
22
|
|
21
|
-
mail to: @new_email, subject: @rodauth.verify_login_change_email_subject
|
23
|
+
mail to: @new_email, subject: @rodauth.email_subject_prefix + @rodauth.verify_login_change_email_subject
|
22
24
|
end
|
23
25
|
|
24
26
|
def password_changed(name, account_id)
|
25
27
|
@rodauth = rodauth(name, account_id)
|
26
28
|
@account = @rodauth.rails_account
|
27
29
|
|
28
|
-
mail
|
30
|
+
mail subject: @rodauth.email_subject_prefix + @rodauth.password_changed_email_subject
|
29
31
|
end
|
30
32
|
|
31
33
|
# def reset_password_notify(name, account_id)
|
32
34
|
# @rodauth = rodauth(name, account_id)
|
33
35
|
# @account = @rodauth.rails_account
|
34
36
|
|
35
|
-
# mail
|
37
|
+
# mail subject: @rodauth.email_subject_prefix + @rodauth.reset_password_notify_email_subject
|
36
38
|
# end
|
37
39
|
|
38
40
|
# def email_auth(name, account_id, key)
|
39
41
|
# @rodauth = rodauth(name, account_id) { @email_auth_key_value = key }
|
40
42
|
# @account = @rodauth.rails_account
|
41
43
|
|
42
|
-
# mail
|
44
|
+
# mail subject: @rodauth.email_subject_prefix + @rodauth.email_auth_email_subject
|
43
45
|
# end
|
44
46
|
|
45
47
|
# def unlock_account(name, account_id, key)
|
46
48
|
# @rodauth = rodauth(name, account_id) { @unlock_account_key_value = key }
|
47
49
|
# @account = @rodauth.rails_account
|
48
50
|
|
49
|
-
# mail
|
51
|
+
# mail subject: @rodauth.email_subject_prefix + @rodauth.unlock_account_email_subject
|
50
52
|
# end
|
51
53
|
|
52
54
|
private
|
@@ -1,18 +1,56 @@
|
|
1
|
+
require "sequel/core"
|
2
|
+
|
1
3
|
class RodauthMain < Rodauth::Rails::Auth
|
2
4
|
configure do
|
3
5
|
# List of authentication features that are loaded.
|
4
6
|
enable :create_account, :verify_account, :verify_account_grace_period,
|
5
7
|
:login, :logout<%= ", :remember" unless jwt? %><%= ", :json" if json? %><%= ", :jwt" if jwt? %>,
|
6
8
|
:reset_password, :change_password, :change_password_notify,
|
7
|
-
:change_login, :verify_login_change, :close_account
|
9
|
+
:change_login, :verify_login_change, :close_account<%= ", :argon2" if argon2? %>
|
8
10
|
|
9
11
|
# See the Rodauth documentation for the list of available config options:
|
10
12
|
# http://rodauth.jeremyevans.net/documentation.html
|
11
13
|
|
12
14
|
# ==> General
|
15
|
+
<% if sequel_activerecord_integration? -%>
|
16
|
+
# Initialize Sequel and have it reuse Active Record's database connection.
|
17
|
+
<% if RUBY_ENGINE == "jruby" -%>
|
18
|
+
db Sequel.connect("jdbc:<%= sequel_adapter %>://", extensions: :activerecord_connection, keep_reference: false)
|
19
|
+
<% else -%>
|
20
|
+
db Sequel.<%= sequel_adapter %>(extensions: :activerecord_connection, keep_reference: false)
|
21
|
+
<% end -%>
|
22
|
+
|
23
|
+
<% end -%>
|
24
|
+
# Change prefix of table and foreign key column names from default "account"
|
25
|
+
<% if table -%>
|
26
|
+
accounts_table :<%= table_prefix.pluralize %>
|
27
|
+
verify_account_table :<%= table_prefix %>_verification_keys
|
28
|
+
verify_login_change_table :<%= table_prefix %>_login_change_keys
|
29
|
+
reset_password_table :<%= table_prefix %>_password_reset_keys
|
30
|
+
<% unless jwt? -%>
|
31
|
+
remember_table :<%= table_prefix %>_remember_keys
|
32
|
+
<% end -%>
|
33
|
+
<% else -%>
|
34
|
+
# accounts_table :users
|
35
|
+
# verify_account_table :user_verification_keys
|
36
|
+
# verify_login_change_table :user_login_change_keys
|
37
|
+
# reset_password_table :user_password_reset_keys
|
38
|
+
<% unless jwt? -%>
|
39
|
+
# remember_table :user_remember_keys
|
40
|
+
<% end -%>
|
41
|
+
<% end -%>
|
42
|
+
|
13
43
|
# The secret key used for hashing public-facing tokens for various features.
|
14
44
|
# Defaults to Rails `secret_key_base`, but you can use your own secret key.
|
15
45
|
# hmac_secret "<%= SecureRandom.hex(64) %>"
|
46
|
+
<% if argon2? -%>
|
47
|
+
|
48
|
+
# Use a rotatable password pepper when hashing passwords with Argon2.
|
49
|
+
# argon2_secret "<SECRET_KEY>"
|
50
|
+
|
51
|
+
# Since we're using argon2, prevent loading the bcrypt gem to save memory.
|
52
|
+
require_bcrypt? false
|
53
|
+
<% end -%>
|
16
54
|
<% if jwt? -%>
|
17
55
|
|
18
56
|
# Set JWT secret, which is used to cryptographically protect the token.
|
@@ -28,10 +66,13 @@ class RodauthMain < Rodauth::Rails::Auth
|
|
28
66
|
# require_login_confirmation? false
|
29
67
|
<% end -%>
|
30
68
|
|
31
|
-
#
|
69
|
+
# Use path prefix for all routes.
|
70
|
+
# prefix "/auth"
|
71
|
+
|
72
|
+
# Specify the controller used for view rendering, CSRF, and callbacks.
|
32
73
|
rails_controller { RodauthController }
|
33
74
|
|
34
|
-
# Set
|
75
|
+
# Set in Rodauth controller instance with the title of the current page.
|
35
76
|
title_instance_variable :@page_title
|
36
77
|
|
37
78
|
# Store account status in an integer column without foreign key constraint.
|
@@ -40,14 +81,13 @@ class RodauthMain < Rodauth::Rails::Auth
|
|
40
81
|
# Store password hash in a column instead of a separate table.
|
41
82
|
account_password_hash_column :password_hash
|
42
83
|
|
43
|
-
# Passwords shorter than 8 characters are considered weak according to OWASP.
|
44
|
-
password_minimum_length 8
|
45
|
-
# bcrypt has a maximum input length of 72 bytes, truncating any extra bytes.
|
46
|
-
password_maximum_bytes 72
|
47
|
-
|
48
84
|
# Set password when creating account instead of when verifying.
|
49
85
|
verify_account_set_password? false
|
50
86
|
|
87
|
+
# Change some default param keys.
|
88
|
+
login_param "email"
|
89
|
+
# password_confirm_param "confirm_password"
|
90
|
+
|
51
91
|
# Redirect back to originally requested location after authentication.
|
52
92
|
# login_return_to_requested_location? true
|
53
93
|
# two_factor_auth_return_to_requested_location? true # if using MFA
|
@@ -110,8 +150,27 @@ class RodauthMain < Rodauth::Rails::Auth
|
|
110
150
|
# password_too_short_message { "needs to have at least #{password_minimum_length} characters" }
|
111
151
|
# login_does_not_meet_requirements_message { "invalid email#{", #{login_requirement_message}" if login_requirement_message}" }
|
112
152
|
|
113
|
-
#
|
114
|
-
|
153
|
+
# Passwords shorter than 8 characters are considered weak according to OWASP.
|
154
|
+
password_minimum_length 8
|
155
|
+
<% if argon2? -%>
|
156
|
+
# Having a maximum password length set prevents long password DoS attacks.
|
157
|
+
password_maximum_length 64
|
158
|
+
<% else -%>
|
159
|
+
# bcrypt has a maximum input length of 72 bytes, truncating any extra bytes.
|
160
|
+
password_maximum_bytes 72
|
161
|
+
<% end -%>
|
162
|
+
|
163
|
+
# Custom password complexity requirements (alternative to password_complexity feature).
|
164
|
+
# password_meets_requirements? do |password|
|
165
|
+
# super(password) && password_complex_enough?(password)
|
166
|
+
# end
|
167
|
+
# auth_class_eval do
|
168
|
+
# def password_complex_enough?(password)
|
169
|
+
# return true if password.match?(/\d/) && password.match?(/[^a-zA-Z\d]/)
|
170
|
+
# set_password_requirement_error_message(:password_simple, "requires one number and one special character")
|
171
|
+
# false
|
172
|
+
# end
|
173
|
+
# end
|
115
174
|
<% unless jwt? -%>
|
116
175
|
|
117
176
|
# ==> Remember Feature
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if defined?(ActiveRecord::Railtie) -%>
|
2
|
-
class
|
2
|
+
class <%= table_prefix.camelize %> < ApplicationRecord
|
3
3
|
include Rodauth::Rails.model
|
4
4
|
<% if ActiveRecord.version >= Gem::Version.new("7.0") -%>
|
5
5
|
enum :status, unverified: 1, verified: 2, closed: 3
|
@@ -8,7 +8,7 @@ class Account < ApplicationRecord
|
|
8
8
|
<% end -%>
|
9
9
|
end
|
10
10
|
<% else -%>
|
11
|
-
class
|
11
|
+
class <%= table_prefix.camelize %> < Sequel::Model
|
12
12
|
include Rodauth::Rails.model
|
13
13
|
plugin :enum
|
14
14
|
enum :status, unverified: 1, verified: 2, closed: 3
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<% else %>
|
8
8
|
<div class="form-group mb-3">
|
9
9
|
<%= form.label "login", rodauth.login_label, class: "form-label" %>
|
10
|
-
<%= form.email_field rodauth.login_param, value: params[rodauth.login_param], id: "login", autocomplete:
|
10
|
+
<%= form.email_field rodauth.login_param, value: params[rodauth.login_param], id: "login", autocomplete: rodauth.login_field_autocomplete_value, required: true, class: "form-control #{"is-invalid" if rodauth.field_error(rodauth.login_param)}", aria: ({ invalid: true, describedby: "login_error_message" } if rodauth.field_error(rodauth.login_param)) %>
|
11
11
|
<%= content_tag(:span, rodauth.field_error(rodauth.login_param), class: "invalid-feedback", id: "login_error_message") if rodauth.field_error(rodauth.login_param) %>
|
12
12
|
</div>
|
13
13
|
<% end %>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
1
|
+
<%== rodauth.login_form_header %>
|
2
2
|
<%= render "login_form" %>
|
3
|
-
|
3
|
+
<%== rodauth.login_form_footer %>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
1
|
+
<%== rodauth.login_form_header %>
|
2
2
|
<%== rodauth.render_multi_phase_login_forms %>
|
3
|
-
|
3
|
+
<%== rodauth.login_form_footer %>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<% else %>
|
8
8
|
<div class="mb-6">
|
9
9
|
<%= form.label "login", rodauth.login_label, class: "block text-sm font-semibold" %>
|
10
|
-
<%= form.email_field rodauth.login_param, value: params[rodauth.login_param], id: "login", autocomplete:
|
10
|
+
<%= form.email_field rodauth.login_param, value: params[rodauth.login_param], id: "login", autocomplete: rodauth.login_field_autocomplete_value, required: true, class: "mt-2 text-sm w-full px-3 py-2 border rounded-md dark:bg-gray-900 dark:text-gray-100 dark:focus:bg-gray-800 #{rodauth.field_error(rodauth.login_param) ? "border-red-600 focus:ring-red-600 focus:border-red-600 dark:border-red-400 dark:focus:ring-red-400" : "border-gray-300 dark:border-gray-700 dark:focus:border-emerald-400 dark:focus:ring-emerald-400" }", aria: ({ invalid: true, describedby: "login_error_message" } if rodauth.field_error(rodauth.login_param)) %>
|
11
11
|
<%= content_tag(:span, rodauth.field_error(rodauth.login_param), class: "block mt-1 text-red-600 text-xs dark:text-red-400", id: "login_error_message") if rodauth.field_error(rodauth.login_param) %>
|
12
12
|
</div>
|
13
13
|
<% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% cred = rodauth.webauthn_credential_options_for_get %>
|
2
|
+
|
3
|
+
<%= form_with url: rodauth.webauthn_login_path, method: :post, id: "webauthn-login-form", data: { credential_options: cred.as_json.to_json, turbo: false } do |form| %>
|
4
|
+
<%= form.hidden_field rodauth.webauthn_auth_challenge_param, value: cred.challenge %>
|
5
|
+
<%= form.hidden_field rodauth.webauthn_auth_challenge_hmac_param, value: rodauth.compute_hmac(cred.challenge) %>
|
6
|
+
<%= form.text_field rodauth.webauthn_auth_param, value: "", id: "webauthn-auth", class: "hidden", aria: { hidden: "true" } %>
|
7
|
+
<%= form.submit rodauth.webauthn_auth_button, class: "hidden" %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<%= javascript_include_tag rodauth.webauthn_autofill_js_path, extname: false %>
|
@@ -8,13 +8,13 @@
|
|
8
8
|
<% end %>
|
9
9
|
|
10
10
|
<fieldset class="mb-6">
|
11
|
-
<%
|
11
|
+
<% rodauth.account_webauthn_usage.each do |id, last_use| %>
|
12
12
|
<div class="flex items-center space-x-2">
|
13
13
|
<%= form.radio_button rodauth.webauthn_remove_param, id, id: "webauthn-remove-#{id}", class: "dark:bg-gray-900 dark:border-gray-600 dark:checked:bg-current dark:checked:border-current dark:checked:text-emerald-400 dark:focus:ring-emerald-400 dark:focus:ring-offset-gray-900" %>
|
14
14
|
<%= form.label "webauthn-remove-#{id}", "Last use: #{last_use}", class: "text-sm" %>
|
15
|
-
<%= content_tag(:span, rodauth.field_error(rodauth.webauthn_remove_param), class: "block mt-1 text-red-600 text-xs dark:text-red-400", id: "webauthn_remove_error_message") if rodauth.field_error(rodauth.webauthn_remove_param) && id == usage.keys.last %>
|
16
15
|
</div>
|
17
16
|
<% end %>
|
17
|
+
<%= content_tag(:span, rodauth.field_error(rodauth.webauthn_remove_param), class: "block mt-1 text-red-600 text-xs dark:text-red-400", id: "webauthn_remove_error_message") if rodauth.field_error(rodauth.webauthn_remove_param) %>
|
18
18
|
</fieldset>
|
19
19
|
|
20
20
|
<%= form.submit rodauth.webauthn_remove_button, class: "w-full px-8 py-3 cursor-pointer font-semibold text-sm rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-600 dark:bg-emerald-400 dark:hover:bg-emerald-500 dark:text-gray-900 dark:focus:ring-emerald-400 dark:focus:ring-offset-current" %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% cred = rodauth.webauthn_credential_options_for_get %>
|
2
|
+
|
3
|
+
<%= form_with url: rodauth.webauthn_login_path, method: :post, id: "webauthn-login-form", data: { credential_options: cred.as_json.to_json, turbo: false } do |form| %>
|
4
|
+
<%= form.hidden_field rodauth.webauthn_auth_challenge_param, value: cred.challenge %>
|
5
|
+
<%= form.hidden_field rodauth.webauthn_auth_challenge_hmac_param, value: rodauth.compute_hmac(cred.challenge) %>
|
6
|
+
<%= form.text_field rodauth.webauthn_auth_param, value: "", id: "webauthn-auth", class: "d-none", aria: { hidden: "true" } %>
|
7
|
+
<%= form.submit rodauth.webauthn_auth_button, class: "d-none" %>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<%= javascript_include_tag rodauth.webauthn_autofill_js_path, extname: false %>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Someone has requested
|
1
|
+
Someone has requested that the account with this email be unlocked.
|
2
2
|
If you did not request the unlocking of this account, please ignore this
|
3
3
|
message. If you requested the unlocking of this account, please go to
|
4
4
|
<%= @rodauth.unlock_account_email_link %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<% if defined?(::ActiveRecord::Railtie) -%>
|
2
|
-
class <%= migration_class_name %> < ActiveRecord::Migration<%=
|
2
|
+
class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
3
3
|
def change
|
4
4
|
<%= migration_content -%>
|
5
5
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
2
|
one:
|
3
3
|
email: freddie@queen.com
|
4
|
-
password_hash: <%%=
|
4
|
+
password_hash: <%%= RodauthMain.allocate.password_hash("password") %>
|
5
5
|
status: verified
|
6
6
|
|
7
7
|
two:
|
8
8
|
email: brian@queen.com
|
9
|
-
password_hash: <%%=
|
9
|
+
password_hash: <%%= RodauthMain.allocate.password_hash("password") %>
|
10
10
|
status: verified
|