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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +60 -28
  4. data/lib/generators/rodauth/install_generator.rb +36 -35
  5. data/lib/generators/rodauth/migration/active_record/account_expiration.erb +2 -2
  6. data/lib/generators/rodauth/migration/active_record/active_sessions.erb +4 -4
  7. data/lib/generators/rodauth/migration/active_record/audit_logging.erb +5 -5
  8. data/lib/generators/rodauth/migration/active_record/base.erb +1 -1
  9. data/lib/generators/rodauth/migration/active_record/disallow_password_reuse.erb +2 -2
  10. data/lib/generators/rodauth/migration/active_record/email_auth.erb +3 -2
  11. data/lib/generators/rodauth/migration/active_record/jwt_refresh.erb +3 -3
  12. data/lib/generators/rodauth/migration/active_record/lockout.erb +4 -4
  13. data/lib/generators/rodauth/migration/active_record/otp.erb +3 -3
  14. data/lib/generators/rodauth/migration/active_record/password_expiration.erb +3 -3
  15. data/lib/generators/rodauth/migration/active_record/recovery_codes.erb +2 -2
  16. data/lib/generators/rodauth/migration/active_record/remember.erb +2 -2
  17. data/lib/generators/rodauth/migration/active_record/reset_password.erb +3 -3
  18. data/lib/generators/rodauth/migration/active_record/single_session.erb +2 -2
  19. data/lib/generators/rodauth/migration/active_record/sms_codes.erb +3 -3
  20. data/lib/generators/rodauth/migration/active_record/verify_account.erb +4 -4
  21. data/lib/generators/rodauth/migration/active_record/verify_login_change.erb +2 -2
  22. data/lib/generators/rodauth/migration/active_record/webauthn.erb +5 -5
  23. data/lib/generators/rodauth/migration/sequel/account_expiration.erb +2 -2
  24. data/lib/generators/rodauth/migration/sequel/active_sessions.erb +3 -3
  25. data/lib/generators/rodauth/migration/sequel/audit_logging.erb +3 -3
  26. data/lib/generators/rodauth/migration/sequel/base.erb +1 -1
  27. data/lib/generators/rodauth/migration/sequel/disallow_password_reuse.erb +2 -2
  28. data/lib/generators/rodauth/migration/sequel/email_auth.erb +2 -2
  29. data/lib/generators/rodauth/migration/sequel/jwt_refresh.erb +3 -3
  30. data/lib/generators/rodauth/migration/sequel/lockout.erb +4 -4
  31. data/lib/generators/rodauth/migration/sequel/otp.erb +2 -2
  32. data/lib/generators/rodauth/migration/sequel/password_expiration.erb +2 -2
  33. data/lib/generators/rodauth/migration/sequel/recovery_codes.erb +2 -2
  34. data/lib/generators/rodauth/migration/sequel/remember.erb +2 -2
  35. data/lib/generators/rodauth/migration/sequel/reset_password.erb +2 -2
  36. data/lib/generators/rodauth/migration/sequel/single_session.erb +2 -2
  37. data/lib/generators/rodauth/migration/sequel/sms_codes.erb +2 -2
  38. data/lib/generators/rodauth/migration/sequel/verify_account.erb +2 -2
  39. data/lib/generators/rodauth/migration/sequel/verify_login_change.erb +2 -2
  40. data/lib/generators/rodauth/migration/sequel/webauthn.erb +5 -5
  41. data/lib/generators/rodauth/migration_generator.rb +45 -23
  42. data/lib/generators/rodauth/templates/app/mailers/{rodauth_mailer.rb → rodauth_mailer.rb.tt} +9 -7
  43. data/lib/generators/rodauth/templates/app/misc/{rodauth_main.rb → rodauth_main.rb.tt} +69 -10
  44. data/lib/generators/rodauth/templates/app/models/{account.rb → account.rb.tt} +2 -2
  45. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb +1 -1
  46. data/lib/generators/rodauth/templates/app/views/rodauth/login.html.erb +2 -2
  47. data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +2 -2
  48. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form.html.erb +1 -1
  49. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/login.html.erb +2 -2
  50. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/multi_phase_login.html.erb +2 -2
  51. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_autofill.html.erb +10 -0
  52. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_remove.html.erb +2 -2
  53. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_autofill.html.erb +10 -0
  54. data/lib/generators/rodauth/templates/app/views/rodauth_mailer/unlock_account.text.erb +1 -1
  55. data/lib/generators/rodauth/templates/db/migrate/{create_rodauth.rb → create_rodauth.rb.tt} +1 -1
  56. data/lib/generators/rodauth/templates/test/fixtures/{accounts.yml → accounts.yml.tt} +2 -2
  57. data/lib/generators/rodauth/views_generator.rb +3 -12
  58. data/lib/rodauth/rails/app.rb +18 -1
  59. data/lib/rodauth/rails/feature/base.rb +5 -39
  60. data/lib/rodauth/rails/feature/render.rb +1 -1
  61. data/lib/rodauth/rails/railtie.rb +2 -6
  62. data/lib/rodauth/rails/version.rb +1 -1
  63. data/lib/rodauth/rails.rb +0 -10
  64. data/rodauth-rails.gemspec +2 -2
  65. metadata +17 -18
  66. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb +0 -3
  67. data/lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form_header.html.erb +0 -3
  68. data/lib/generators/rodauth/templates/config/initializers/sequel.rb +0 -4
  69. /data/lib/generators/rodauth/templates/app/controllers/{rodauth_controller.rb → rodauth_controller.rb.tt} +0 -0
  70. /data/lib/generators/rodauth/templates/app/misc/{rodauth_app.rb → rodauth_app.rb.tt} +0 -0
  71. /data/lib/generators/rodauth/templates/config/initializers/{rodauth.rb → rodauth.rb.tt} +0 -0
@@ -23,7 +23,7 @@ module Rodauth
23
23
  default: nil
24
24
 
25
25
  VIEWS = {
26
- login: %w[_login_form _login_form_footer _login_form_header login multi_phase_login],
26
+ login: %w[_login_form _login_form_footer login multi_phase_login],
27
27
  create_account: %w[create_account],
28
28
  logout: %w[logout],
29
29
  reset_password: %w[reset_password_request reset_password],
@@ -40,13 +40,7 @@ module Rodauth
40
40
  sms_codes: %w[sms_setup sms_confirm sms_auth sms_request sms_disable],
41
41
  recovery_codes: %w[recovery_codes add_recovery_codes recovery_auth],
42
42
  webauthn: %w[webauthn_setup webauthn_auth webauthn_remove],
43
- }
44
-
45
- DEPENDENCIES = {
46
- otp: :two_factor_base,
47
- sms_codes: :two_factor_base,
48
- recovery_codes: :two_factor_base,
49
- webauthn: :two_factor_base,
43
+ webauthn_autofill: %w[webauthn_autofill],
50
44
  }
51
45
 
52
46
  def create_views
@@ -65,10 +59,7 @@ module Rodauth
65
59
  private
66
60
 
67
61
  def views
68
- features.inject([]) do |list, feature|
69
- list |= VIEWS.fetch(feature)
70
- list |= VIEWS[DEPENDENCIES[feature]] || []
71
- end
62
+ features.flat_map { |feature| VIEWS.fetch(feature) }
72
63
  end
73
64
 
74
65
  def validate_features
@@ -43,7 +43,7 @@ module Rodauth
43
43
 
44
44
  after do
45
45
  rails_request.commit_flash
46
- end unless ActionPack.version < Gem::Version.new("5.0")
46
+ end
47
47
 
48
48
  def flash
49
49
  rails_request.flash
@@ -82,6 +82,23 @@ module Rodauth
82
82
  super
83
83
  end
84
84
  end
85
+
86
+ # The Rack input might not be rewindable, so ensure we parse the JSON
87
+ # request body in Rails, and avoid parsing it again in Roda.
88
+ def POST
89
+ if content_type =~ /json/
90
+ env["roda.json_params"] = scope.rails_request.POST.to_hash
91
+ end
92
+ super
93
+ end
94
+
95
+ # When calling a Rodauth method that redirects inside the Rails
96
+ # router, Roda's after hook that commits the flash would never get
97
+ # called, so we make sure to commit the flash beforehand.
98
+ def redirect(*)
99
+ scope.rails_request.commit_flash
100
+ super
101
+ end
85
102
  end
86
103
  end
87
104
  end
@@ -13,16 +13,7 @@ module Rodauth
13
13
  end
14
14
 
15
15
  def rails_account
16
- return unless account || logged_in?
17
-
18
- account_from_session unless account
19
-
20
- unless account
21
- clear_session
22
- return
23
- end
24
-
25
- @rails_account ||= instantiate_rails_account
16
+ @rails_account ||= instantiate_rails_account if account!
26
17
  end
27
18
 
28
19
  # Reset Rails session to protect from session fixation attacks.
@@ -41,7 +32,7 @@ module Rodauth
41
32
  end
42
33
 
43
34
  def rails_controller
44
- if only_json? && Rodauth::Rails.api_only?
35
+ if only_json? && ::Rails.application.config.api_only
45
36
  ActionController::API
46
37
  else
47
38
  ActionController::Base
@@ -60,16 +51,6 @@ module Rodauth
60
51
 
61
52
  private
62
53
 
63
- unless ActionPack.version < Gem::Version.new("5.0")
64
- # When calling a Rodauth method that redirects inside the Rails
65
- # router, Roda's after hook that commits the flash would never get
66
- # called, so we make sure to commit the flash beforehand.
67
- def redirect(*)
68
- rails_request.commit_flash
69
- super
70
- end
71
- end
72
-
73
54
  def instantiate_rails_account
74
55
  if defined?(ActiveRecord::Base) && rails_account_model < ActiveRecord::Base
75
56
  rails_account_model.instantiate(account.stringify_keys)
@@ -80,28 +61,13 @@ module Rodauth
80
61
  end
81
62
  end
82
63
 
83
- # Instances of the configured controller with current request's env hash.
64
+ # Instance of the configured controller with current request's env hash.
84
65
  def _rails_controller_instance
85
66
  controller = rails_controller.new
86
- prepare_rails_controller(controller, rails_request)
67
+ controller.set_request! rails_request
68
+ controller.set_response! rails_controller.make_response!(controller.request)
87
69
  controller
88
70
  end
89
-
90
- if ActionPack.version >= Gem::Version.new("5.0")
91
- def prepare_rails_controller(controller, rails_request)
92
- controller.set_request! rails_request
93
- controller.set_response! rails_controller.make_response!(rails_request)
94
- end
95
- else
96
- def prepare_rails_controller(controller, rails_request)
97
- controller.send(:set_response!, rails_request)
98
- controller.instance_variable_set(:@_request, rails_request)
99
- end
100
- end
101
-
102
- def rails_api_controller?
103
- defined?(ActionController::API) && rails_controller <= ActionController::API
104
- end
105
71
  end
106
72
  end
107
73
  end
@@ -32,7 +32,7 @@ module Rodauth
32
32
 
33
33
  # Calls the Rails renderer, returning nil if a template is missing.
34
34
  def rails_render(*args)
35
- return if rails_api_controller?
35
+ return if rails_controller <= ActionController::API
36
36
 
37
37
  rails_controller_instance.render_to_string(*args)
38
38
  rescue ActionView::MissingTemplate
@@ -23,12 +23,8 @@ module Rodauth
23
23
  # Rodauth uses RACK_ENV to set the default bcrypt hash cost
24
24
  ENV["RACK_ENV"] = "test" if ::Rails.env.test?
25
25
 
26
- if ActionPack.version >= Gem::Version.new("5.0")
27
- ActiveSupport.on_load(:action_controller_test_case) do
28
- include Rodauth::Rails::Test::Controller
29
- end
30
- else
31
- ActionController::TestCase.include Rodauth::Rails::Test::Controller
26
+ ActiveSupport.on_load(:action_controller_test_case) do
27
+ include Rodauth::Rails::Test::Controller
32
28
  end
33
29
  end
34
30
 
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "1.7.1"
3
+ VERSION = "1.9.0"
4
4
  end
5
5
  end
data/lib/rodauth/rails.rb CHANGED
@@ -66,16 +66,6 @@ module Rodauth
66
66
  end
67
67
  end
68
68
 
69
- if ::Rails.gem_version >= Gem::Version.new("5.0")
70
- def api_only?
71
- ::Rails.application.config.api_only
72
- end
73
- else
74
- def api_only?
75
- false
76
- end
77
- end
78
-
79
69
  def configure
80
70
  yield self
81
71
  end
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
16
16
  spec.files = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "lib/**/*", "*.gemspec"]
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency "railties", ">= 4.2", "< 8"
20
- spec.add_dependency "rodauth", "~> 2.27"
19
+ spec.add_dependency "railties", ">= 5.0", "< 8"
20
+ spec.add_dependency "rodauth", "~> 2.30"
21
21
  spec.add_dependency "roda", "~> 3.55"
22
22
  spec.add_dependency "sequel-activerecord_connection", "~> 1.1"
23
23
  spec.add_dependency "rodauth-model", "~> 0.2"
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: 1.7.1
4
+ version: 1.9.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: 2023-01-25 00:00:00.000000000 Z
11
+ date: 2023-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '8'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '4.2'
29
+ version: '5.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8'
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.27'
39
+ version: '2.30'
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.27'
46
+ version: '2.30'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: roda
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -219,15 +219,14 @@ files:
219
219
  - lib/generators/rodauth/migration/sequel/webauthn.erb
220
220
  - lib/generators/rodauth/migration_generator.rb
221
221
  - lib/generators/rodauth/templates/INSTRUCTIONS
222
- - lib/generators/rodauth/templates/app/controllers/rodauth_controller.rb
223
- - lib/generators/rodauth/templates/app/mailers/rodauth_mailer.rb
224
- - lib/generators/rodauth/templates/app/misc/rodauth_app.rb
225
- - lib/generators/rodauth/templates/app/misc/rodauth_main.rb
226
- - lib/generators/rodauth/templates/app/models/account.rb
222
+ - lib/generators/rodauth/templates/app/controllers/rodauth_controller.rb.tt
223
+ - lib/generators/rodauth/templates/app/mailers/rodauth_mailer.rb.tt
224
+ - lib/generators/rodauth/templates/app/misc/rodauth_app.rb.tt
225
+ - lib/generators/rodauth/templates/app/misc/rodauth_main.rb.tt
226
+ - lib/generators/rodauth/templates/app/models/account.rb.tt
227
227
  - lib/generators/rodauth/templates/app/views/rodauth/_email_auth_request_form.html.erb
228
228
  - lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb
229
229
  - lib/generators/rodauth/templates/app/views/rodauth/_login_form_footer.html.erb
230
- - lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb
231
230
  - lib/generators/rodauth/templates/app/views/rodauth/add_recovery_codes.html.erb
232
231
  - lib/generators/rodauth/templates/app/views/rodauth/change_login.html.erb
233
232
  - lib/generators/rodauth/templates/app/views/rodauth/change_password.html.erb
@@ -254,7 +253,6 @@ files:
254
253
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/_email_auth_request_form.html.erb
255
254
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form.html.erb
256
255
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form_footer.html.erb
257
- - lib/generators/rodauth/templates/app/views/rodauth/tailwind/_login_form_header.html.erb
258
256
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/add_recovery_codes.html.erb
259
257
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/change_login.html.erb
260
258
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/change_password.html.erb
@@ -287,6 +285,7 @@ files:
287
285
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/verify_account_resend.html.erb
288
286
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/verify_login_change.html.erb
289
287
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_auth.html.erb
288
+ - lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_autofill.html.erb
290
289
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_remove.html.erb
291
290
  - lib/generators/rodauth/templates/app/views/rodauth/tailwind/webauthn_setup.html.erb
292
291
  - lib/generators/rodauth/templates/app/views/rodauth/two_factor_auth.html.erb
@@ -298,6 +297,7 @@ files:
298
297
  - lib/generators/rodauth/templates/app/views/rodauth/verify_account_resend.html.erb
299
298
  - lib/generators/rodauth/templates/app/views/rodauth/verify_login_change.html.erb
300
299
  - lib/generators/rodauth/templates/app/views/rodauth/webauthn_auth.html.erb
300
+ - lib/generators/rodauth/templates/app/views/rodauth/webauthn_autofill.html.erb
301
301
  - lib/generators/rodauth/templates/app/views/rodauth/webauthn_remove.html.erb
302
302
  - lib/generators/rodauth/templates/app/views/rodauth/webauthn_setup.html.erb
303
303
  - lib/generators/rodauth/templates/app/views/rodauth_mailer/email_auth.text.erb
@@ -307,10 +307,9 @@ files:
307
307
  - lib/generators/rodauth/templates/app/views/rodauth_mailer/unlock_account.text.erb
308
308
  - lib/generators/rodauth/templates/app/views/rodauth_mailer/verify_account.text.erb
309
309
  - lib/generators/rodauth/templates/app/views/rodauth_mailer/verify_login_change.text.erb
310
- - lib/generators/rodauth/templates/config/initializers/rodauth.rb
311
- - lib/generators/rodauth/templates/config/initializers/sequel.rb
312
- - lib/generators/rodauth/templates/db/migrate/create_rodauth.rb
313
- - lib/generators/rodauth/templates/test/fixtures/accounts.yml
310
+ - lib/generators/rodauth/templates/config/initializers/rodauth.rb.tt
311
+ - lib/generators/rodauth/templates/db/migrate/create_rodauth.rb.tt
312
+ - lib/generators/rodauth/templates/test/fixtures/accounts.yml.tt
314
313
  - lib/generators/rodauth/views_generator.rb
315
314
  - lib/rodauth-rails.rb
316
315
  - lib/rodauth/rails.rb
@@ -352,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
352
351
  - !ruby/object:Gem::Version
353
352
  version: '0'
354
353
  requirements: []
355
- rubygems_version: 3.4.4
354
+ rubygems_version: 3.4.12
356
355
  signing_key:
357
356
  specification_version: 4
358
357
  summary: Provides Rails integration for Rodauth.
@@ -1,3 +0,0 @@
1
- <% if rodauth.field_error(rodauth.password_param) && rodauth.features.include?(:reset_password) %>
2
- <%= render template: "rodauth/reset_password_request", layout: false %>
3
- <% end %>
@@ -1,3 +0,0 @@
1
- <% if rodauth.field_error(rodauth.password_param) && rodauth.features.include?(:reset_password) %>
2
- <%= render template: "rodauth/reset_password_request", layout: false %>
3
- <% end %>
@@ -1,4 +0,0 @@
1
- require "sequel/core"
2
-
3
- # initialize Sequel and have it reuse Active Record's database connection
4
- DB = Sequel.connect("<%= sequel_uri_scheme %>://", extensions: :activerecord_connection)