rodauth-rails 0.12.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +119 -33
  4. data/lib/generators/rodauth/templates/app/lib/rodauth_app.rb +10 -1
  5. data/lib/generators/rodauth/templates/app/views/rodauth/_email_auth_request_form.html.erb +1 -1
  6. data/lib/generators/rodauth/templates/app/views/rodauth/_field.html.erb +2 -2
  7. data/lib/generators/rodauth/templates/app/views/rodauth/_field_error.html.erb +2 -2
  8. data/lib/generators/rodauth/templates/app/views/rodauth/_global_logout_field.html.erb +1 -1
  9. data/lib/generators/rodauth/templates/app/views/rodauth/_login_confirm_field.html.erb +1 -1
  10. data/lib/generators/rodauth/templates/app/views/rodauth/_login_display.html.erb +1 -1
  11. data/lib/generators/rodauth/templates/app/views/rodauth/_login_field.html.erb +1 -1
  12. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb +3 -3
  13. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_footer.html.erb +2 -2
  14. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb +2 -2
  15. data/lib/generators/rodauth/templates/app/views/rodauth/_login_hidden_field.html.erb +1 -1
  16. data/lib/generators/rodauth/templates/app/views/rodauth/_new_password_field.html.erb +1 -1
  17. data/lib/generators/rodauth/templates/app/views/rodauth/_otp_auth_code_field.html.erb +1 -1
  18. data/lib/generators/rodauth/templates/app/views/rodauth/_password_confirm_field.html.erb +1 -1
  19. data/lib/generators/rodauth/templates/app/views/rodauth/_password_field.html.erb +1 -1
  20. data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_code_field.html.erb +1 -1
  21. data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_codes_form.html.erb +4 -4
  22. data/lib/generators/rodauth/templates/app/views/rodauth/_sms_code_field.html.erb +1 -1
  23. data/lib/generators/rodauth/templates/app/views/rodauth/_sms_phone_field.html.erb +1 -1
  24. data/lib/generators/rodauth/templates/app/views/rodauth/add_recovery_codes.html.erb +2 -2
  25. data/lib/generators/rodauth/templates/app/views/rodauth/change_login.html.erb +3 -3
  26. data/lib/generators/rodauth/templates/app/views/rodauth/change_password.html.erb +3 -3
  27. data/lib/generators/rodauth/templates/app/views/rodauth/close_account.html.erb +2 -2
  28. data/lib/generators/rodauth/templates/app/views/rodauth/confirm_password.html.erb +1 -1
  29. data/lib/generators/rodauth/templates/app/views/rodauth/create_account.html.erb +4 -4
  30. data/lib/generators/rodauth/templates/app/views/rodauth/email_auth.html.erb +1 -1
  31. data/lib/generators/rodauth/templates/app/views/rodauth/logout.html.erb +2 -2
  32. data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +1 -1
  33. data/lib/generators/rodauth/templates/app/views/rodauth/otp_auth.html.erb +1 -1
  34. data/lib/generators/rodauth/templates/app/views/rodauth/otp_disable.html.erb +2 -2
  35. data/lib/generators/rodauth/templates/app/views/rodauth/otp_setup.html.erb +7 -7
  36. data/lib/generators/rodauth/templates/app/views/rodauth/recovery_auth.html.erb +1 -1
  37. data/lib/generators/rodauth/templates/app/views/rodauth/remember.html.erb +4 -4
  38. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password.html.erb +2 -2
  39. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password_request.html.erb +2 -2
  40. data/lib/generators/rodauth/templates/app/views/rodauth/sms_auth.html.erb +1 -1
  41. data/lib/generators/rodauth/templates/app/views/rodauth/sms_confirm.html.erb +1 -1
  42. data/lib/generators/rodauth/templates/app/views/rodauth/sms_disable.html.erb +2 -2
  43. data/lib/generators/rodauth/templates/app/views/rodauth/sms_request.html.erb +1 -1
  44. data/lib/generators/rodauth/templates/app/views/rodauth/sms_setup.html.erb +2 -2
  45. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_auth.html.erb +1 -1
  46. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_disable.html.erb +2 -2
  47. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_manage.html.erb +6 -6
  48. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account.html.erb +2 -2
  49. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account_request.html.erb +1 -1
  50. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account.html.erb +3 -3
  51. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account_resend.html.erb +2 -2
  52. data/lib/generators/rodauth/templates/app/views/rodauth/verify_login_change.html.erb +1 -1
  53. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_auth.html.erb +7 -7
  54. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_remove.html.erb +5 -5
  55. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_setup.html.erb +7 -7
  56. data/lib/generators/rodauth/views_generator.rb +25 -4
  57. data/lib/rodauth/rails/auth.rb +9 -12
  58. data/lib/rodauth/rails/feature/base.rb +8 -8
  59. data/lib/rodauth/rails/feature/render.rb +7 -0
  60. data/lib/rodauth/rails/version.rb +1 -1
  61. data/lib/rodauth/rails.rb +26 -4
  62. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27d48e6bf86cf81b33f6b0282048c2fb6f16ec6602136e18de6ede5120cfd808
4
- data.tar.gz: 2f79498ff25a42131a5ead77f3d4adf05152bc85f271c8b985f0f9fa8c04b503
3
+ metadata.gz: d447d09fef8c29feb6240523286b8906049e85965f20a6410d1a475f913d9051
4
+ data.tar.gz: bca9b6eadec6b32f2193291c6922467a554105d290ffd7b34bc2606d62121926
5
5
  SHA512:
6
- metadata.gz: 8a0c44b54d304d4dfb2a205d41a5ac360e483209229fa49e767f9eaa595434b291661e283110f3ee39a8fbc17a4ad2d82f90a6e4545ca4112852ee50a35aa8da
7
- data.tar.gz: 52bb16489dd97777f7ff2359be9014a2c55c7537b8d4449621eb95ef3b7f0030febcd06caa811d406db1fb24fcc884d22c7460a36a94255133ce261a2bbeb68d
6
+ metadata.gz: 1f512f9fe9a3e22dcddf477d8906d1ea63a548241fd93b43bbcaf274ff39e0104e20f64c6a2836e5b243e812ffde654deae55a0beca69f4ba917cd5943da8a3c
7
+ data.tar.gz: dbbd99959dfd42134cd3374f1f9767cf3e8d49327c195d4c35c4ecf281d0c3dad52db76b7e2fbf030c9e3ea2131bfcb1b6a120cc4a310983d8db564e63b97cda
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 0.14.0 (2021-07-10)
2
+
3
+ * Speed up template rendering by only searching formats accepted by the request (@janko)
4
+
5
+ * Add `--name` option to `rodauth:views` generator for specifying different rodauth configuration (@janko)
6
+
7
+ * Infer correct template path from configured controller in `rodauth:views` generator (@janko)
8
+
9
+ * Raise `ArgumentError` if undefined rodauth configuration is passed to `Rodauth::Rails.app` (@janko)
10
+
11
+ * Make `#rails_controller` method on the rodauth instance public (@janko)
12
+
13
+ * Remove `--directory` option from `rodauth:views` generator (@janko)
14
+
15
+ * Remove `#features` and `#routes` writer and `#configuration` reader from `Rodauth::Rails::Auth` (@janko)
16
+
17
+ ## 0.13.0 (2021-06-10)
18
+
19
+ * Add `:query`, `:form`, `:session`, `:account`, and `:env` options to `Rodauth::Rails.rodauth` (@janko)
20
+
1
21
  ## 0.12.0 (2021-05-15)
2
22
 
3
23
  * Include total view render time in logs for Rodauth requests (@janko)
data/README.md CHANGED
@@ -41,27 +41,15 @@ Active Record's database connection][sequel-activerecord_connection].
41
41
 
42
42
  ## Upgrading
43
43
 
44
- ### Upgrading to 0.7.0
45
-
46
- Starting from version 0.7.0, rodauth-rails now correctly detects Rails
47
- application's `secret_key_base` when setting default `hmac_secret`, including
48
- when it's set via credentials or `$SECRET_KEY_BASE` environment variable. This
49
- means that your authentication will now be more secure by default, and Rodauth
50
- features that require `hmac_secret` should now work automatically as well.
51
-
52
- However, if you've already been using rodauth-rails in production, where the
53
- `secret_key_base` is set via credentials or environment variable and `hmac_secret`
54
- was not explicitly set, the fact that your authentication will now start using
55
- HMACs has backwards compatibility considerations. See the [Rodauth
56
- documentation][hmac] for instructions on how to safely transition, or just set
57
- `hmac_secret nil` in your Rodauth configuration.
44
+ For instructions on upgrading from previous rodauth-rails versions, see
45
+ [UPGRADING.md](/UPGRADING.md).
58
46
 
59
47
  ## Installation
60
48
 
61
49
  Add the gem to your Gemfile:
62
50
 
63
51
  ```rb
64
- gem "rodauth-rails", "~> 0.12"
52
+ gem "rodauth-rails", "~> 0.14"
65
53
 
66
54
  # gem "jwt", require: false # for JWT feature
67
55
  # gem "rotp", require: false # for OTP feature
@@ -290,8 +278,8 @@ $ rails generate rodauth:views
290
278
  ```
291
279
 
292
280
  This will generate views for the default set of Rodauth features into the
293
- `app/views/rodauth` directory, which will be automatically picked up by the
294
- `RodauthController`.
281
+ `app/views/rodauth` directory, provided that `RodauthController` is set for the
282
+ main configuration.
295
283
 
296
284
  You can pass a list of Rodauth features to the generator to create views for
297
285
  these features (this will not remove or overwrite any existing views):
@@ -306,12 +294,10 @@ Or you can generate views for all features:
306
294
  $ rails generate rodauth:views --all
307
295
  ```
308
296
 
309
- You can also tell the generator to create views into another directory (in this
310
- case make sure to rename the Rodauth controller accordingly):
297
+ Use `--name` to generate views for a different Rodauth configuration:
311
298
 
312
299
  ```sh
313
- # generates views into app/views/authentication
314
- $ rails generate rodauth:views --name authentication
300
+ $ rails generate rodauth:views --name admin
315
301
  ```
316
302
 
317
303
  #### Layout
@@ -404,14 +390,48 @@ end
404
390
  This configuration calls `#deliver_later`, which uses Active Job to deliver
405
391
  emails in a background job. It's generally recommended to send emails
406
392
  asynchronously for better request throughput and the ability to retry
407
- deliveries. However, if you want to send emails synchronously, modify the
408
- configuration to call `#deliver_now` instead.
393
+ deliveries. However, if you want to send emails synchronously, you can modify
394
+ the configuration to call `#deliver_now` instead.
409
395
 
410
396
  If you're using a background processing library without an Active Job adapter,
411
397
  or a 3rd-party service for sending transactional emails, this two-phase API
412
398
  might not be suitable. In this case, instead of overriding `#create_*_email`
413
399
  and `#send_email`, override the `#send_*_email` methods instead, which are
414
- required to send the email immediately.
400
+ required to send the email immediately. For example:
401
+
402
+ ```rb
403
+ # app/workers/rodauth_mailer_worker.rb
404
+ class RodauthMailerWorker
405
+ include Sidekiq::Worker
406
+
407
+ def perform(name, *args)
408
+ email = RodauthMailer.public_send(name, *args)
409
+ email.deliver_now
410
+ end
411
+ end
412
+ ```
413
+ ```rb
414
+ # app/lib/rodauth_app.rb
415
+ class RodauthApp < Rodauth::Rails::App
416
+ configure do
417
+ # ...
418
+ # use `#send_*_email` method to be able to immediately enqueue email delivery
419
+ send_reset_password_email do
420
+ enqueue_email(:reset_password, email_to, reset_password_email_link)
421
+ end
422
+ # ...
423
+ auth_class_eval do
424
+ # custom method for enqueuing email delivery using our worker
425
+ def enqueue_email(name, *args)
426
+ db.after_commit do
427
+ RodauthMailerWorker.perform_async(name, *args)
428
+ end
429
+ end
430
+ end
431
+ # ...
432
+ end
433
+ end
434
+ ```
415
435
 
416
436
  ### Migrations
417
437
 
@@ -452,10 +472,6 @@ class RodauthApp < Rodauth::Rails::App
452
472
  prefix "/admin"
453
473
  session_key_prefix "admin_"
454
474
  remember_cookie_key "_admin_remember" # if using remember feature
455
-
456
- # if you want separate tables
457
- accounts_table :admin_accounts
458
- password_hash_table :admin_account_password_hashes
459
475
  # ...
460
476
  end
461
477
 
@@ -464,7 +480,7 @@ class RodauthApp < Rodauth::Rails::App
464
480
 
465
481
  r.on "admin" do
466
482
  r.rodauth(:admin)
467
- r.pass # allow the Rails app to handle other "/admin/*" requests
483
+ break # allow routing of other /admin/* requests to continue to Rails
468
484
  end
469
485
 
470
486
  # ...
@@ -478,6 +494,50 @@ Then in your application you can reference the secondary Rodauth instance:
478
494
  rodauth(:admin).login_path #=> "/admin/login"
479
495
  ```
480
496
 
497
+ You'll likely want to save the information of which account belongs to which
498
+ configuration to the database. One way would be to have a separate table that
499
+ stores account types:
500
+
501
+ ```sh
502
+ $ rails generate migration create_account_types
503
+ ```
504
+ ```rb
505
+ # db/migrate/*_create_account_types.rb
506
+ class CreateAccountTypes < ActiveRecord::Migration
507
+ def change
508
+ create_table :account_types do |t|
509
+ t.references :account, foreign_key: { on_delete: :cascade }, null: false
510
+ t.string :type, null: false
511
+ end
512
+ end
513
+ end
514
+ ```
515
+ ```sh
516
+ $ rails db:migrate
517
+ ```
518
+
519
+ Then an entry would be inserted after account creation, and optionally whenever
520
+ Rodauth retrieves accounts you could filter only those belonging to the current
521
+ configuration:
522
+
523
+ ```rb
524
+ # app/lib/rodauth_app.rb
525
+ class RodauthApp < Rodauth::Rails::App
526
+ configure(:admin) do
527
+ # ...
528
+ after_create_account do
529
+ db[:account_types].insert(account_id: account_id, type: "admin")
530
+ end
531
+ auth_class_eval do
532
+ def account_ds(*)
533
+ super.join(:account_types, account_id: :id).where(type: "admin")
534
+ end
535
+ end
536
+ # ...
537
+ end
538
+ end
539
+ ```
540
+
481
541
  #### Named auth classes
482
542
 
483
543
  A `configure` block inside `Rodauth::Rails::App` will internally create an
@@ -599,8 +659,8 @@ end
599
659
  ### Rodauth instance
600
660
 
601
661
  In some cases you might need to use Rodauth more programmatically, and perform
602
- Rodauth operations outside of the request context. rodauth-rails gives you the
603
- ability to retrieve the Rodauth instance:
662
+ Rodauth operations outside of the request context. rodauth-rails gives you a
663
+ helper method for building a Rodauth instance:
604
664
 
605
665
  ```rb
606
666
  rodauth = Rodauth::Rails.rodauth # or Rodauth::Rails.rodauth(:admin)
@@ -612,8 +672,22 @@ rodauth.setup_account_verification
612
672
  rodauth.close_account
613
673
  ```
614
674
 
615
- This Rodauth instance will be initialized with basic Rack env that allows it
616
- to generate URLs, using `config.action_mailer.default_url_options` options.
675
+ The base URL is taken from Action Mailer's `default_url_options` setting if
676
+ configured. The `Rodauth::Rails.rodauth` method accepts additional keyword
677
+ arguments:
678
+
679
+ * `:account` – Active Record model instance from which to set `account` and `session[:account_id]`
680
+ * `:query` & `:form` – set specific query/form parameters
681
+ * `:session` – set any session values
682
+ * `:env` – set any additional Rack env values
683
+
684
+ ```rb
685
+ Rodauth::Rails.rodauth(account: Account.find(account_id))
686
+ Rodauth::Rails.rodauth(query: { "param" => "value" })
687
+ Rodauth::Rails.rodauth(form: { "param" => "value" })
688
+ Rodauth::Rails.rodauth(session: { two_factor_auth_setup: true })
689
+ Rodauth::Rails.rodauth(env: { "HTTP_USER_AGENT" => "programmatic" })
690
+ ```
617
691
 
618
692
  ## How it works
619
693
 
@@ -1176,6 +1250,18 @@ configure do
1176
1250
  end
1177
1251
  ```
1178
1252
 
1253
+ ### Deadline values
1254
+
1255
+ To simplify changes to the database schema, rodauth-rails configures Rodauth
1256
+ to set deadline values for various features in Ruby, instead of relying on
1257
+ the database to set default column values.
1258
+
1259
+ You can easily change this back:
1260
+
1261
+ ```rb
1262
+ set_deadline_values? false
1263
+ ```
1264
+
1179
1265
  ## License
1180
1266
 
1181
1267
  The gem is available as open source under the terms of the [MIT
@@ -156,9 +156,18 @@ class RodauthApp < Rodauth::Rails::App
156
156
 
157
157
  # ==> Multiple configurations
158
158
  # configure(:admin) do
159
- # enable :http_basic_auth # enable different set of features
159
+ # # ... enable features ...
160
160
  # prefix "/admin"
161
161
  # session_key_prefix "admin_"
162
+ # # remember_cookie_key "_admin_remember" # if using remember feature
163
+ #
164
+ # # search views in `app/views/admin/rodauth` directory
165
+ # rails_controller { Admin::RodauthController }
166
+ #
167
+ # # use separate tables (requires creating the new tables)
168
+ # methods.grep(/_table$/) do |table_method|
169
+ # public_send(table_method) { :"admin_#{super()}" }
170
+ # end
162
171
  # end
163
172
 
164
173
  route do |r|
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.email_auth_request_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.email_auth_request_path, method: :post do %>
2
2
  <%%= render "login_hidden_field" %>
3
3
  <%%= render "submit", value: "Send Login Link Via Email" %>
4
4
  <%% end %>
@@ -4,7 +4,7 @@
4
4
  autocomplete: local_assigns[:autocomplete],
5
5
  inputmode: local_assigns[:inputmode],
6
6
  required: local_assigns[:required] != false,
7
- class: "#{local_assigns[:class] || "form-control"} #{"is-invalid" if rodauth.field_error(name)}",
8
- aria: ({ invalid: "true", describedby: "#{name}_error_message" } if rodauth.field_error(name)) %>
7
+ class: "#{local_assigns[:class] || "form-control"} #{"is-invalid" if <%= rodauth %>.field_error(name)}",
8
+ aria: ({ invalid: "true", describedby: "#{name}_error_message" } if <%= rodauth %>.field_error(name)) %>
9
9
 
10
10
  <%%= render "field_error", name: name unless local_assigns[:skip_error_message] %>
@@ -1,3 +1,3 @@
1
- <%% if rodauth.field_error(name) %>
2
- <div class="invalid-feedback" id="<%%= name %>_error_message"><%%= rodauth.field_error(name) %></div>
1
+ <%% if <%= rodauth %>.field_error(name) %>
2
+ <div class="invalid-feedback" id="<%%= name %>_error_message"><%%= <%= rodauth %>.field_error(name) %></div>
3
3
  <%% end %>
@@ -1,6 +1,6 @@
1
1
  <div class="form-group mb-3">
2
2
  <div class="form-check">
3
- <%%= check_box_tag rodauth.global_logout_param, "t", false, id: "global-logout", class: "form-check-input" %>
3
+ <%%= check_box_tag <%= rodauth %>.global_logout_param, "t", false, id: "global-logout", class: "form-check-input" %>
4
4
  <%%= label_tag "global-logout", "Logout all Logged In Sessons?", class: "form-check-label" %>
5
5
  </div>
6
6
  </div>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group mb-3">
2
2
  <%%= label_tag "login-confirm", "Confirm Login", class: "form-label" %>
3
- <%%= render "field", name: rodauth.login_confirm_param, id: "login-confirm", type: :email, autocomplete: "email" %>
3
+ <%%= render "field", name: <%= rodauth %>.login_confirm_param, id: "login-confirm", type: :email, autocomplete: "email" %>
4
4
  </div>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group mb-3">
2
2
  <%%= label_tag "login", "Login", class: "form-label" %>
3
- <%%= email_field_tag rodauth.login_param, params[rodauth.login_param], id: "login", readonly: true, class: "form-control-plaintext" %>
3
+ <%%= email_field_tag <%= rodauth %>.login_param, params[<%= rodauth %>.login_param], id: "login", readonly: true, class: "form-control-plaintext" %>
4
4
  </div>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group mb-3">
2
2
  <%%= label_tag "login", "Login", class: "form-label" %>
3
- <%%= render "field", name: rodauth.login_param, id: "login", type: :email, autocomplete: "email" %>
3
+ <%%= render "field", name: <%= rodauth %>.login_param, id: "login", type: :email, autocomplete: "email" %>
4
4
  </div>
@@ -1,9 +1,9 @@
1
- <%%= form_tag rodauth.login_path, method: :post do %>
2
- <%% if rodauth.skip_login_field_on_login? %>
1
+ <%%= form_tag <%= rodauth %>.login_path, method: :post do %>
2
+ <%% if <%= rodauth %>.skip_login_field_on_login? %>
3
3
  <%%= render "login_display" %>
4
4
  <%% else %>
5
5
  <%%= render "login_field" %>
6
6
  <%% end %>
7
- <%%= render "password_field" unless rodauth.skip_password_field_on_login? %>
7
+ <%%= render "password_field" unless <%= rodauth %>.skip_password_field_on_login? %>
8
8
  <%%= render "submit", value: "Login" %>
9
9
  <%% end %>
@@ -1,7 +1,7 @@
1
- <%% unless rodauth.login_form_footer_links.empty? %>
1
+ <%% unless <%= rodauth %>.login_form_footer_links.empty? %>
2
2
  <h2>Other Options</h2>
3
3
  <ul>
4
- <%% rodauth.login_form_footer_links.sort.each do |_, link, text| %>
4
+ <%% <%= rodauth %>.login_form_footer_links.sort.each do |_, link, text| %>
5
5
  <li><%%= link_to text, link %></li>
6
6
  <%% end %>
7
7
  </ul>
@@ -1,3 +1,3 @@
1
- <%% if rodauth.field_error("password") && rodauth.features.include?(:reset_password) %>
2
- <%%= render template: "<%= options[:directory] %>/reset_password_request", layout: false %>
1
+ <%% if <%= rodauth %>.field_error("password") && <%= rodauth %>.features.include?(:reset_password) %>
2
+ <%%= render template: "<%= directory %>/reset_password_request", layout: false %>
3
3
  <%% end %>
@@ -1 +1 @@
1
- <%%= hidden_field_tag rodauth.login_param, params[rodauth.login_param] %>
1
+ <%%= hidden_field_tag <%= rodauth %>.login_param, params[<%= rodauth %>.login_param] %>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group mb-3">
2
2
  <%%= label_tag "new-password", "New Password", class: "form-label" %>
3
- <%%= render "field", name: rodauth.new_password_param, id: "new-password", type: "password", value: "", autocomplete: "new-password" %>
3
+ <%%= render "field", name: <%= rodauth %>.new_password_param, id: "new-password", type: "password", value: "", autocomplete: "new-password" %>
4
4
  </div>
@@ -2,7 +2,7 @@
2
2
  <%%= label_tag "otp-auth-code", "Authentication Code", class: "form-label" %>
3
3
  <div class="row">
4
4
  <div class="col-sm-3">
5
- <%%= render "field", name: rodauth.otp_auth_param, id: "otp-auth-code", value: "", autocomplete: "off", inputmode: "numeric" %>
5
+ <%%= render "field", name: <%= rodauth %>.otp_auth_param, id: "otp-auth-code", value: "", autocomplete: "off", inputmode: "numeric" %>
6
6
  </div>
7
7
  </div>
8
8
  </div>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group mb-3">
2
2
  <%%= label_tag "password-confirm", "Confirm Password", class: "form-label" %>
3
- <%%= render "field", name: rodauth.password_confirm_param, id: "password-confirm", type: :password, value: "", autocomplete: "new-password" %>
3
+ <%%= render "field", name: <%= rodauth %>.password_confirm_param, id: "password-confirm", type: :password, value: "", autocomplete: "new-password" %>
4
4
  </div>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group mb-3">
2
2
  <%%= label_tag "password", "Password", class: "form-label" %>
3
- <%%= render "field", name: rodauth.password_param, id: "password", type: :password, value: "", autocomplete: rodauth.password_field_autocomplete_value %>
3
+ <%%= render "field", name: <%= rodauth %>.password_param, id: "password", type: :password, value: "", autocomplete: <%= rodauth %>.password_field_autocomplete_value %>
4
4
  </div>
@@ -1,4 +1,4 @@
1
1
  <div class="form-group mb-3">
2
2
  <%%= label_tag "recovery_code", "Recovery Code", class: "form-label" %>
3
- <%%= render "field", name: rodauth.recovery_codes_param, id: "recovery_code", value: "", autocomplete: "off" %>
3
+ <%%= render "field", name: <%= rodauth %>.recovery_codes_param, id: "recovery_code", value: "", autocomplete: "off" %>
4
4
  </div>
@@ -1,6 +1,6 @@
1
- <%%= form_tag rodauth.recovery_codes_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
1
+ <%%= form_tag <%= rodauth %>.recovery_codes_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
3
3
  <%%= render "submit",
4
- value: rodauth.recovery_codes_button || "View Authentication Recovery Codes",
5
- name: (rodauth.add_recovery_codes_param if rodauth.recovery_codes_button) %>
4
+ value: <%= rodauth %>.recovery_codes_button || "View Authentication Recovery Codes",
5
+ name: (<%= rodauth %>.add_recovery_codes_param if <%= rodauth %>.recovery_codes_button) %>
6
6
  <%% end %>
@@ -2,7 +2,7 @@
2
2
  <%%= label_tag "sms-code", "SMS Code", class: "form-label" %>
3
3
  <div class="row">
4
4
  <div class="col-sm-3">
5
- <%%= render "field", name: rodauth.sms_code_param, id: "sms-code", value: "", autocomplete: "one-time-code", inputmode: "numeric" %>
5
+ <%%= render "field", name: <%= rodauth %>.sms_code_param, id: "sms-code", value: "", autocomplete: "one-time-code", inputmode: "numeric" %>
6
6
  </div>
7
7
  </div>
8
8
  </div>
@@ -2,7 +2,7 @@
2
2
  <%%= label_tag "sms-phone", "Phone Number", class: "form-label" %>
3
3
  <div class="row">
4
4
  <div class="col-sm-3">
5
- <%%= render "field", name: rodauth.sms_phone_param, id: "sms-phone", type: :tel, autocomplete: "tel" %>
5
+ <%%= render "field", name: <%= rodauth %>.sms_phone_param, id: "sms-phone", type: :tel, autocomplete: "tel" %>
6
6
  </div>
7
7
  </div>
8
8
  </div>
@@ -1,6 +1,6 @@
1
- <pre id="recovery-codes"><%%= rodauth.recovery_codes.map { |s| h(s) }.join("\n\n") %></pre>
1
+ <pre id="recovery-codes"><%%= <%= rodauth %>.recovery_codes.map { |s| h(s) }.join("\n\n") %></pre>
2
2
 
3
- <%% if rodauth.can_add_recovery_codes? %>
3
+ <%% if <%= rodauth %>.can_add_recovery_codes? %>
4
4
  <h2>Add Additional Recovery Codes</h2>
5
5
  <%%= render "recovery_codes_form" %>
6
6
  <%% end %>
@@ -1,6 +1,6 @@
1
- <%%= form_tag rodauth.change_login_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.change_login_path, method: :post do %>
2
2
  <%%= render "login_field" %>
3
- <%%= render "login_confirm_field" if rodauth.require_login_confirmation? %>
4
- <%%= render "password_field" if rodauth.change_login_requires_password? %>
3
+ <%%= render "login_confirm_field" if <%= rodauth %>.require_login_confirmation? %>
4
+ <%%= render "password_field" if <%= rodauth %>.change_login_requires_password? %>
5
5
  <%%= render "submit", value: "Change Login" %>
6
6
  <%% end %>
@@ -1,6 +1,6 @@
1
- <%%= form_tag rodauth.change_password_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.change_password_requires_password? %>
1
+ <%%= form_tag <%= rodauth %>.change_password_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.change_password_requires_password? %>
3
3
  <%%= render "new_password_field" %>
4
- <%%= render "password_confirm_field" if rodauth.require_password_confirmation? %>
4
+ <%%= render "password_confirm_field" if <%= rodauth %>.require_password_confirmation? %>
5
5
  <%%= render "submit", value: "Change Password" %>
6
6
  <%% end %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.close_account_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.close_account_requires_password? %>
1
+ <%%= form_tag <%= rodauth %>.close_account_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.close_account_requires_password? %>
3
3
  <%%= render "submit", value: "Close Account", class: "btn btn-danger" %>
4
4
  <%% end %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.confirm_password_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.confirm_password_path, method: :post do %>
2
2
  <%%= render "password_field" %>
3
3
  <%%= render "submit", value: "Confirm Password" %>
4
4
  <%% end %>
@@ -1,7 +1,7 @@
1
- <%%= form_tag rodauth.create_account_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.create_account_path, method: :post do %>
2
2
  <%%= render "login_field" %>
3
- <%%= render "login_confirm_field" if rodauth.require_login_confirmation? %>
4
- <%%= render "password_field" if rodauth.create_account_set_password? %>
5
- <%%= render "password_confirm_field" if rodauth.create_account_set_password? && rodauth.require_password_confirmation? %>
3
+ <%%= render "login_confirm_field" if <%= rodauth %>.require_login_confirmation? %>
4
+ <%%= render "password_field" if <%= rodauth %>.create_account_set_password? %>
5
+ <%%= render "password_confirm_field" if <%= rodauth %>.create_account_set_password? && <%= rodauth %>.require_password_confirmation? %>
6
6
  <%%= render "submit", value: "Create Account" %>
7
7
  <%% end %>
@@ -1,3 +1,3 @@
1
- <%%= form_tag rodauth.email_auth_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.email_auth_path, method: :post do %>
2
2
  <%%= render "submit", value: "Login" %>
3
3
  <%% end %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.logout_path, method: :post do %>
2
- <%%= render "global_logout_field" if rodauth.features.include?(:active_sessions) %>
1
+ <%%= form_tag <%= rodauth %>.logout_path, method: :post do %>
2
+ <%%= render "global_logout_field" if <%= rodauth %>.features.include?(:active_sessions) %>
3
3
  <%%= render "submit", value: "Logout", class: "btn btn-warning" %>
4
4
  <%% end %>
@@ -1,3 +1,3 @@
1
1
  <%%= render "login_form_header" %>
2
- <%%= rodauth.render_multi_phase_login_forms.html_safe %>
2
+ <%%= <%= rodauth %>.render_multi_phase_login_forms.html_safe %>
3
3
  <%%= render "login_form_footer" %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.otp_auth_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.otp_auth_path, method: :post do %>
2
2
  <%%= render "otp_auth_code_field" %>
3
3
  <%%= render "submit", value: "Authenticate Using TOTP" %>
4
4
  <%% end %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.otp_disable_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
1
+ <%%= form_tag <%= rodauth %>.otp_disable_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
3
3
  <%%= render "submit", value: "Disable TOTP Authentication", class: "btn btn-warning" %>
4
4
  <%% end %>
@@ -1,21 +1,21 @@
1
- <%%= form_tag rodauth.otp_setup_path, method: :post do %>
2
- <%%= hidden_field_tag rodauth.otp_setup_param, rodauth.otp_user_key, id: "otp-key" %>
3
- <%%= hidden_field_tag rodauth.otp_setup_raw_param, rodauth.otp_key, id: "otp-hmac-secret" if rodauth.otp_keys_use_hmac? %>
1
+ <%%= form_tag <%= rodauth %>.otp_setup_path, method: :post do %>
2
+ <%%= hidden_field_tag <%= rodauth %>.otp_setup_param, <%= rodauth %>.otp_user_key, id: "otp-key" %>
3
+ <%%= hidden_field_tag <%= rodauth %>.otp_setup_raw_param, <%= rodauth %>.otp_key, id: "otp-hmac-secret" if <%= rodauth %>.otp_keys_use_hmac? %>
4
4
 
5
5
  <div class="form-group mb-3">
6
- <p>Secret: <%%= rodauth.otp_user_key %></p>
7
- <p>Provisioning URL: <%%= rodauth.otp_provisioning_uri %></p>
6
+ <p>Secret: <%%= <%= rodauth %>.otp_user_key %></p>
7
+ <p>Provisioning URL: <%%= <%= rodauth %>.otp_provisioning_uri %></p>
8
8
  </div>
9
9
 
10
10
  <div class="row">
11
11
  <div class="col-lg-6 col-lg">
12
12
  <div class="form-group mb-3">
13
- <p><%%= rodauth.otp_qr_code.html_safe %></p>
13
+ <p><%%= <%= rodauth %>.otp_qr_code.html_safe %></p>
14
14
  </div>
15
15
  </div>
16
16
 
17
17
  <div class="col-lg-6 col-lg">
18
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
18
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
19
19
  <%%= render "otp_auth_code_field" %>
20
20
  <%%= render "submit", value: "Setup TOTP Authentication" %>
21
21
  </div>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.recovery_auth_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.recovery_auth_path, method: :post do %>
2
2
  <%%= render "recovery_code_field" %>
3
3
  <%%= render "submit", value: "Authenticate via Recovery Code" %>
4
4
  <%% end %>
@@ -1,17 +1,17 @@
1
- <%%= form_tag rodauth.remember_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.remember_path, method: :post do %>
2
2
  <fieldset class="form-group mb-3">
3
3
  <div class="form-check">
4
- <%%= radio_button_tag rodauth.remember_param, rodauth.remember_remember_param_value, false, id: "remember-remember", class: "form-check-input" %>
4
+ <%%= radio_button_tag <%= rodauth %>.remember_param, <%= rodauth %>.remember_remember_param_value, false, id: "remember-remember", class: "form-check-input" %>
5
5
  <%%= label_tag "remember-remember", "Remember Me", class: "form-check-label" %>
6
6
  </div>
7
7
 
8
8
  <div class="form-check">
9
- <%%= radio_button_tag rodauth.remember_param, rodauth.remember_forget_param_value, false, id: "remember-forget", class: "form-check-input" %>
9
+ <%%= radio_button_tag <%= rodauth %>.remember_param, <%= rodauth %>.remember_forget_param_value, false, id: "remember-forget", class: "form-check-input" %>
10
10
  <%%= label_tag "remember-forget", "Forget Me", class: "form-check-label" %>
11
11
  </div>
12
12
 
13
13
  <div class="form-check">
14
- <%%= radio_button_tag rodauth.remember_param, rodauth.remember_disable_param_value, false, id: "remember-disable", class: "form-check-input" %>
14
+ <%%= radio_button_tag <%= rodauth %>.remember_param, <%= rodauth %>.remember_disable_param_value, false, id: "remember-disable", class: "form-check-input" %>
15
15
  <%%= label_tag "remember-disable", "Disable Remember Me", class: "form-check-label" %>
16
16
  </div>
17
17
  </fieldset>
@@ -1,5 +1,5 @@
1
- <%%= form_tag rodauth.reset_password_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.reset_password_path, method: :post do %>
2
2
  <%%= render "password_field" %>
3
- <%%= render "password_confirm_field" if rodauth.require_password_confirmation? %>
3
+ <%%= render "password_confirm_field" if <%= rodauth %>.require_password_confirmation? %>
4
4
  <%%= render "submit", value: "Reset Password" %>
5
5
  <%% end %>
@@ -1,6 +1,6 @@
1
- <%%= form_tag rodauth.reset_password_request_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.reset_password_request_path, method: :post do %>
2
2
  <p>If you have forgotten your password, you can request a password reset:</p>
3
- <%% if params[rodauth.login_param] && !rodauth.field_error(rodauth.login_param) %>
3
+ <%% if params[<%= rodauth %>.login_param] && !<%= rodauth %>.field_error(<%= rodauth %>.login_param) %>
4
4
  <%%= render "login_hidden_field" %>
5
5
  <%% else %>
6
6
  <%%= render "login_field" %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.sms_auth_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.sms_auth_path, method: :post do %>
2
2
  <%%= render "sms_code_field" %>
3
3
  <%%= render "submit", value: "Authenticate via SMS Code" %>
4
4
  <%% end %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.sms_confirm_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.sms_confirm_path, method: :post do %>
2
2
  <%%= render "sms_code_field" %>
3
3
  <%%= render "submit", value: "Confirm SMS Backup Number" %>
4
4
  <%% end %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.sms_disable_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
1
+ <%%= form_tag <%= rodauth %>.sms_disable_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
3
3
  <%%= render "submit", value: "Disable Backup SMS Authentication" %>
4
4
  <%% end %>
@@ -1,3 +1,3 @@
1
- <%%= form_tag rodauth.sms_request_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.sms_request_path, method: :post do %>
2
2
  <%%= render "submit", value: "Send SMS Code" %>
3
3
  <%% end %>
@@ -1,5 +1,5 @@
1
- <%%= form_tag rodauth.sms_setup_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
1
+ <%%= form_tag <%= rodauth %>.sms_setup_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
3
3
  <%%= render "sms_phone_field" %>
4
4
  <%%= render "submit", value: "Setup SMS Backup Number" %>
5
5
  <%% end %>
@@ -1,5 +1,5 @@
1
1
  <ul>
2
- <%% rodauth.two_factor_auth_links.sort.each do |_, link, text| %>
2
+ <%% <%= rodauth %>.two_factor_auth_links.sort.each do |_, link, text| %>
3
3
  <li><%%= link_to text, link %></li>
4
4
  <%% end %>
5
5
  </ul>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.two_factor_disable_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
1
+ <%%= form_tag <%= rodauth %>.two_factor_disable_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
3
3
  <%%= render "submit", value: "Remove All Multifactor Authentication Methods" %>
4
4
  <%% end %>
@@ -1,22 +1,22 @@
1
- <%% if rodauth.two_factor_setup_links.any? %>
1
+ <%% if <%= rodauth %>.two_factor_setup_links.any? %>
2
2
  <h2>Setup Multifactor Authentication</h2>
3
3
 
4
4
  <ul>
5
- <%% rodauth.two_factor_setup_links.sort.each do |_, link, text| %>
5
+ <%% <%= rodauth %>.two_factor_setup_links.sort.each do |_, link, text| %>
6
6
  <li><%%= link_to text, link %></li>
7
7
  <%% end %>
8
8
  </ul>
9
9
  <%% end %>
10
10
 
11
- <%% if rodauth.two_factor_remove_links.any? %>
11
+ <%% if <%= rodauth %>.two_factor_remove_links.any? %>
12
12
  <h2>Remove Multifactor Authentication</h2>
13
13
 
14
14
  <ul>
15
- <%% rodauth.two_factor_remove_links.sort.each do |_, link, text| %>
15
+ <%% <%= rodauth %>.two_factor_remove_links.sort.each do |_, link, text| %>
16
16
  <li><%%= link_to text, link %></li>
17
17
  <%% end %>
18
- <%% if rodauth.two_factor_remove_links.length > 1 %>
19
- <li><%%= link_to "Remove All Multifactor Authentication Methods", rodauth.two_factor_disable_path %></li>
18
+ <%% if <%= rodauth %>.two_factor_remove_links.length > 1 %>
19
+ <li><%%= link_to "Remove All Multifactor Authentication Methods", <%= rodauth %>.two_factor_disable_path %></li>
20
20
  <%% end %>
21
21
  </ul>
22
22
  <%% end %>
@@ -1,5 +1,5 @@
1
- <%%= form_tag rodauth.unlock_account_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.unlock_account_path, method: :post do %>
2
2
  <p>This account is currently locked out. You can unlock the account:</p>
3
- <%%= render "password_field" if rodauth.unlock_account_requires_password? %>
3
+ <%%= render "password_field" if <%= rodauth %>.unlock_account_requires_password? %>
4
4
  <%%= render "submit", value: "Unlock Account" %>
5
5
  <%% end %>
@@ -1,4 +1,4 @@
1
- <%%= form_tag rodauth.unlock_account_request_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.unlock_account_request_path, method: :post do %>
2
2
  <p>This account is currently locked out. You can request that the account be unlocked:</p>
3
3
  <%%= render "login_hidden_field" %>
4
4
  <%%= render "submit", value: "Request Account Unlock" %>
@@ -1,5 +1,5 @@
1
- <%%= form_tag rodauth.verify_account_path, method: :post do %>
2
- <%%= render "password_field" if rodauth.verify_account_set_password? %>
3
- <%%= render "password_confirm_field" if rodauth.verify_account_set_password? && rodauth.require_password_confirmation? %>
1
+ <%%= form_tag <%= rodauth %>.verify_account_path, method: :post do %>
2
+ <%%= render "password_field" if <%= rodauth %>.verify_account_set_password? %>
3
+ <%%= render "password_confirm_field" if <%= rodauth %>.verify_account_set_password? && <%= rodauth %>.require_password_confirmation? %>
4
4
  <%%= render "submit", value: "Verify Account" %>
5
5
  <%% end %>
@@ -1,6 +1,6 @@
1
- <%%= form_tag rodauth.verify_account_resend_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.verify_account_resend_path, method: :post do %>
2
2
  <p>If you no longer have the email to verify the account, you can request that it be resent to you:</p>
3
- <%% if params[rodauth.login_param] %>
3
+ <%% if params[<%= rodauth %>.login_param] %>
4
4
  <%%= render "login_hidden_field" %>
5
5
  <%% else %>
6
6
  <%%= render "login_field" %>
@@ -1,3 +1,3 @@
1
- <%%= form_tag rodauth.verify_login_change_path, method: :post do %>
1
+ <%%= form_tag <%= rodauth %>.verify_login_change_path, method: :post do %>
2
2
  <%%= render "submit", value: "Verify Login Change" %>
3
3
  <%% end %>
@@ -1,13 +1,13 @@
1
- <%% cred = rodauth.webauth_credential_options_for_get %>
1
+ <%% cred = <%= rodauth %>.webauth_credential_options_for_get %>
2
2
 
3
- <%%= form_tag rodauth.webauthn_auth_form_path, method: :post, id: "webauthn-auth-form", data: { credential_options: cred.as_json.to_json } do %>
4
- <%%= render "login_hidden_field" if params[rodauth.login_param] %>
5
- <%%= hidden_field_tag rodauth.webauthn_auth_challenge_param, cred.challenge %>
6
- <%%= hidden_field_tag rodauth.webauthn_auth_challenge_hmac_param, rodauth.compute_hmac(cred.challenge) %>
7
- <%%= text_field_tag rodauth.webauthn_auth_param, "", id: "webauthn-auth", aria: { hidden: "true" } %>
3
+ <%%= form_tag <%= rodauth %>.webauthn_auth_form_path, method: :post, id: "webauthn-auth-form", data: { credential_options: cred.as_json.to_json } do %>
4
+ <%%= render "login_hidden_field" if params[<%= rodauth %>.login_param] %>
5
+ <%%= hidden_field_tag <%= rodauth %>.webauthn_auth_challenge_param, cred.challenge %>
6
+ <%%= hidden_field_tag <%= rodauth %>.webauthn_auth_challenge_hmac_param, <%= rodauth %>.compute_hmac(cred.challenge) %>
7
+ <%%= text_field_tag <%= rodauth %>.webauthn_auth_param, "", id: "webauthn-auth", aria: { hidden: "true" } %>
8
8
  <div id="webauthn-auth-button">
9
9
  <%%= render "submit", value: "Authenticate Using WebAuthn" %>
10
10
  </div>
11
11
  <%% end %>
12
12
 
13
- <%%= javascript_include_tag rodauth.webauthn_auth_js_path %>
13
+ <%%= javascript_include_tag <%= rodauth %>.webauthn_auth_js_path %>
@@ -1,11 +1,11 @@
1
- <%%= form_tag rodauth.webauthn_remove_path, method: :post, id: "webauthn-remove-form" do %>
2
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
1
+ <%%= form_tag <%= rodauth %>.webauthn_remove_path, method: :post, id: "webauthn-remove-form" do %>
2
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
3
3
  <fieldset class="form-group mb-3">
4
- <%% (usage = rodauth.account_webauthn_usage).each do |id, last_use| %>
4
+ <%% (usage = <%= rodauth %>.account_webauthn_usage).each do |id, last_use| %>
5
5
  <div class="form-check">
6
- <%%= render "field", name: rodauth.webauthn_remove_param, id: "webauthn-remove-#{id}", type: :radio, class: "form-check-input", skip_error_message: true, value: id, required: false %>
6
+ <%%= render "field", name: <%= rodauth %>.webauthn_remove_param, id: "webauthn-remove-#{id}", type: :radio, class: "form-check-input", skip_error_message: true, value: id, required: false %>
7
7
  <%%= label_tag "webauthn-remove-#{id}", "Last use: #{last_use}", class: "form-check-label" %>
8
- <%%= render "field_error", name: rodauth.webauthn_remove_param if id == usage.keys.last %>
8
+ <%%= render "field_error", name: <%= rodauth %>.webauthn_remove_param if id == usage.keys.last %>
9
9
  </div>
10
10
  <%% end %>
11
11
  </fieldset>
@@ -1,13 +1,13 @@
1
- <%% cred = rodauth.new_webauthn_credential %>
1
+ <%% cred = <%= rodauth %>.new_webauthn_credential %>
2
2
 
3
- <%%= form_tag rodauth.webauthn_setup_path, method: :post, id: "webauthn-setup-form", data: { credential_options: cred.as_json.to_json } do %>
4
- <%%= hidden_field_tag rodauth.webauthn_setup_challenge_param, cred.challenge %>
5
- <%%= hidden_field_tag rodauth.webauthn_setup_challenge_hmac_param, rodauth.compute_hmac(cred.challenge) %>
6
- <%%= text_field_tag rodauth.webauthn_setup_param, "", id: "webauthn-setup", aria: { hidden: "true" } %>
7
- <%%= render "password_field" if rodauth.two_factor_modifications_require_password? %>
3
+ <%%= form_tag <%= rodauth %>.webauthn_setup_path, method: :post, id: "webauthn-setup-form", data: { credential_options: cred.as_json.to_json } do %>
4
+ <%%= hidden_field_tag <%= rodauth %>.webauthn_setup_challenge_param, cred.challenge %>
5
+ <%%= hidden_field_tag <%= rodauth %>.webauthn_setup_challenge_hmac_param, <%= rodauth %>.compute_hmac(cred.challenge) %>
6
+ <%%= text_field_tag <%= rodauth %>.webauthn_setup_param, "", id: "webauthn-setup", aria: { hidden: "true" } %>
7
+ <%%= render "password_field" if <%= rodauth %>.two_factor_modifications_require_password? %>
8
8
  <div id="webauthn-setup-button">
9
9
  <%%= render "submit", value: "Setup WebAuthn Authentication" %>
10
10
  </div>
11
11
  <%% end %>
12
12
 
13
- <%%= javascript_include_tag rodauth.webauthn_setup_js_path %>
13
+ <%%= javascript_include_tag <%= rodauth %>.webauthn_setup_js_path %>
@@ -18,9 +18,9 @@ module Rodauth
18
18
  desc: "Generates views for all Rodauth features",
19
19
  default: false
20
20
 
21
- class_option :directory, aliases: "-d", type: :string,
22
- desc: "The directory under app/views/* into which to create views",
23
- default: "rodauth"
21
+ class_option :name, aliases: "-n", type: :string,
22
+ desc: "The configuration name for which to generate views",
23
+ default: nil
24
24
 
25
25
  VIEWS = {
26
26
  login: %w[
@@ -112,9 +112,30 @@ module Rodauth
112
112
 
113
113
  views.each do |view|
114
114
  template "app/views/rodauth/#{view}.html.erb",
115
- "app/views/#{options[:directory].underscore}/#{view}.html.erb"
115
+ "app/views/#{directory}/#{view}.html.erb"
116
116
  end
117
117
  end
118
+
119
+ def directory
120
+ if controller.abstract?
121
+ fail Error, "no controller configured for configuration: #{configuration_name.inspect}"
122
+ end
123
+
124
+ controller.controller_path
125
+ end
126
+
127
+ def rodauth
128
+ "rodauth#{"(:#{configuration_name})" if configuration_name}"
129
+ end
130
+
131
+ def controller
132
+ rodauth = Rodauth::Rails.rodauth(configuration_name)
133
+ rodauth.rails_controller
134
+ end
135
+
136
+ def configuration_name
137
+ options[:name]&.to_sym
138
+ end
118
139
  end
119
140
  end
120
141
  end
@@ -6,20 +6,17 @@ module Rodauth
6
6
  # Base auth class that applies some default configuration and supports
7
7
  # multi-level inheritance.
8
8
  class Auth < Rodauth::Auth
9
- class << self
10
- attr_writer :features
11
- attr_writer :routes
12
- attr_accessor :configuration
13
- end
14
-
15
9
  def self.inherited(auth_class)
16
10
  super
17
- auth_class.roda_class = Rodauth::Rails.app
18
- auth_class.features = features.dup
19
- auth_class.routes = routes.dup
20
- auth_class.route_hash = route_hash.dup
21
- auth_class.configuration = configuration.clone
22
- auth_class.configuration.instance_variable_set(:@auth, auth_class)
11
+ superclass = self
12
+ auth_class.class_eval do
13
+ @roda_class = Rodauth::Rails.app
14
+ @features = superclass.features.clone
15
+ @routes = superclass.routes.clone
16
+ @route_hash = superclass.route_hash.clone
17
+ @configuration = superclass.instance_variable_get(:@configuration).clone
18
+ @configuration.instance_variable_set(:@auth, self)
19
+ end
23
20
  end
24
21
 
25
22
  # apply default configuration
@@ -22,6 +22,14 @@ module Rodauth
22
22
  rails_controller_instance.instance_exec(&block)
23
23
  end
24
24
 
25
+ def rails_controller
26
+ if only_json? && Rodauth::Rails.api_only?
27
+ ActionController::API
28
+ else
29
+ ActionController::Base
30
+ end
31
+ end
32
+
25
33
  delegate :rails_routes, :rails_request, to: :scope
26
34
 
27
35
  private
@@ -48,14 +56,6 @@ module Rodauth
48
56
  def rails_api_controller?
49
57
  defined?(ActionController::API) && rails_controller <= ActionController::API
50
58
  end
51
-
52
- def rails_controller
53
- if only_json? && Rodauth::Rails.api_only?
54
- ActionController::API
55
- else
56
- ActionController::Base
57
- end
58
- end
59
59
  end
60
60
  end
61
61
  end
@@ -35,6 +35,13 @@ module Rodauth
35
35
  rescue ActionView::MissingTemplate
36
36
  nil
37
37
  end
38
+
39
+ # Only look up template formats that the current request is accepting.
40
+ def _rails_controller_instance
41
+ controller = super
42
+ controller.formats = rails_request.formats.map(&:ref).compact
43
+ controller
44
+ end
38
45
  end
39
46
  end
40
47
  end
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "0.12.0"
3
+ VERSION = "0.14.0"
4
4
  end
5
5
  end
data/lib/rodauth/rails.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require "rodauth/rails/version"
2
2
  require "rodauth/rails/railtie"
3
3
 
4
+ require "rack/utils"
5
+ require "stringio"
6
+
4
7
  module Rodauth
5
8
  module Rails
6
9
  class Error < StandardError
@@ -14,7 +17,11 @@ module Rodauth
14
17
  @middleware = true
15
18
 
16
19
  class << self
17
- def rodauth(name = nil)
20
+ def rodauth(name = nil, query: {}, form: {}, session: {}, account: nil, env: {})
21
+ unless app.rodauth(name)
22
+ fail ArgumentError, "undefined rodauth configuration: #{name.inspect}"
23
+ end
24
+
18
25
  url_options = ActionMailer::Base.default_url_options
19
26
 
20
27
  scheme = url_options[:protocol] || "http"
@@ -23,14 +30,29 @@ module Rodauth
23
30
  host = url_options[:host]
24
31
  host += ":#{port}" if port
25
32
 
33
+ content_type = "application/x-www-form-urlencoded" if form.any?
34
+
26
35
  rack_env = {
36
+ "QUERY_STRING" => Rack::Utils.build_nested_query(query),
37
+ "rack.input" => StringIO.new(Rack::Utils.build_nested_query(form)),
38
+ "CONTENT_TYPE" => content_type,
39
+ "rack.session" => {},
27
40
  "HTTP_HOST" => host,
28
41
  "rack.url_scheme" => scheme,
29
- }
42
+ }.merge(env)
30
43
 
31
- scope = app.new(rack_env)
44
+ scope = app.new(rack_env)
45
+ instance = scope.rodauth(name)
46
+
47
+ # update session hash here to make it work with JWT session
48
+ instance.session.merge!(session)
49
+
50
+ if account
51
+ instance.instance_variable_set(:@account, account.attributes.symbolize_keys)
52
+ instance.session[instance.session_key] = instance.account_session_value
53
+ end
32
54
 
33
- scope.rodauth(name)
55
+ instance
34
56
  end
35
57
 
36
58
  # routing constraint that requires authentication
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.12.0
4
+ version: 0.14.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-15 00:00:00.000000000 Z
11
+ date: 2021-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
237
  - !ruby/object:Gem::Version
238
238
  version: '0'
239
239
  requirements: []
240
- rubygems_version: 3.2.3
240
+ rubygems_version: 3.2.15
241
241
  signing_key:
242
242
  specification_version: 4
243
243
  summary: Provides Rails integration for Rodauth.