rodauth-rails 0.13.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 +16 -0
  3. data/README.md +86 -14
  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.rb +4 -0
  58. data/lib/rodauth/rails/auth.rb +9 -12
  59. data/lib/rodauth/rails/feature/base.rb +8 -8
  60. data/lib/rodauth/rails/feature/render.rb +7 -0
  61. data/lib/rodauth/rails/version.rb +1 -1
  62. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc8ee44d094627dcacd9d9b7f5da1eb165cff1af209f079b667e0f04e9540b30
4
- data.tar.gz: f179e4eaea99d04ff6ff71c6357cdf75a19991645c9904ab6373c03b5dcd1a16
3
+ metadata.gz: d447d09fef8c29feb6240523286b8906049e85965f20a6410d1a475f913d9051
4
+ data.tar.gz: bca9b6eadec6b32f2193291c6922467a554105d290ffd7b34bc2606d62121926
5
5
  SHA512:
6
- metadata.gz: 78c28c13751abb439179813948bf665cd040444171998e42ecdb4cb42f698097731f4c073b7595d083ba5825a9989940deee052771fb5f76f93bd333e94af500
7
- data.tar.gz: eb3a04ae6333dc471fd7fbdb264527a359893fb100d7833bab3545f7d91e213bfc8a2daa562ffc22f531073f39f4bee3de893bffd87201b3e57d1dce99c97320
6
+ metadata.gz: 1f512f9fe9a3e22dcddf477d8906d1ea63a548241fd93b43bbcaf274ff39e0104e20f64c6a2836e5b243e812ffde654deae55a0beca69f4ba917cd5943da8a3c
7
+ data.tar.gz: dbbd99959dfd42134cd3374f1f9767cf3e8d49327c195d4c35c4ecf281d0c3dad52db76b7e2fbf030c9e3ea2131bfcb1b6a120cc4a310983d8db564e63b97cda
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
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
+
1
17
  ## 0.13.0 (2021-06-10)
2
18
 
3
19
  * Add `:query`, `:form`, `:session`, `:account`, and `:env` options to `Rodauth::Rails.rodauth` (@janko)
data/README.md CHANGED
@@ -49,7 +49,7 @@ For instructions on upgrading from previous rodauth-rails versions, see
49
49
  Add the gem to your Gemfile:
50
50
 
51
51
  ```rb
52
- gem "rodauth-rails", "~> 0.13"
52
+ gem "rodauth-rails", "~> 0.14"
53
53
 
54
54
  # gem "jwt", require: false # for JWT feature
55
55
  # gem "rotp", require: false # for OTP feature
@@ -278,8 +278,8 @@ $ rails generate rodauth:views
278
278
  ```
279
279
 
280
280
  This will generate views for the default set of Rodauth features into the
281
- `app/views/rodauth` directory, which will be automatically picked up by the
282
- `RodauthController`.
281
+ `app/views/rodauth` directory, provided that `RodauthController` is set for the
282
+ main configuration.
283
283
 
284
284
  You can pass a list of Rodauth features to the generator to create views for
285
285
  these features (this will not remove or overwrite any existing views):
@@ -294,12 +294,10 @@ Or you can generate views for all features:
294
294
  $ rails generate rodauth:views --all
295
295
  ```
296
296
 
297
- You can also tell the generator to create views into another directory (in this
298
- case make sure to rename the Rodauth controller accordingly):
297
+ Use `--name` to generate views for a different Rodauth configuration:
299
298
 
300
299
  ```sh
301
- # generates views into app/views/authentication
302
- $ rails generate rodauth:views --name authentication
300
+ $ rails generate rodauth:views --name admin
303
301
  ```
304
302
 
305
303
  #### Layout
@@ -392,14 +390,48 @@ end
392
390
  This configuration calls `#deliver_later`, which uses Active Job to deliver
393
391
  emails in a background job. It's generally recommended to send emails
394
392
  asynchronously for better request throughput and the ability to retry
395
- deliveries. However, if you want to send emails synchronously, modify the
396
- 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.
397
395
 
398
396
  If you're using a background processing library without an Active Job adapter,
399
397
  or a 3rd-party service for sending transactional emails, this two-phase API
400
398
  might not be suitable. In this case, instead of overriding `#create_*_email`
401
399
  and `#send_email`, override the `#send_*_email` methods instead, which are
402
- 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
+ ```
403
435
 
404
436
  ### Migrations
405
437
 
@@ -440,10 +472,6 @@ class RodauthApp < Rodauth::Rails::App
440
472
  prefix "/admin"
441
473
  session_key_prefix "admin_"
442
474
  remember_cookie_key "_admin_remember" # if using remember feature
443
-
444
- # if you want separate tables
445
- accounts_table :admin_accounts
446
- password_hash_table :admin_account_password_hashes
447
475
  # ...
448
476
  end
449
477
 
@@ -466,6 +494,50 @@ Then in your application you can reference the secondary Rodauth instance:
466
494
  rodauth(:admin).login_path #=> "/admin/login"
467
495
  ```
468
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
+
469
541
  #### Named auth classes
470
542
 
471
543
  A `configure` block inside `Rodauth::Rails::App` will internally create an
@@ -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
data/lib/rodauth/rails.rb CHANGED
@@ -18,6 +18,10 @@ module Rodauth
18
18
 
19
19
  class << self
20
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
+
21
25
  url_options = ActionMailer::Base.default_url_options
22
26
 
23
27
  scheme = url_options[:protocol] || "http"
@@ -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.13.0"
3
+ VERSION = "0.14.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.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-06-10 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