rodauth-rails 0.11.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +40 -0
  3. data/README.md +316 -218
  4. data/lib/generators/rodauth/templates/app/lib/rodauth_app.rb +8 -4
  5. data/lib/generators/rodauth/templates/app/models/account.rb +1 -0
  6. data/lib/generators/rodauth/templates/app/views/rodauth/_email_auth_request_form.html.erb +1 -1
  7. data/lib/generators/rodauth/templates/app/views/rodauth/_field.html.erb +2 -2
  8. data/lib/generators/rodauth/templates/app/views/rodauth/_field_error.html.erb +2 -2
  9. data/lib/generators/rodauth/templates/app/views/rodauth/_global_logout_field.html.erb +2 -2
  10. data/lib/generators/rodauth/templates/app/views/rodauth/_login_confirm_field.html.erb +3 -3
  11. data/lib/generators/rodauth/templates/app/views/rodauth/_login_display.html.erb +3 -3
  12. data/lib/generators/rodauth/templates/app/views/rodauth/_login_field.html.erb +3 -3
  13. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb +3 -3
  14. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_footer.html.erb +2 -2
  15. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb +2 -2
  16. data/lib/generators/rodauth/templates/app/views/rodauth/_login_hidden_field.html.erb +1 -1
  17. data/lib/generators/rodauth/templates/app/views/rodauth/_new_password_field.html.erb +3 -3
  18. data/lib/generators/rodauth/templates/app/views/rodauth/_otp_auth_code_field.html.erb +3 -3
  19. data/lib/generators/rodauth/templates/app/views/rodauth/_password_confirm_field.html.erb +3 -3
  20. data/lib/generators/rodauth/templates/app/views/rodauth/_password_field.html.erb +3 -3
  21. data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_code_field.html.erb +3 -3
  22. data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_codes_form.html.erb +4 -4
  23. data/lib/generators/rodauth/templates/app/views/rodauth/_sms_code_field.html.erb +3 -3
  24. data/lib/generators/rodauth/templates/app/views/rodauth/_sms_phone_field.html.erb +3 -3
  25. data/lib/generators/rodauth/templates/app/views/rodauth/_submit.html.erb +1 -1
  26. data/lib/generators/rodauth/templates/app/views/rodauth/add_recovery_codes.html.erb +2 -2
  27. data/lib/generators/rodauth/templates/app/views/rodauth/change_login.html.erb +3 -3
  28. data/lib/generators/rodauth/templates/app/views/rodauth/change_password.html.erb +3 -3
  29. data/lib/generators/rodauth/templates/app/views/rodauth/close_account.html.erb +2 -2
  30. data/lib/generators/rodauth/templates/app/views/rodauth/confirm_password.html.erb +1 -1
  31. data/lib/generators/rodauth/templates/app/views/rodauth/create_account.html.erb +4 -4
  32. data/lib/generators/rodauth/templates/app/views/rodauth/email_auth.html.erb +1 -1
  33. data/lib/generators/rodauth/templates/app/views/rodauth/logout.html.erb +2 -2
  34. data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +1 -1
  35. data/lib/generators/rodauth/templates/app/views/rodauth/otp_auth.html.erb +1 -1
  36. data/lib/generators/rodauth/templates/app/views/rodauth/otp_disable.html.erb +2 -2
  37. data/lib/generators/rodauth/templates/app/views/rodauth/otp_setup.html.erb +9 -9
  38. data/lib/generators/rodauth/templates/app/views/rodauth/recovery_auth.html.erb +1 -1
  39. data/lib/generators/rodauth/templates/app/views/rodauth/remember.html.erb +5 -5
  40. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password.html.erb +2 -2
  41. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password_request.html.erb +2 -2
  42. data/lib/generators/rodauth/templates/app/views/rodauth/sms_auth.html.erb +1 -1
  43. data/lib/generators/rodauth/templates/app/views/rodauth/sms_confirm.html.erb +1 -1
  44. data/lib/generators/rodauth/templates/app/views/rodauth/sms_disable.html.erb +2 -2
  45. data/lib/generators/rodauth/templates/app/views/rodauth/sms_request.html.erb +1 -1
  46. data/lib/generators/rodauth/templates/app/views/rodauth/sms_setup.html.erb +2 -2
  47. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_auth.html.erb +1 -1
  48. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_disable.html.erb +2 -2
  49. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_manage.html.erb +6 -6
  50. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account.html.erb +2 -2
  51. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account_request.html.erb +1 -1
  52. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account.html.erb +3 -3
  53. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account_resend.html.erb +2 -2
  54. data/lib/generators/rodauth/templates/app/views/rodauth/verify_login_change.html.erb +1 -1
  55. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_auth.html.erb +7 -7
  56. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_remove.html.erb +6 -6
  57. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_setup.html.erb +7 -7
  58. data/lib/generators/rodauth/views_generator.rb +26 -4
  59. data/lib/rodauth/rails.rb +32 -13
  60. data/lib/rodauth/rails/auth.rb +9 -12
  61. data/lib/rodauth/rails/feature.rb +19 -230
  62. data/lib/rodauth/rails/feature/base.rb +62 -0
  63. data/lib/rodauth/rails/feature/callbacks.rb +65 -0
  64. data/lib/rodauth/rails/feature/csrf.rb +65 -0
  65. data/lib/rodauth/rails/feature/email.rb +30 -0
  66. data/lib/rodauth/rails/feature/instrumentation.rb +71 -0
  67. data/lib/rodauth/rails/feature/internal_request.rb +50 -0
  68. data/lib/rodauth/rails/feature/render.rb +48 -0
  69. data/lib/rodauth/rails/model.rb +101 -0
  70. data/lib/rodauth/rails/model/associations.rb +195 -0
  71. data/lib/rodauth/rails/railtie.rb +0 -5
  72. data/lib/rodauth/rails/tasks.rake +5 -5
  73. data/lib/rodauth/rails/version.rb +1 -1
  74. data/rodauth-rails.gemspec +4 -1
  75. metadata +56 -6
  76. data/lib/rodauth/rails/log_subscriber.rb +0 -34
@@ -0,0 +1,195 @@
1
+ module Rodauth
2
+ module Rails
3
+ class Model
4
+ class Associations
5
+ attr_reader :rodauth
6
+
7
+ def self.call(rodauth)
8
+ new(rodauth).call
9
+ end
10
+
11
+ def initialize(rodauth)
12
+ @rodauth = rodauth
13
+ end
14
+
15
+ def call
16
+ rodauth.features
17
+ .select { |feature| respond_to?(feature, true) }
18
+ .flat_map { |feature| send(feature) }
19
+ end
20
+
21
+ private
22
+
23
+ def remember
24
+ {
25
+ name: :remember_key,
26
+ type: :has_one,
27
+ table: rodauth.remember_table,
28
+ foreign_key: rodauth.remember_id_column,
29
+ }
30
+ end
31
+
32
+ def verify_account
33
+ {
34
+ name: :verification_key,
35
+ type: :has_one,
36
+ table: rodauth.verify_account_table,
37
+ foreign_key: rodauth.verify_account_id_column,
38
+ }
39
+ end
40
+
41
+ def reset_password
42
+ {
43
+ name: :password_reset_key,
44
+ type: :has_one,
45
+ table: rodauth.reset_password_table,
46
+ foreign_key: rodauth.reset_password_id_column,
47
+ }
48
+ end
49
+
50
+ def verify_login_change
51
+ {
52
+ name: :login_change_key,
53
+ type: :has_one,
54
+ table: rodauth.verify_login_change_table,
55
+ foreign_key: rodauth.verify_login_change_id_column,
56
+ }
57
+ end
58
+
59
+ def lockout
60
+ [
61
+ {
62
+ name: :lockout,
63
+ type: :has_one,
64
+ table: rodauth.account_lockouts_table,
65
+ foreign_key: rodauth.account_lockouts_id_column,
66
+ },
67
+ {
68
+ name: :login_failure,
69
+ type: :has_one,
70
+ table: rodauth.account_login_failures_table,
71
+ foreign_key: rodauth.account_login_failures_id_column,
72
+ }
73
+ ]
74
+ end
75
+
76
+ def email_auth
77
+ {
78
+ name: :email_auth_key,
79
+ type: :has_one,
80
+ table: rodauth.email_auth_table,
81
+ foreign_key: rodauth.email_auth_id_column,
82
+ }
83
+ end
84
+
85
+ def account_expiration
86
+ {
87
+ name: :activity_time,
88
+ type: :has_one,
89
+ table: rodauth.account_activity_table,
90
+ foreign_key: rodauth.account_activity_id_column,
91
+ }
92
+ end
93
+
94
+ def active_sessions
95
+ {
96
+ name: :active_session_keys,
97
+ type: :has_many,
98
+ table: rodauth.active_sessions_table,
99
+ foreign_key: rodauth.active_sessions_account_id_column,
100
+ }
101
+ end
102
+
103
+ def audit_logging
104
+ {
105
+ name: :authentication_audit_logs,
106
+ type: :has_many,
107
+ table: rodauth.audit_logging_table,
108
+ foreign_key: rodauth.audit_logging_account_id_column,
109
+ dependent: nil,
110
+ }
111
+ end
112
+
113
+ def disallow_password_reuse
114
+ {
115
+ name: :previous_password_hashes,
116
+ type: :has_many,
117
+ table: rodauth.previous_password_hash_table,
118
+ foreign_key: rodauth.previous_password_account_id_column,
119
+ }
120
+ end
121
+
122
+ def jwt_refresh
123
+ {
124
+ name: :jwt_refresh_keys,
125
+ type: :has_many,
126
+ table: rodauth.jwt_refresh_token_table,
127
+ foreign_key: rodauth.jwt_refresh_token_account_id_column,
128
+ }
129
+ end
130
+
131
+ def password_expiration
132
+ {
133
+ name: :password_change_time,
134
+ type: :has_one,
135
+ table: rodauth.password_expiration_table,
136
+ foreign_key: rodauth.password_expiration_id_column,
137
+ }
138
+ end
139
+
140
+ def single_session
141
+ {
142
+ name: :session_key,
143
+ type: :has_one,
144
+ table: rodauth.single_session_table,
145
+ foreign_key: rodauth.single_session_id_column,
146
+ }
147
+ end
148
+
149
+ def otp
150
+ {
151
+ name: :otp_key,
152
+ type: :has_one,
153
+ table: rodauth.otp_keys_table,
154
+ foreign_key: rodauth.otp_keys_id_column,
155
+ }
156
+ end
157
+
158
+ def sms_codes
159
+ {
160
+ name: :sms_code,
161
+ type: :has_one,
162
+ table: rodauth.sms_codes_table,
163
+ foreign_key: rodauth.sms_id_column,
164
+ }
165
+ end
166
+
167
+ def recovery_codes
168
+ {
169
+ name: :recovery_codes,
170
+ type: :has_many,
171
+ table: rodauth.recovery_codes_table,
172
+ foreign_key: rodauth.recovery_codes_id_column,
173
+ }
174
+ end
175
+
176
+ def webauthn
177
+ [
178
+ {
179
+ name: :webauthn_user_id,
180
+ type: :has_one,
181
+ table: rodauth.webauthn_user_ids_table,
182
+ foreign_key: rodauth.webauthn_user_ids_account_id_column,
183
+ },
184
+ {
185
+ name: :webauthn_keys,
186
+ type: :has_many,
187
+ table: rodauth.webauthn_keys_table,
188
+ foreign_key: rodauth.webauthn_keys_account_id_column,
189
+ }
190
+ ]
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
@@ -1,6 +1,5 @@
1
1
  require "rodauth/rails/middleware"
2
2
  require "rodauth/rails/controller_methods"
3
- require "rodauth/rails/log_subscriber"
4
3
 
5
4
  require "rails"
6
5
 
@@ -17,10 +16,6 @@ module Rodauth
17
16
  end
18
17
  end
19
18
 
20
- initializer "rodauth.log_subscriber" do
21
- Rodauth::Rails::LogSubscriber.attach_to :rodauth
22
- end
23
-
24
19
  initializer "rodauth.test" do
25
20
  # Rodauth uses RACK_ENV to set the default bcrypt hash cost
26
21
  ENV["RACK_ENV"] = "test" if ::Rails.env.test?
@@ -4,15 +4,15 @@ namespace :rodauth do
4
4
 
5
5
  puts "Routes handled by #{app}:"
6
6
 
7
- app.opts[:rodauths].each_key do |rodauth_name|
8
- rodauth = Rodauth::Rails.rodauth(rodauth_name)
7
+ app.opts[:rodauths].each do |configuration_name, auth_class|
8
+ auth_class.configure { enable :path_class_methods }
9
9
 
10
- routes = rodauth.class.routes.map do |handle_method|
10
+ routes = auth_class.routes.map do |handle_method|
11
11
  path_method = "#{handle_method.to_s.sub(/\Ahandle_/, "")}_path"
12
12
 
13
13
  [
14
- rodauth.public_send(path_method),
15
- "rodauth#{rodauth_name && "(:#{rodauth_name})"}.#{path_method}",
14
+ auth_class.public_send(path_method),
15
+ "rodauth#{configuration_name && "(:#{configuration_name})"}.#{path_method}",
16
16
  ]
17
17
  end
18
18
 
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "0.11.0"
3
+ VERSION = "0.15.0"
4
4
  end
5
5
  end
@@ -17,10 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency "railties", ">= 4.2", "< 7"
20
- spec.add_dependency "rodauth", "~> 2.11"
20
+ spec.add_dependency "rodauth", "~> 2.15"
21
21
  spec.add_dependency "sequel-activerecord_connection", "~> 1.1"
22
22
  spec.add_dependency "tilt"
23
23
  spec.add_dependency "bcrypt"
24
24
 
25
25
  spec.add_development_dependency "jwt"
26
+ spec.add_development_dependency "rotp"
27
+ spec.add_development_dependency "rqrcode"
28
+ spec.add_development_dependency "webauthn" unless RUBY_ENGINE == "jruby"
26
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-06 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.11'
39
+ version: '2.15'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.11'
46
+ version: '2.15'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sequel-activerecord_connection
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,48 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rotp
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rqrcode
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: webauthn
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
103
145
  description: Provides Rails integration for Rodauth.
104
146
  email:
105
147
  - janko.marohnic@gmail.com
@@ -207,8 +249,16 @@ files:
207
249
  - lib/rodauth/rails/auth.rb
208
250
  - lib/rodauth/rails/controller_methods.rb
209
251
  - lib/rodauth/rails/feature.rb
210
- - lib/rodauth/rails/log_subscriber.rb
252
+ - lib/rodauth/rails/feature/base.rb
253
+ - lib/rodauth/rails/feature/callbacks.rb
254
+ - lib/rodauth/rails/feature/csrf.rb
255
+ - lib/rodauth/rails/feature/email.rb
256
+ - lib/rodauth/rails/feature/instrumentation.rb
257
+ - lib/rodauth/rails/feature/internal_request.rb
258
+ - lib/rodauth/rails/feature/render.rb
211
259
  - lib/rodauth/rails/middleware.rb
260
+ - lib/rodauth/rails/model.rb
261
+ - lib/rodauth/rails/model/associations.rb
212
262
  - lib/rodauth/rails/railtie.rb
213
263
  - lib/rodauth/rails/tasks.rake
214
264
  - lib/rodauth/rails/version.rb
@@ -232,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
282
  - !ruby/object:Gem::Version
233
283
  version: '0'
234
284
  requirements: []
235
- rubygems_version: 3.2.3
285
+ rubygems_version: 3.2.15
236
286
  signing_key:
237
287
  specification_version: 4
238
288
  summary: Provides Rails integration for Rodauth.
@@ -1,34 +0,0 @@
1
- module Rodauth
2
- module Rails
3
- class LogSubscriber < ActiveSupport::LogSubscriber
4
- def start_processing(event)
5
- rodauth = event.payload[:rodauth]
6
- app_class = rodauth.scope.class.superclass
7
- format = rodauth.rails_request.format.ref
8
- format = format.to_s.upcase if format.is_a?(Symbol)
9
- format = "*/*" if format.nil?
10
-
11
- info "Processing by #{app_class} as #{format}"
12
- end
13
-
14
- def process_request(event)
15
- status = event.payload[:status]
16
-
17
- additions = ActionController::Base.log_process_action(event.payload)
18
- if ::Rails.gem_version >= Gem::Version.new("6.0")
19
- additions << "Allocations: #{event.allocations}"
20
- end
21
-
22
- message = "Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms"
23
- message << " (#{additions.join(" | ")})"
24
- message << "\n\n" if defined?(::Rails.env) && ::Rails.env.development?
25
-
26
- info message
27
- end
28
-
29
- def logger
30
- ::Rails.logger
31
- end
32
- end
33
- end
34
- end