rodauth-rails 1.15.2 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4347261e8bb70c5e8f8cd218b0485d335eae250b8efc51677acb0bb7625e655b
4
- data.tar.gz: d00e315a95b9c8659c29eec2e1722d95c6b77d7804682c3ad0c70058df1ee709
3
+ metadata.gz: cca905fd1f4b103aef68317cf45c2758d432b32c0f91a50e2f896c83750c4567
4
+ data.tar.gz: 3170987bb8ba8821d66c2ad46369be451069d3cac01d0bcc6aa7f3e149b150f1
5
5
  SHA512:
6
- metadata.gz: 7218d821e3d83d779c40c1ae6a5a0aef7d1ff1e46bb207805f23daf1480f0cdbef19f7e24165d21fc8647bfe9c64973a162d83028a145df60e63c5d2b67ba915
7
- data.tar.gz: c0a318f879f6cf35daade60784e7cc896d061d14c93281475d33831aa95e9377d3664cb3d7e86ab32ed99984ee9f477f37282c204860c8a8cf9ed5ee3cf7ad84
6
+ metadata.gz: 13108dbbf6bedd2201c58b4377defbc9a41fa893c874b5ac833c1fd63d3b2b418dc397c59a50cc1eede6739d5d4e6a9d682e10f5a061645f8cd0eae9ac2cb0cb
7
+ data.tar.gz: d0bec919f0fdadfb978b15c6da1e35ba18a823c27b4e75b715eac536bff8a9f886567b3ff918384594546ed4f31de4897bb886164ebbc0a622cadd7e01b45eb4
data/README.md CHANGED
@@ -90,17 +90,15 @@ $ rails generate rodauth:install users
90
90
  If you want Rodauth endpoints to be exposed via [JSON API]:
91
91
 
92
92
  ```sh
93
- $ rails generate rodauth:install --json # regular authentication using the Rails session
93
+ $ rails generate rodauth:install --json # cookied-based authentication
94
94
  # or
95
- $ rails generate rodauth:install --jwt # token authentication via the "Authorization" header
96
- $ bundle add jwt
95
+ $ rails generate rodauth:install --jwt # token-based authentication
97
96
  ```
98
97
 
99
98
  To use Argon2 instead of bcrypt for password hashing:
100
99
 
101
100
  ```sh
102
101
  $ rails generate rodauth:install --argon2
103
- $ bundle add argon2
104
102
  ```
105
103
 
106
104
  ## Usage
@@ -672,6 +670,11 @@ $ rails middleware
672
670
  # run MyApp::Application.routes
673
671
  ```
674
672
 
673
+ > [!NOTE]
674
+ > If you're using a middleware that should be called before Rodauth routes, make sure that middleware is inserted *before* Rodauth.
675
+ >
676
+ > For example, if you're using [Rack::Attack] to throttle signups, make sure you put the `rack-attack` gem *above* `rodauth-rails` in the Gemfile, so that its middleware is inserted first.
677
+
675
678
  ### Roda app
676
679
 
677
680
  The [`Rodauth::Rails::App`](/lib/rodauth/rails/app.rb) class is a [Roda]
@@ -795,3 +798,4 @@ conduct](CODE_OF_CONDUCT.md).
795
798
  [inheritance]: http://rodauth.jeremyevans.net/rdoc/files/doc/guides/share_configuration_rdoc.html
796
799
  [library]: https://github.com/jeremyevans/rodauth#label-Using+Rodauth+as+a+Library
797
800
  [restoring defaults]: https://github.com/janko/rodauth-rails/wiki/Restoring-Rodauth-Defaults
801
+ [Rack::Attack]: https://github.com/rack/rack-attack
@@ -38,6 +38,22 @@ module Rodauth
38
38
  template "app/misc/rodauth_main.rb"
39
39
  end
40
40
 
41
+ def add_gems
42
+ if activerecord? && !sequel?
43
+ gem "sequel-activerecord_connection", "~> 2.0", comment: "Enables Sequel to use Active Record's database connection"
44
+ gem "after_commit_everywhere", "~> 1.1", comment: "Required for Sequel's transaction hooks to work in all cases (on Active Record < 7.2)" if ActiveRecord.version < Gem::Version.new("7.2")
45
+ end
46
+ if argon2?
47
+ gem "argon2", "~> 2.3", comment: "Used by Rodauth for password hashing"
48
+ else
49
+ gem "bcrypt", "~> 3.1", comment: "Used by Rodauth for password hashing"
50
+ end
51
+ if jwt?
52
+ gem "jwt", "~> 2.9", comment: "Used by Rodauth for JWT support"
53
+ end
54
+ gem "tilt", "~> 2.4", comment: "Used by Rodauth for rendering built-in view and email templates"
55
+ end
56
+
41
57
  def create_rodauth_controller
42
58
  template "app/controllers/rodauth_controller.rb"
43
59
  end
@@ -55,7 +71,7 @@ module Rodauth
55
71
  end
56
72
 
57
73
  def show_instructions
58
- readme "INSTRUCTIONS" if behavior == :invoke && !api_only?
74
+ readme "INSTRUCTIONS" if behavior == :invoke && !json? && !jwt?
59
75
  end
60
76
 
61
77
  private
@@ -83,11 +83,7 @@ module Rodauth
83
83
  end
84
84
 
85
85
  def erb_eval(content)
86
- if ERB.version[/\d+\.\d+\.\d+/].to_s >= "2.2.0"
87
- ERB.new(content, trim_mode: "-").result(binding)
88
- else
89
- ERB.new(content, 0, "-").result(binding)
90
- end
86
+ ERB.new(content, trim_mode: "-").result(binding)
91
87
  end
92
88
 
93
89
  def emails
@@ -7,6 +7,7 @@ create_table :<%= table_prefix.pluralize %><%= primary_key_type %> do |t|
7
7
  <% case activerecord_adapter -%>
8
8
  <% when "postgresql" -%>
9
9
  t.citext :email, null: false
10
+ t.check_constraint "email ~ '^[^,;@ \r\n]+@[^,@; \r\n]+\.[^,@; \r\n]+$'", name: "valid_email"
10
11
  <% else -%>
11
12
  t.string :email, null: false
12
13
  <% end -%>
@@ -54,11 +54,7 @@ module Rodauth
54
54
  end
55
55
 
56
56
  def erb_eval(content)
57
- if ERB.version[/\d+\.\d+\.\d+/].to_s >= "2.2.0"
58
- ERB.new(content, trim_mode: "-").result(binding)
59
- else
60
- ERB.new(content, 0, "-").result(binding)
61
- end
57
+ ERB.new(content, trim_mode: "-").result(binding)
62
58
  end
63
59
 
64
60
  def migration_chunk(feature)
@@ -132,11 +128,7 @@ module Rodauth
132
128
  end
133
129
 
134
130
  def default_primary_key_type
135
- if ActiveRecord.version >= Gem::Version.new("5.1") && activerecord_adapter != "sqlite3"
136
- :bigint
137
- else
138
- :integer
139
- end
131
+ activerecord_adapter == "sqlite3" ? :integer : :bigint
140
132
  end
141
133
 
142
134
  # Active Record 7+ sets default precision to 6 for timestamp columns,
@@ -52,7 +52,6 @@ module Rodauth
52
52
  copy_file view_location(view), "app/views/#{directory}/#{view}.html.erb" do |content|
53
53
  content = content.gsub("rodauth.", "rodauth(:#{configuration_name}).") if configuration_name
54
54
  content = content.gsub("rodauth/", "#{directory}/")
55
- content = form_helpers_compatibility(content) if ActionView.version < Gem::Version.new("5.1")
56
55
  content
57
56
  end
58
57
  end
@@ -103,16 +102,6 @@ module Rodauth
103
102
  options[:name]&.to_sym
104
103
  end
105
104
 
106
- # We need to use the *_tag helpers on versions lower than Rails 5.1.
107
- def form_helpers_compatibility(content)
108
- content
109
- .gsub(/form_with url: (.+) do \|form\|/, 'form_tag \1 do')
110
- .gsub(/form\.(label|submit)/, '\1_tag')
111
- .gsub(/form\.(email|password|text|telephone|hidden)_field (\S+), value:/, '\1_field_tag \2,')
112
- .gsub(/form\.radio_button (\S+), (\S+),/, 'radio_button_tag \1, \2, false,')
113
- .gsub(/form\.check_box (\S+), (.+) /, 'check_box_tag \1, "t", false, \2 ')
114
- end
115
-
116
105
  def view_location(view)
117
106
  if tailwind?
118
107
  "app/views/rodauth/tailwind/#{view}.html.erb"
@@ -4,14 +4,10 @@ module Rodauth
4
4
  def self.included(controller)
5
5
  # ActionController::API doesn't have helper methods
6
6
  if controller.respond_to?(:helper_method)
7
- controller.helper_method :rodauth, :current_account
7
+ controller.helper_method :rodauth
8
8
  end
9
9
  end
10
10
 
11
- def current_account(name = nil)
12
- rodauth(name).rails_account
13
- end
14
-
15
11
  def rodauth(name = nil)
16
12
  request.env.fetch ["rodauth", *name].join(".")
17
13
  end
@@ -12,20 +12,18 @@ module Rodauth
12
12
 
13
13
  # Create emails with ActionMailer which uses configured delivery method.
14
14
  def create_email_to(to, subject, body)
15
- Mailer.create_email(to: to, from: email_from, subject: "#{email_subject_prefix}#{subject}", body: body)
15
+ Rodauth::Rails::Mailer.create_email(
16
+ to: to,
17
+ from: email_from,
18
+ subject: "#{email_subject_prefix}#{subject}",
19
+ body: body
20
+ )
16
21
  end
17
22
 
18
23
  # Delivers the given email.
19
24
  def send_email(email)
20
25
  email.deliver_now
21
26
  end
22
-
23
- # ActionMailer subclass for correct email delivering.
24
- class Mailer < ActionMailer::Base
25
- def create_email(options)
26
- mail(options)
27
- end
28
- end
29
27
  end
30
28
  end
31
29
  end
@@ -80,7 +80,7 @@ module Rodauth
80
80
  response
81
81
  end
82
82
 
83
- if ActionPack.version >= Gem::Version.new("8.0.0.beta1")
83
+ if ActionPack.version >= Gem::Version.new("8.0")
84
84
  def rails_benchmark(&block)
85
85
  ActiveSupport::Benchmark.realtime(:float_millisecond, &block)
86
86
  end
@@ -0,0 +1,9 @@
1
+ module Rodauth
2
+ module Rails
3
+ class Mailer < ActionMailer::Base
4
+ def create_email(options)
5
+ mail(options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "1.15.2"
3
+ VERSION = "2.0.1"
4
4
  end
5
5
  end
data/lib/rodauth/rails.rb CHANGED
@@ -7,10 +7,10 @@ module Rodauth
7
7
  class Error < StandardError
8
8
  end
9
9
 
10
- # This allows the developer to avoid loading Rodauth at boot time.
10
+ # This allows avoiding loading Rodauth at boot time.
11
11
  autoload :App, "rodauth/rails/app"
12
12
  autoload :Auth, "rodauth/rails/auth"
13
- autoload :Model, "rodauth/rails/model"
13
+ autoload :Mailer, "rodauth/rails/mailer"
14
14
 
15
15
  @app = nil
16
16
  @middleware = true
@@ -66,15 +66,6 @@ module Rodauth
66
66
  end
67
67
  end
68
68
 
69
- def authenticated(name = nil, &condition)
70
- warn "Rodauth::Rails.authenticated has been deprecated in favor of Rodauth::Rails.authenticate, which additionally requires existence of the account record."
71
- lambda do |request|
72
- rodauth = request.env.fetch ["rodauth", *name].join(".")
73
- rodauth.require_authentication
74
- rodauth.authenticated? && (condition.nil? || condition.call(rodauth))
75
- end
76
- end
77
-
78
69
  if ::Rails.gem_version >= Gem::Version.new("5.2")
79
70
  def secret_key_base
80
71
  ::Rails.application.secret_key_base
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = "https://github.com/janko/rodauth-rails"
12
12
  spec.license = "MIT"
13
13
 
14
- spec.required_ruby_version = ">= 2.5"
14
+ spec.required_ruby_version = ">= 2.6"
15
15
 
16
16
  spec.files = Dir["README.md", "LICENSE.txt", "lib/**/*", "*.gemspec"]
17
17
  spec.require_paths = ["lib"]
@@ -19,11 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.add_dependency "railties", ">= 5.0", "< 8.1"
20
20
  spec.add_dependency "rodauth", "~> 2.36"
21
21
  spec.add_dependency "roda", "~> 3.76"
22
- spec.add_dependency "sequel-activerecord_connection", "~> 1.1"
23
22
  spec.add_dependency "rodauth-model", "~> 0.2"
24
- spec.add_dependency "tilt"
25
- spec.add_dependency "bcrypt"
26
23
 
24
+ spec.add_development_dependency "tilt"
25
+ spec.add_development_dependency "bcrypt", "~> 3.1"
27
26
  spec.add_development_dependency "jwt"
28
27
  spec.add_development_dependency "rotp"
29
28
  spec.add_development_dependency "rqrcode"
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.15.2
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-08 00:00:00.000000000 Z
11
+ date: 2024-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -58,20 +58,6 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '3.76'
61
- - !ruby/object:Gem::Dependency
62
- name: sequel-activerecord_connection
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1.1'
68
- type: :runtime
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1.1'
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: rodauth-model
77
63
  requirement: !ruby/object:Gem::Requirement
@@ -93,7 +79,7 @@ dependencies:
93
79
  - - ">="
94
80
  - !ruby/object:Gem::Version
95
81
  version: '0'
96
- type: :runtime
82
+ type: :development
97
83
  prerelease: false
98
84
  version_requirements: !ruby/object:Gem::Requirement
99
85
  requirements:
@@ -104,16 +90,16 @@ dependencies:
104
90
  name: bcrypt
105
91
  requirement: !ruby/object:Gem::Requirement
106
92
  requirements:
107
- - - ">="
93
+ - - "~>"
108
94
  - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :runtime
95
+ version: '3.1'
96
+ type: :development
111
97
  prerelease: false
112
98
  version_requirements: !ruby/object:Gem::Requirement
113
99
  requirements:
114
- - - ">="
100
+ - - "~>"
115
101
  - !ruby/object:Gem::Version
116
- version: '0'
102
+ version: '3.1'
117
103
  - !ruby/object:Gem::Dependency
118
104
  name: jwt
119
105
  requirement: !ruby/object:Gem::Requirement
@@ -351,8 +337,8 @@ files:
351
337
  - lib/rodauth/rails/feature/instrumentation.rb
352
338
  - lib/rodauth/rails/feature/internal_request.rb
353
339
  - lib/rodauth/rails/feature/render.rb
340
+ - lib/rodauth/rails/mailer.rb
354
341
  - lib/rodauth/rails/middleware.rb
355
- - lib/rodauth/rails/model.rb
356
342
  - lib/rodauth/rails/railtie.rb
357
343
  - lib/rodauth/rails/tasks.rake
358
344
  - lib/rodauth/rails/tasks/routes.rb
@@ -372,14 +358,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
372
358
  requirements:
373
359
  - - ">="
374
360
  - !ruby/object:Gem::Version
375
- version: '2.5'
361
+ version: '2.6'
376
362
  required_rubygems_version: !ruby/object:Gem::Requirement
377
363
  requirements:
378
364
  - - ">="
379
365
  - !ruby/object:Gem::Version
380
366
  version: '0'
381
367
  requirements: []
382
- rubygems_version: 3.5.11
368
+ rubygems_version: 3.5.22
383
369
  signing_key:
384
370
  specification_version: 4
385
371
  summary: Provides Rails integration for Rodauth authentication framework.
@@ -1,6 +0,0 @@
1
- module Rodauth
2
- module Rails
3
- Model = Rodauth::Model
4
- deprecate_constant :Model
5
- end
6
- end