rodauth 2.44.0 → 2.45.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 040bf69b63cc893df29a1a4e5c99889f5dc7fcae928c81639be5a38157dc910e
4
- data.tar.gz: 0f013ee9f86f80379fe575251697fc622f9c0d9ede248e39df67565312edc6eb
3
+ metadata.gz: 5dea248f50448b260c6d0007d8bc4054f17794270e857a6310b969ba58105fbf
4
+ data.tar.gz: 875dbda4ddd85b04041a8e854e0adb09b466269ecef74dd1a73f384519d54553
5
5
  SHA512:
6
- metadata.gz: a9d5ec9033e65cd7578dad8864eb5fcfb258f7ba4484e949923a3502e2e642a77898a01fa2dbb0947d92c4ce009e9b238d5e11a7243cf7f25ad566e9c38c6d72
7
- data.tar.gz: 2fb3aafcb91f26560370059512bb074122bb87267c7d50c27aa465a2ede5b0380dec0d0d17cb946121ca83a28716ffad02427bc83ae9c4959c44f5bc82a21bb9
6
+ metadata.gz: dbf7c82f8b1c93496c59225891c1d747f317eaf46d8283f9c6f2d0562a48aaaec4d6491ed7567011356914fb4498e0f86576c230e183cf53c0ac7a7c5f27d99a
7
+ data.tar.gz: c8c2a228ce0395e4e14dbd1a69b01f7038b2ac94267b33bc5695d11b3eae6a278846be5100714dc18b0a65010db1693c0621f9ec1f2d0ba0793e92b61a698bf9
@@ -35,7 +35,7 @@ module Rodauth
35
35
  auth_value_method :accounts_table, :accounts
36
36
  auth_value_method :cache_templates, true
37
37
  auth_value_method :check_csrf_block, nil
38
- auth_value_method :check_csrf_opts, {}.freeze
38
+ auth_value_method :check_csrf_opts, OPTS
39
39
  auth_value_method :default_redirect, '/'
40
40
  auth_value_method :convert_token_id_to_integer?, nil
41
41
  flash_key :flash_error_key, :error
@@ -73,9 +73,10 @@ module Rodauth
73
73
  auth_value_method :mark_input_fields_with_inputmode?, true
74
74
  auth_value_method :skip_status_checks?, true
75
75
  translatable_method :strftime_format, '%F %T'
76
- auth_value_method :template_opts, {}.freeze
76
+ auth_value_method :template_opts, OPTS
77
77
  auth_value_method :title_instance_variable, nil
78
78
  auth_value_method :token_separator, "_"
79
+ auth_value_method :transaction_opts, OPTS
79
80
  auth_value_method :unmatched_field_error_status, 422
80
81
  auth_value_method :unopen_account_error_status, 403
81
82
  translatable_method :unverified_account_message, "unverified account, please verify account before logging in"
@@ -107,6 +108,7 @@ module Rodauth
107
108
  :check_csrf,
108
109
  :clear_session,
109
110
  :clear_tokens,
111
+ :convert_token_id,
110
112
  :csrf_tag,
111
113
  :function_name,
112
114
  :hook_action,
@@ -135,7 +137,6 @@ module Rodauth
135
137
  :account_from_id,
136
138
  :account_from_login,
137
139
  :account_from_session,
138
- :convert_token_id,
139
140
  :field_attributes,
140
141
  :field_error_attributes,
141
142
  :formatted_field_error,
@@ -218,7 +219,7 @@ module Rodauth
218
219
  end
219
220
  end
220
221
 
221
- def input_field_string(param, id, opts={})
222
+ def input_field_string(param, id, opts=OPTS)
222
223
  type = opts.fetch(:type, "text")
223
224
 
224
225
  unless type == "password"
@@ -449,7 +450,7 @@ module Rodauth
449
450
  _template_opts(opts, 'button')
450
451
  end
451
452
 
452
- def button(value, opts={})
453
+ def button(value, opts=OPTS)
453
454
  scope.render(button_opts(value, opts))
454
455
  end
455
456
 
@@ -696,17 +697,18 @@ module Rodauth
696
697
  request.halt
697
698
  end
698
699
 
699
- def route_path(route, opts={})
700
+ def route_path(route, opts=OPTS)
700
701
  path = "#{prefix}/#{route}"
701
702
  path += "?#{Rack::Utils.build_nested_query(opts)}" unless opts.empty?
702
703
  path
703
704
  end
704
705
 
705
- def route_url(route, opts={})
706
+ def route_url(route, opts=OPTS)
706
707
  "#{base_url}#{route_path(route, opts)}"
707
708
  end
708
709
 
709
- def transaction(opts={}, &block)
710
+ def transaction(opts=OPTS, &block)
711
+ opts = opts.empty? ? transaction_opts : transaction_opts.merge(opts)
710
712
  db.transaction(opts, &block)
711
713
  end
712
714
 
@@ -966,6 +968,14 @@ module Rodauth
966
968
  false
967
969
  end
968
970
 
971
+ # :nocov:
972
+ if RUBY_VERSION >= '4.0'
973
+ # :nocov:
974
+ def instance_variables_to_inspect
975
+ instance_variables.reject{|v| instance_variable_get(v).nil?}
976
+ end
977
+ end
978
+
969
979
  def use_scope_clear_session?
970
980
  scope.respond_to?(:clear_session)
971
981
  end
@@ -318,7 +318,7 @@ module Rodauth
318
318
  ]
319
319
  end
320
320
 
321
- def internal_request(route, opts={}, &block)
321
+ def internal_request(route, opts=OPTS, &block)
322
322
  opts = opts.dup
323
323
 
324
324
  env = {
@@ -425,7 +425,7 @@ module Rodauth
425
425
  feature = FEATURES[feature_name]
426
426
  if meths = feature.internal_request_methods
427
427
  meths.each do |name|
428
- klass.define_singleton_method(name){|opts={}, &block| internal_class.internal_request(name, opts, &block)}
428
+ klass.define_singleton_method(name){|opts=OPTS, &block| internal_class.internal_request(name, opts, &block)}
429
429
  end
430
430
  end
431
431
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Rodauth
4
4
  Feature.define(:json, :Json) do
5
+ self.allowed_undefined_configuration_methods = [:only_json?].freeze
6
+
5
7
  translatable_method :json_not_accepted_error_message, 'Unsupported Accept header. Must accept "application/json" or compatible content type'
6
8
  translatable_method :json_non_post_error_message, 'non-POST method used in JSON API'
7
9
  auth_value_method :json_accept_regexp, /(?:(?:\*|\bapplication)\/\*|\bapplication\/(?:vnd\.api\+)?json\b)/i
@@ -11,7 +11,7 @@ module Rodauth
11
11
  auth_value_method :jwt_algorithm, "HS256"
12
12
  auth_value_method :jwt_authorization_ignore, /\A(?:Basic|Digest) /
13
13
  auth_value_method :jwt_authorization_remove, /\ABearer:?\s+/
14
- auth_value_method :jwt_decode_opts, {}.freeze
14
+ auth_value_method :jwt_decode_opts, OPTS
15
15
  auth_value_method :jwt_old_secret, nil
16
16
  auth_value_method :jwt_session_key, nil
17
17
  auth_value_method :jwt_symbolize_deeply?, false
@@ -251,7 +251,14 @@ module Rodauth
251
251
 
252
252
  private
253
253
 
254
- attr_reader :unlock_account_key_value
254
+ def unlock_account_key
255
+ @unlock_account_key_value
256
+ end
257
+
258
+ def unlock_account_key_value
259
+ # RODAUTH3: call unlock_account_key directly
260
+ unlock_account_key
261
+ end
255
262
 
256
263
  def before_login_attempt
257
264
  if locked_out?
@@ -13,8 +13,8 @@ module Rodauth
13
13
  path_meth = :"#{route}_path"
14
14
  url_meth = :"#{route}_url"
15
15
  instance = klass.allocate.freeze
16
- klass.define_singleton_method(path_meth){|opts={}| instance.send(path_meth, opts)}
17
- klass.define_singleton_method(url_meth){|opts={}| instance.send(url_meth, opts)}
16
+ klass.define_singleton_method(path_meth){|opts=OPTS| instance.send(path_meth, opts)}
17
+ klass.define_singleton_method(url_meth){|opts=OPTS| instance.send(url_meth, opts)}
18
18
  end
19
19
  end
20
20
  end
@@ -16,7 +16,7 @@ module Rodauth
16
16
  response
17
17
 
18
18
  auth_value_method :raw_remember_token_deadline, nil
19
- auth_value_method :remember_cookie_options, {}.freeze
19
+ auth_value_method :remember_cookie_options, OPTS
20
20
  auth_value_method :extend_remember_deadline?, false
21
21
  auth_value_method :extend_remember_deadline_period, 3600
22
22
  auth_value_method :remember_period, {:days=>14}.freeze
@@ -192,6 +192,11 @@ module Rodauth
192
192
  end
193
193
 
194
194
  def get_password_reset_key(id)
195
+ # RODAUTH3: Remove method and call get_reset_password_key directly
196
+ get_reset_password_key(id)
197
+ end
198
+
199
+ def get_reset_password_key(id)
195
200
  ds = password_reset_ds(id)
196
201
  ds.where(Sequel::CURRENT_TIMESTAMP > reset_password_deadline_column).delete
197
202
  ds.get(reset_password_key_column)
@@ -92,7 +92,6 @@ module Rodauth
92
92
  auth_value_methods(
93
93
  :sms_codes_primary?,
94
94
  :sms_needs_confirmation_notice_flash,
95
- :sms_request_response
96
95
  )
97
96
 
98
97
  auth_methods(
@@ -120,6 +119,7 @@ module Rodauth
120
119
  :sms_setup?,
121
120
  :sms_valid_phone?
122
121
  )
122
+ auth_private_methods :sms_request_response
123
123
 
124
124
  uses_instance_variables(:@sms)
125
125
 
@@ -6,7 +6,7 @@ module Rodauth
6
6
  MAJOR = 2
7
7
 
8
8
  # The minor version of Rodauth, updated for new feature releases of Rodauth.
9
- MINOR = 44
9
+ MINOR = 45
10
10
 
11
11
  # The patch version of Rodauth, updated only for bug fixes from the last
12
12
  # feature release.
data/lib/rodauth.rb CHANGED
@@ -3,9 +3,12 @@
3
3
  require 'securerandom'
4
4
 
5
5
  module Rodauth
6
+ OPTS = {}.freeze
7
+ SCOPE_INSTANCE_VARIABLES = [:@_rodauths, :@_rodauth].freeze
8
+
6
9
  class ConfigurationError < StandardError; end
7
10
 
8
- def self.lib(opts={}, &block)
11
+ def self.lib(opts=OPTS, &block)
9
12
  require 'roda'
10
13
  c = Class.new(Roda)
11
14
  c.plugin(:rodauth, opts) do
@@ -16,7 +19,7 @@ module Rodauth
16
19
  c.rodauth
17
20
  end
18
21
 
19
- def self.load_dependencies(app, opts={}, &_)
22
+ def self.load_dependencies(app, opts=OPTS, &_)
20
23
  json_opt = opts.fetch(:json, app.opts[:rodauth_json])
21
24
  if json_opt
22
25
  app.plugin :json
@@ -45,7 +48,7 @@ module Rodauth
45
48
  end
46
49
  end
47
50
 
48
- def self.configure(app, opts={}, &block)
51
+ def self.configure(app, opts=OPTS, &block)
49
52
  json_opt = app.opts[:rodauth_json] = opts.fetch(:json, app.opts[:rodauth_json])
50
53
  csrf = app.opts[:rodauth_csrf] = opts.fetch(:csrf, app.opts[:rodauth_csrf])
51
54
  app.opts[:rodauth_route_csrf] = case csrf
@@ -71,15 +74,32 @@ module Rodauth
71
74
 
72
75
  class FeatureConfiguration < Module
73
76
  def def_configuration_methods(feature)
74
- private_methods = feature.private_instance_methods.map(&:to_sym)
77
+ private_methods = feature.private_instance_methods
75
78
  priv = proc{|m| private_methods.include?(m)}
76
- feature.auth_methods.each{|m| def_auth_method(m, priv[m])}
77
- feature.auth_value_methods.each{|m| def_auth_value_method(m, priv[m])}
78
- feature.auth_private_methods.each{|m| def_auth_private_method(m)}
79
+ feature.auth_methods.each do |m|
80
+ _check_method_defined(feature, m, priv[m])
81
+ def_auth_method(m, priv[m])
82
+ end
83
+ feature.auth_value_methods.each do |m|
84
+ _check_method_defined(feature, m, priv[m])
85
+ def_auth_value_method(m, priv[m])
86
+ end
87
+ feature.auth_private_methods.each do |m|
88
+ _check_method_defined(feature, :"_#{m}", true)
89
+ def_auth_private_method(m)
90
+ end
79
91
  end
80
92
 
81
93
  private
82
94
 
95
+ def _check_method_defined(feature, meth, priv)
96
+ if !feature.send(priv ? :private_method_defined? : :method_defined?, meth) &&
97
+ (!(allowed = feature.allowed_undefined_configuration_methods) || !allowed.include?(meth))
98
+ # RODAUTH3: raise instead of warn
99
+ warn "Bug in Rodauth #{feature.feature_name} feature definition, configuration method added for #{meth}, but the feature doesn't define the method"
100
+ end
101
+ end
102
+
83
103
  def def_auth_method(meth, priv)
84
104
  define_method(meth) do |&block|
85
105
  @auth.send(:define_method, meth, &block)
@@ -125,6 +145,7 @@ module Rodauth
125
145
  attr_accessor :dependencies
126
146
  attr_accessor :routes
127
147
  attr_accessor :configuration
148
+ attr_accessor :allowed_undefined_configuration_methods
128
149
  attr_reader :internal_request_methods
129
150
  attr_reader :instance_variables_used
130
151
 
@@ -132,8 +153,8 @@ module Rodauth
132
153
  route_meth = :"#{name}_route"
133
154
  auth_value_method route_meth, default
134
155
 
135
- define_method(:"#{name}_path"){|opts={}| route_path(send(route_meth), opts) if send(route_meth)}
136
- define_method(:"#{name}_url"){|opts={}| route_url(send(route_meth), opts) if send(route_meth)}
156
+ define_method(:"#{name}_path"){|opts=OPTS| route_path(send(route_meth), opts) if send(route_meth)}
157
+ define_method(:"#{name}_url"){|opts=OPTS| route_url(send(route_meth), opts) if send(route_meth)}
137
158
 
138
159
  handle_meth = :"handle_#{name}"
139
160
  internal_handle_meth = :"_#{handle_meth}"
@@ -260,7 +281,7 @@ module Rodauth
260
281
  end
261
282
  end
262
283
 
263
- def email(type, subject, opts = {})
284
+ def email(type, subject, opts = OPTS)
264
285
  subject_method = :"#{type}_email_subject"
265
286
  body_method = :"#{type}_email_body"
266
287
  create_method = :"create_#{type}_email"
@@ -507,7 +528,7 @@ module Rodauth
507
528
  view_opts = rodauth.send(:loaded_templates).map do |page|
508
529
  rodauth.send(:_view_opts, page)
509
530
  end
510
- view_opts << rodauth.send(:button_opts, '', {})
531
+ view_opts << rodauth.send(:button_opts, '', OPTS)
511
532
 
512
533
  view_opts.each do |opts|
513
534
  instance.send(:retrieve_template, opts).send(:compiled_method, opts[:locals].keys.sort_by(&:to_s))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.44.0
4
+ version: 2.45.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans