rodauth-rails 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +29 -4
  4. data/lib/generators/rodauth/templates/INSTRUCTIONS +11 -1
  5. data/lib/generators/rodauth/templates/app/misc/rodauth_main.rb +3 -0
  6. data/lib/generators/rodauth/templates/app/views/rodauth/add_recovery_codes.html.erb +0 -2
  7. data/lib/generators/rodauth/templates/app/views/rodauth/change_login.html.erb +0 -2
  8. data/lib/generators/rodauth/templates/app/views/rodauth/change_password.html.erb +0 -2
  9. data/lib/generators/rodauth/templates/app/views/rodauth/close_account.html.erb +0 -2
  10. data/lib/generators/rodauth/templates/app/views/rodauth/confirm_password.html.erb +0 -2
  11. data/lib/generators/rodauth/templates/app/views/rodauth/create_account.html.erb +0 -2
  12. data/lib/generators/rodauth/templates/app/views/rodauth/email_auth.html.erb +0 -2
  13. data/lib/generators/rodauth/templates/app/views/rodauth/login.html.erb +0 -2
  14. data/lib/generators/rodauth/templates/app/views/rodauth/logout.html.erb +0 -2
  15. data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +0 -2
  16. data/lib/generators/rodauth/templates/app/views/rodauth/otp_auth.html.erb +0 -2
  17. data/lib/generators/rodauth/templates/app/views/rodauth/otp_disable.html.erb +0 -2
  18. data/lib/generators/rodauth/templates/app/views/rodauth/otp_setup.html.erb +0 -2
  19. data/lib/generators/rodauth/templates/app/views/rodauth/recovery_auth.html.erb +0 -2
  20. data/lib/generators/rodauth/templates/app/views/rodauth/recovery_codes.html.erb +0 -2
  21. data/lib/generators/rodauth/templates/app/views/rodauth/remember.html.erb +0 -2
  22. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password.html.erb +0 -2
  23. data/lib/generators/rodauth/templates/app/views/rodauth/reset_password_request.html.erb +0 -2
  24. data/lib/generators/rodauth/templates/app/views/rodauth/sms_auth.html.erb +0 -2
  25. data/lib/generators/rodauth/templates/app/views/rodauth/sms_confirm.html.erb +0 -2
  26. data/lib/generators/rodauth/templates/app/views/rodauth/sms_disable.html.erb +0 -2
  27. data/lib/generators/rodauth/templates/app/views/rodauth/sms_request.html.erb +0 -2
  28. data/lib/generators/rodauth/templates/app/views/rodauth/sms_setup.html.erb +0 -2
  29. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_auth.html.erb +0 -2
  30. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_disable.html.erb +0 -2
  31. data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_manage.html.erb +0 -2
  32. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account.html.erb +0 -2
  33. data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account_request.html.erb +0 -2
  34. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account.html.erb +0 -2
  35. data/lib/generators/rodauth/templates/app/views/rodauth/verify_account_resend.html.erb +0 -2
  36. data/lib/generators/rodauth/templates/app/views/rodauth/verify_login_change.html.erb +0 -2
  37. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_auth.html.erb +0 -2
  38. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_remove.html.erb +0 -2
  39. data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_setup.html.erb +0 -2
  40. data/lib/rodauth/rails/feature/render.rb +8 -1
  41. data/lib/rodauth/rails/version.rb +1 -1
  42. data/lib/rodauth/rails.rb +1 -1
  43. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a42fbc8522feb0a7d18227ca1cb3d79448c6d5d824befb040699afdb69318ea
4
- data.tar.gz: 4d60492cc1ea2acf8176ffb6a05c6f0aba7deda63d1541da42de7f558e55b6e6
3
+ metadata.gz: 43e0f2c048024645cb8af7e744042187ded20eeca3f685bdf28a959aebf296e0
4
+ data.tar.gz: 96d02ad057f315a339bc1cda804f71e19cd629a9cb2ca5c574c515d954692673
5
5
  SHA512:
6
- metadata.gz: 8782debac4a0b3bea9bb1849ab0817966f62c3bcf0cf352c2cf83d68e0fc35bce83a321e8c49f96d027450b87d6c196afd1e451a6e79e53cd35328dd84893d8c
7
- data.tar.gz: 24de3dec4d061a9421de53062d75959d67091aff43dc26bf7f7fd749664e2288a4a9c198f24fa4ce8890b0c88f38c294d85a565b09aae330c0bcf7674242f112
6
+ metadata.gz: c943289cb0c628b37d89fcc6e2a0b22b190ba0e0c0351ffc53c726ac81b0c9f87b0b6e1f929a823724fa1aed70c5b5601279b24df5b54026cb06bb073c3b284c
7
+ data.tar.gz: afb5b6523b6c440c9b02255b047cf562dd0122a6abb8d49f7c93671981c75935d6a1a9ab1c27a9e8158578a928b70b3705db24760db803acd79abafa58cdc4ce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.5.0 (2022-06-11)
2
+
3
+ * Remove `content_for` calls from generated view templates (@janko)
4
+
5
+ * Set title instance variable to `@page_title` in generated configuration (@janko)
6
+
7
+ * Set title instance variable on the controller when `title_instance_variable` is set (@HoneyryderChuck)
8
+
1
9
  ## 1.4.2 (2022-05-15)
2
10
 
3
11
  * Stop passing email addresses in mailer arguments on verifying login change (@janko)
data/README.md CHANGED
@@ -321,16 +321,26 @@ $ rails generate rodauth:views webauthn --name admin
321
321
 
322
322
  #### Page titles
323
323
 
324
- The generated view templates use `content_for(:title)` to store Rodauth's page
325
- titles, which you can then retrieve in your layout template to set the page
326
- title:
324
+ The generated configuration sets `title_instance_variable` to make page titles
325
+ available in your views via `@page_title` instance variable, which you can then
326
+ use in your layout:
327
327
 
328
+ ```rb
329
+ # app/misc/rodauth_main.rb
330
+ class RodauthMain < Rodauth::Rails::Auth
331
+ configure do
332
+ # ...
333
+ title_instance_variable :@page_title
334
+ # ...
335
+ end
336
+ end
337
+ ```
328
338
  ```erb
329
339
  <!-- app/views/layouts/application.html.erb -->
330
340
  <!DOCTYPE html>
331
341
  <html>
332
342
  <head>
333
- <title><%= content_for(:title) %></title>
343
+ <title><%= @page_title || "Default title" %></title>
334
344
  <!-- ... -->
335
345
  </head>
336
346
  <body>
@@ -339,6 +349,21 @@ title:
339
349
  </html>
340
350
  ```
341
351
 
352
+ If you're already setting page titles via `content_for`, you can use it in
353
+ generated Rodauth views, giving it the result of the corresponding
354
+ `*_page_title` method:
355
+
356
+ ```erb
357
+ <!-- app/views/rodauth/login.html.erb -->
358
+ <%= content_for :page_title, rodauth.login_page_title %>
359
+ <!-- ... -->
360
+ ```
361
+ ```erb
362
+ <!-- app/views/rodauth/change_password.html.erb -->
363
+ <%= content_for :page_title, rodauth.change_password_page_title %>
364
+ <!-- ... -->
365
+ ```
366
+
342
367
  #### Layout
343
368
 
344
369
  To use different layouts for different Rodauth views, you can compare the
@@ -31,7 +31,17 @@ Depending on your application's configuration some manual setup may be required:
31
31
 
32
32
  * Not required for API-only Applications *
33
33
 
34
- 4. You can copy Rodauth views (for customization) to your app by running:
34
+ 4. Titles for Rodauth pages are available via @page_title instance variable
35
+ by default, you can use it in your layout file:
36
+
37
+ <head>
38
+ <title><%= @page_title || "Default title" %></title>
39
+ ...
40
+ </head>
41
+
42
+ * Not required *
43
+
44
+ 5. You can copy Rodauth views (for customization) to your app by running:
35
45
 
36
46
  rails g rodauth:views
37
47
 
@@ -31,6 +31,9 @@ class RodauthMain < Rodauth::Rails::Auth
31
31
  # Specify the controller used for view rendering and CSRF verification.
32
32
  rails_controller { RodauthController }
33
33
 
34
+ # Set on Rodauth controller with the title of the current page.
35
+ title_instance_variable :@page_title
36
+
34
37
  # Store account status in an integer column without foreign key constraint.
35
38
  account_status_column :status
36
39
 
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.add_recovery_codes_page_title %>
2
-
3
1
  <pre id="recovery-codes"><%= rodauth.recovery_codes.map { |s| h(s) }.join("\n\n") %></pre>
4
2
 
5
3
  <% if rodauth.can_add_recovery_codes? %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.change_login_page_title %>
2
-
3
1
  <%= form_with url: rodauth.change_login_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "login", rodauth.login_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.change_password_page_title %>
2
-
3
1
  <%= form_with url: rodauth.change_password_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.change_password_requires_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.close_account_page_title %>
2
-
3
1
  <%= form_with url: rodauth.close_account_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.close_account_requires_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.confirm_password_page_title %>
2
-
3
1
  <%= form_with url: rodauth.confirm_password_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "password", rodauth.password_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.create_account_page_title %>
2
-
3
1
  <%= form_with url: rodauth.create_account_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "login", rodauth.login_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.email_auth_page_title %>
2
-
3
1
  <%= form_with url: rodauth.email_auth_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.submit rodauth.login_button, class: "btn btn-primary" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.login_page_title %>
2
-
3
1
  <%= render "login_form_header" %>
4
2
  <%= render "login_form" %>
5
3
  <%= render "login_form_footer" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.logout_page_title %>
2
-
3
1
  <%= form_with url: rodauth.logout_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.features.include?(:active_sessions) %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.multi_phase_login_page_title %>
2
-
3
1
  <%= render "login_form_header" %>
4
2
  <%== rodauth.render_multi_phase_login_forms %>
5
3
  <%= render "login_form_footer" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.otp_auth_page_title %>
2
-
3
1
  <%= form_with url: rodauth.otp_auth_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "otp-auth-code", rodauth.otp_auth_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.otp_disable_page_title %>
2
-
3
1
  <%= form_with url: rodauth.otp_disable_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.two_factor_modifications_require_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.otp_setup_page_title %>
2
-
3
1
  <%= form_with url: rodauth.otp_setup_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <%= form.hidden_field rodauth.otp_setup_param, value: rodauth.otp_user_key, id: "otp-key" %>
5
3
  <%= form.hidden_field rodauth.otp_setup_raw_param, value: rodauth.otp_key, id: "otp-hmac-secret" if rodauth.otp_keys_use_hmac? %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.recovery_auth_page_title %>
2
-
3
1
  <%= form_with url: rodauth.recovery_auth_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "recovery-code", rodauth.recovery_codes_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.recovery_codes_page_title %>
2
-
3
1
  <%= form_with url: rodauth.recovery_codes_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.two_factor_modifications_require_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.remember_page_title %>
2
-
3
1
  <%= form_with url: rodauth.remember_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <fieldset class="form-group mb-3">
5
3
  <div class="form-check">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.reset_password_page_title %>
2
-
3
1
  <%= form_with url: rodauth.reset_password_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "password", rodauth.password_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.reset_password_request_page_title %>
2
-
3
1
  <%= form_with url: rodauth.reset_password_request_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <%== rodauth.reset_password_explanatory_text %>
5
3
 
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.sms_auth_page_title %>
2
-
3
1
  <%= form_with url: rodauth.sms_auth_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "sms-code", rodauth.sms_code_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.sms_confirm_page_title %>
2
-
3
1
  <%= form_with url: rodauth.sms_confirm_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.label "sms-code", rodauth.sms_code_label, class: "form-label" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.sms_disable_page_title %>
2
-
3
1
  <%= form_with url: rodauth.sms_disable_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.two_factor_modifications_require_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.sms_request_page_title %>
2
-
3
1
  <%= form_with url: rodauth.sms_request_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.submit rodauth.sms_request_button, class: "btn btn-primary" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.sms_setup_page_title %>
2
-
3
1
  <%= form_with url: rodauth.sms_setup_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.two_factor_modifications_require_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.two_factor_auth_page_title %>
2
-
3
1
  <ul>
4
2
  <% rodauth.two_factor_auth_links.sort.each do |_, link, text| %>
5
3
  <li><%= link_to text, link %></li>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.two_factor_disable_page_title %>
2
-
3
1
  <%= form_with url: rodauth.two_factor_disable_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.two_factor_modifications_require_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.two_factor_manage_page_title %>
2
-
3
1
  <% if rodauth.two_factor_setup_links.any? %>
4
2
  <%== rodauth.two_factor_setup_heading %>
5
3
 
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.unlock_account_page_title %>
2
-
3
1
  <%= form_with url: rodauth.unlock_account_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <%== rodauth.unlock_account_explanatory_text %>
5
3
 
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.unlock_account_request_page_title %>
2
-
3
1
  <%= form_with url: rodauth.unlock_account_request_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <%= form.hidden_field rodauth.login_param, value: params[rodauth.login_param] %>
5
3
 
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.verify_account_page_title %>
2
-
3
1
  <%= form_with url: rodauth.verify_account_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <% if rodauth.verify_account_set_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.resend_verify_account_page_title %>
2
-
3
1
  <%= form_with url: rodauth.verify_account_resend_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <%== rodauth.verify_account_resend_explanatory_text %>
5
3
 
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.verify_login_change_page_title %>
2
-
3
1
  <%= form_with url: rodauth.verify_login_change_path, method: :post, data: { turbo: false } do |form| %>
4
2
  <div class="form-group mb-3">
5
3
  <%= form.submit rodauth.verify_login_change_button, class: "btn btn-primary" %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.webauthn_auth_page_title %>
2
-
3
1
  <% cred = rodauth.webauth_credential_options_for_get %>
4
2
 
5
3
  <%= form_with url: rodauth.webauthn_auth_form_path, method: :post, id: "webauthn-auth-form", data: { credential_options: cred.as_json.to_json, turbo: false } do |form| %>
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.webauthn_remove_page_title %>
2
-
3
1
  <%= form_with url: rodauth.webauthn_remove_path, method: :post, id: "webauthn-remove-form", data: { turbo: false } do |form| %>
4
2
  <% if rodauth.two_factor_modifications_require_password? %>
5
3
  <div class="form-group mb-3">
@@ -1,5 +1,3 @@
1
- <% content_for :title, rodauth.webauthn_setup_page_title %>
2
-
3
1
  <% cred = rodauth.new_webauthn_credential %>
4
2
 
5
3
  <%= form_with url: rodauth.webauthn_setup_path, method: :post, id: "webauthn-setup-form", data: { credential_options: cred.as_json.to_json, turbo: false } do |form| %>
@@ -8,7 +8,8 @@ module Rodauth
8
8
 
9
9
  # Renders templates with layout. First tries to render a user-defined
10
10
  # template, otherwise falls back to Rodauth's template.
11
- def view(page, *)
11
+ def view(page, title)
12
+ set_title(title)
12
13
  rails_render(action: page.tr("-", "_"), layout: true) ||
13
14
  rails_render(html: super.html_safe, layout: true, formats: :html)
14
15
  end
@@ -50,6 +51,12 @@ module Rodauth
50
51
  html = html.gsub(/<form(.+)>/, '<form\1 data-turbo="false">') if meth == :view
51
52
  html
52
53
  end
54
+
55
+ def set_title(title)
56
+ if title_instance_variable
57
+ rails_controller_instance.instance_variable_set(title_instance_variable, title)
58
+ end
59
+ end
53
60
  end
54
61
  end
55
62
  end
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "1.4.2"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
data/lib/rodauth/rails.rb CHANGED
@@ -16,7 +16,7 @@ module Rodauth
16
16
  @middleware = true
17
17
 
18
18
  class << self
19
- def rodauth(name = nil, query: nil, form: nil, account: nil, **options)
19
+ def rodauth(name = nil, account: nil, **options)
20
20
  auth_class = app.rodauth!(name)
21
21
 
22
22
  unless auth_class.features.include?(:internal_request)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.5.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: 2022-05-15 00:00:00.000000000 Z
11
+ date: 2022-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties