rodauth-rails 0.12.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +304 -98
  4. data/lib/generators/rodauth/templates/app/lib/rodauth_app.rb +8 -4
  5. data/lib/generators/rodauth/templates/app/models/account.rb +1 -0
  6. data/lib/generators/rodauth/templates/app/views/rodauth/_email_auth_request_form.html.erb +1 -1
  7. data/lib/generators/rodauth/templates/app/views/rodauth/_field.html.erb +2 -2
  8. data/lib/generators/rodauth/templates/app/views/rodauth/_field_error.html.erb +2 -2
  9. data/lib/generators/rodauth/templates/app/views/rodauth/_global_logout_field.html.erb +1 -1
  10. data/lib/generators/rodauth/templates/app/views/rodauth/_login_confirm_field.html.erb +1 -1
  11. data/lib/generators/rodauth/templates/app/views/rodauth/_login_display.html.erb +1 -1
  12. data/lib/generators/rodauth/templates/app/views/rodauth/_login_field.html.erb +1 -1
  13. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb +3 -3
  14. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_footer.html.erb +2 -2
  15. data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb +2 -2
  16. data/lib/generators/rodauth/templates/app/views/rodauth/_login_hidden_field.html.erb +1 -1
  17. data/lib/generators/rodauth/templates/app/views/rodauth/_new_password_field.html.erb +1 -1
  18. data/lib/generators/rodauth/templates/app/views/rodauth/_otp_auth_code_field.html.erb +1 -1
  19. data/lib/generators/rodauth/templates/app/views/rodauth/_password_confirm_field.html.erb +1 -1
  20. data/lib/generators/rodauth/templates/app/views/rodauth/_password_field.html.erb +1 -1
  21. data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_code_field.html.erb +1 -1
  22. data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_codes_form.html.erb +4 -4
  23. data/lib/generators/rodauth/templates/app/views/rodauth/_sms_code_field.html.erb +1 -1
  24. data/lib/generators/rodauth/templates/app/views/rodauth/_sms_phone_field.html.erb +1 -1
  25. data/lib/generators/rodauth/templates/app/views/rodauth/add_recovery_codes.html.erb +2 -2
  26. data/lib/generators/rodauth/templates/app/views/rodauth/change_login.html.erb +3 -3
  27. data/lib/generators/rodauth/templates/app/views/rodauth/change_password.html.erb +3 -3
  28. data/lib/generators/rodauth/templates/app/views/rodauth/close_account.html.erb +2 -2
  29. data/lib/generators/rodauth/templates/app/views/rodauth/confirm_password.html.erb +1 -1
  30. data/lib/generators/rodauth/templates/app/views/rodauth/create_account.html.erb +4 -4
  31. data/lib/generators/rodauth/templates/app/views/rodauth/email_auth.html.erb +1 -1
  32. data/lib/generators/rodauth/templates/app/views/rodauth/logout.html.erb +2 -2
  33. data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +1 -1
  34. data/lib/generators/rodauth/templates/app/views/rodauth/otp_auth.html.erb +1 -1
  35. data/lib/generators/rodauth/templates/app/views/rodauth/otp_disable.html.erb +2 -2
  36. data/lib/generators/rodauth/templates/app/views/rodauth/otp_setup.html.erb +7 -7
  37. data/lib/generators/rodauth/templates/app/views/rodauth/recovery_auth.html.erb +1 -1
  38. data/lib/generators/rodauth/templates/app/views/rodauth/remember.html.erb +4 -4
  39. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password.html.erb +2 -2
  40. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password_request.html.erb +2 -2
  41. data/lib/generators/rodauth/templates/app/views/rodauth/sms_auth.html.erb +1 -1
  42. data/lib/generators/rodauth/templates/app/views/rodauth/sms_confirm.html.erb +1 -1
  43. data/lib/generators/rodauth/templates/app/views/rodauth/sms_disable.html.erb +2 -2
  44. data/lib/generators/rodauth/templates/app/views/rodauth/sms_request.html.erb +1 -1
  45. data/lib/generators/rodauth/templates/app/views/rodauth/sms_setup.html.erb +2 -2
  46. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_auth.html.erb +1 -1
  47. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_disable.html.erb +2 -2
  48. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_manage.html.erb +6 -6
  49. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account.html.erb +2 -2
  50. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account_request.html.erb +1 -1
  51. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account.html.erb +3 -3
  52. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account_resend.html.erb +2 -2
  53. data/lib/generators/rodauth/templates/app/views/rodauth/verify_login_change.html.erb +1 -1
  54. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_auth.html.erb +7 -7
  55. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_remove.html.erb +5 -5
  56. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_setup.html.erb +7 -7
  57. data/lib/generators/rodauth/views_generator.rb +29 -4
  58. data/lib/rodauth/rails/auth.rb +10 -13
  59. data/lib/rodauth/rails/controller_methods.rb +43 -1
  60. data/lib/rodauth/rails/feature/base.rb +8 -8
  61. data/lib/rodauth/rails/feature/callbacks.rb +6 -2
  62. data/lib/rodauth/rails/feature/internal_request.rb +50 -0
  63. data/lib/rodauth/rails/feature/render.rb +7 -0
  64. data/lib/rodauth/rails/feature.rb +2 -0
  65. data/lib/rodauth/rails/model/associations.rb +195 -0
  66. data/lib/rodauth/rails/model.rb +101 -0
  67. data/lib/rodauth/rails/tasks.rake +5 -5
  68. data/lib/rodauth/rails/version.rb +1 -1
  69. data/lib/rodauth/rails.rb +30 -13
  70. data/rodauth-rails.gemspec +4 -1
  71. metadata +50 -5
@@ -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[
@@ -61,6 +61,9 @@ module Rodauth
61
61
  _field _field_error _login_hidden_field _login_field _submit
62
62
  verify_account_resend verify_account
63
63
  ],
64
+ verify_login_change: %w[
65
+ _submit verify_login_change
66
+ ],
64
67
  lockout: %w[
65
68
  _login_hidden_field _submit unlock_account_request unlock_account
66
69
  ],
@@ -112,8 +115,30 @@ module Rodauth
112
115
 
113
116
  views.each do |view|
114
117
  template "app/views/rodauth/#{view}.html.erb",
115
- "app/views/#{options[:directory].underscore}/#{view}.html.erb"
118
+ "app/views/#{directory}/#{view}.html.erb"
119
+ end
120
+ end
121
+
122
+ def directory
123
+ if controller.abstract?
124
+ fail Error, "no controller configured for configuration: #{configuration_name.inspect}"
116
125
  end
126
+
127
+ controller.controller_path
128
+ end
129
+
130
+ def rodauth
131
+ "rodauth#{"(:#{configuration_name})" if configuration_name}"
132
+ end
133
+
134
+ def controller
135
+ rodauth = Rodauth::Rails.app.rodauth(configuration_name)
136
+ fail ArgumentError, "unknown rodauth configuration: #{configuration_name.inspect}" unless rodauth
137
+ rodauth.allocate.rails_controller
138
+ end
139
+
140
+ def configuration_name
141
+ options[:name]&.to_sym
117
142
  end
118
143
  end
119
144
  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
- def self.inherited(auth_class)
9
+ def self.inherited(subclass)
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
+ subclass.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