rodauth-rails 1.4.2 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +42 -16
- data/lib/generators/rodauth/install_generator.rb +7 -0
- data/lib/generators/rodauth/migration/sequel/base.erb +4 -1
- data/lib/generators/rodauth/templates/INSTRUCTIONS +11 -1
- data/lib/generators/rodauth/templates/app/misc/rodauth_main.rb +3 -0
- data/lib/generators/rodauth/templates/app/test/fixtures/accounts.yml +10 -0
- data/lib/generators/rodauth/templates/app/views/rodauth/add_recovery_codes.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/change_login.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/change_password.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/close_account.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/confirm_password.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/create_account.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/email_auth.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/login.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/logout.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/otp_auth.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/otp_disable.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/otp_setup.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/recovery_auth.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/recovery_codes.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/remember.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/reset_password.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/reset_password_request.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_auth.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_confirm.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_disable.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_request.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_setup.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_auth.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_disable.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_manage.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account_request.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/verify_account.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/verify_account_resend.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/verify_login_change.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_auth.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_remove.html.erb +0 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_setup.html.erb +0 -2
- data/lib/rodauth/rails/app.rb +6 -0
- data/lib/rodauth/rails/feature/instrumentation.rb +1 -1
- data/lib/rodauth/rails/feature/render.rb +8 -1
- data/lib/rodauth/rails/tasks.rake +19 -5
- data/lib/rodauth/rails/version.rb +1 -1
- data/lib/rodauth/rails.rb +1 -1
- data/rodauth-rails.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d36f5274c33c95aab970521c38b77e9ac47242cc248e181f122b8ef518e5017
|
4
|
+
data.tar.gz: d52e7ec12ebde869a023d6123b5550b061bb4210bc44bd4f4fa8200e592cf94d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8162dd61a98976e3b06d6cee8575197f284e3415c8edcfa30ceed005fbedfe18f3d1c739253ce967434c35dc1ce01b246bd535069daaec92d71c807f2c91ac5
|
7
|
+
data.tar.gz: cb6fe07c7cdb2a7d310ec1dcd60f35170fc478230b33d8cb193797b4db824c519ac4f2de588ff2f176ca96b7746ea7573a116e4497436eccaa640f073c8927ac
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## 1.5.2 (2022-07-03)
|
2
|
+
|
3
|
+
* Bump Rodauth dependency version to 2.25+ (@janko)
|
4
|
+
|
5
|
+
* Generate fixture file for accounts on `rodauth:install` (@benkoshy)
|
6
|
+
|
7
|
+
* Fix error about undefined `controller_path` method in `newrelic_rpm` gem instrumentation (@janko)
|
8
|
+
|
9
|
+
* Don't display disabled routes in `rodauth:routes` (@janko)
|
10
|
+
|
11
|
+
* Display HTTP verbs of endpoints in `rodauth:routes` rake task (@janko)
|
12
|
+
|
13
|
+
## 1.5.1 (2022-06-19)
|
14
|
+
|
15
|
+
* Fix syntax for creating `citext` PG extension in Sequel base migration (@Empact)
|
16
|
+
|
17
|
+
## 1.5.0 (2022-06-11)
|
18
|
+
|
19
|
+
* Remove `content_for` calls from generated view templates (@janko)
|
20
|
+
|
21
|
+
* Set title instance variable to `@page_title` in generated configuration (@janko)
|
22
|
+
|
23
|
+
* Set title instance variable on the controller when `title_instance_variable` is set (@HoneyryderChuck)
|
24
|
+
|
1
25
|
## 1.4.2 (2022-05-15)
|
2
26
|
|
3
27
|
* Stop passing email addresses in mailer arguments on verifying login change (@janko)
|
data/README.md
CHANGED
@@ -110,18 +110,18 @@ $ rails rodauth:routes
|
|
110
110
|
```
|
111
111
|
Routes handled by RodauthApp:
|
112
112
|
|
113
|
-
/login rodauth.login_path
|
114
|
-
/create-account rodauth.create_account_path
|
115
|
-
/verify-account-resend rodauth.verify_account_resend_path
|
116
|
-
/verify-account rodauth.verify_account_path
|
117
|
-
/change-password rodauth.change_password_path
|
118
|
-
/change-login rodauth.change_login_path
|
119
|
-
/logout rodauth.logout_path
|
120
|
-
/remember rodauth.remember_path
|
121
|
-
/reset-password-request rodauth.reset_password_request_path
|
122
|
-
/reset-password rodauth.reset_password_path
|
123
|
-
/verify-login-change rodauth.verify_login_change_path
|
124
|
-
/close-account rodauth.close_account_path
|
113
|
+
GET/POST /login rodauth.login_path
|
114
|
+
GET/POST /create-account rodauth.create_account_path
|
115
|
+
GET/POST /verify-account-resend rodauth.verify_account_resend_path
|
116
|
+
GET/POST /verify-account rodauth.verify_account_path
|
117
|
+
GET/POST /change-password rodauth.change_password_path
|
118
|
+
GET/POST /change-login rodauth.change_login_path
|
119
|
+
GET/POST /logout rodauth.logout_path
|
120
|
+
GET/POST /remember rodauth.remember_path
|
121
|
+
GET/POST /reset-password-request rodauth.reset_password_request_path
|
122
|
+
GET/POST /reset-password rodauth.reset_password_path
|
123
|
+
GET/POST /verify-login-change rodauth.verify_login_change_path
|
124
|
+
GET/POST /close-account rodauth.close_account_path
|
125
125
|
```
|
126
126
|
|
127
127
|
Using this information, you can add some basic authentication links to your
|
@@ -321,16 +321,26 @@ $ rails generate rodauth:views webauthn --name admin
|
|
321
321
|
|
322
322
|
#### Page titles
|
323
323
|
|
324
|
-
The generated
|
325
|
-
|
326
|
-
|
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><%=
|
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
|
@@ -356,6 +381,7 @@ class RodauthController < ApplicationController
|
|
356
381
|
when rodauth.login_path,
|
357
382
|
rodauth.create_account_path,
|
358
383
|
rodauth.verify_account_path,
|
384
|
+
rodauth.verify_account_resend_path,
|
359
385
|
rodauth.reset_password_path,
|
360
386
|
rodauth.reset_password_request_path
|
361
387
|
"authentication"
|
@@ -70,6 +70,13 @@ module Rodauth
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
def create_fixtures
|
74
|
+
test_unit_options = ::Rails.application.config.generators.options[:test_unit]
|
75
|
+
if test_unit_options[:fixture] && test_unit_options[:fixture_replacement].nil?
|
76
|
+
template "app/test/fixtures/accounts.yml"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
73
80
|
def show_instructions
|
74
81
|
readme "INSTRUCTIONS" if behavior == :invoke
|
75
82
|
end
|
@@ -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.
|
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
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
2
|
+
one:
|
3
|
+
email: freddie@queen.com
|
4
|
+
password_hash: <%%= BCrypt::Password.create("password", cost: BCrypt::Engine::MIN_COST) %>
|
5
|
+
status: 2
|
6
|
+
|
7
|
+
two:
|
8
|
+
email: brian@queen.com
|
9
|
+
password_hash: <%%= BCrypt::Password.create("password", cost: BCrypt::Engine::MIN_COST) %>
|
10
|
+
status: 2
|
@@ -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.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.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| %>
|
data/lib/rodauth/rails/app.rb
CHANGED
@@ -59,6 +59,12 @@ module Rodauth
|
|
59
59
|
rodauth(name) or fail ArgumentError, "unknown rodauth configuration: #{name.inspect}"
|
60
60
|
end
|
61
61
|
|
62
|
+
# The newrelic_rpm gem expects this when we pass the roda class as
|
63
|
+
# :controller in instrumentation payload.
|
64
|
+
def self.controller_path
|
65
|
+
name.underscore
|
66
|
+
end
|
67
|
+
|
62
68
|
module RequestMethods
|
63
69
|
def rodauth(name = nil)
|
64
70
|
prefix = scope.rodauth(name).prefix
|
@@ -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
|
@@ -6,20 +6,34 @@ namespace :rodauth do
|
|
6
6
|
|
7
7
|
app.opts[:rodauths].each do |configuration_name, auth_class|
|
8
8
|
rodauth = auth_class.allocate
|
9
|
+
only_json = rodauth.method(:only_json?).owner != Rodauth::Base && rodauth.only_json?
|
10
|
+
|
11
|
+
routes = auth_class.route_hash.map do |path, handle_method|
|
12
|
+
file_path, start_line = rodauth.method(:"_#{handle_method}").source_location
|
13
|
+
lines = File.foreach(file_path).to_a
|
14
|
+
indentation = lines[start_line - 1][/^\s+/]
|
15
|
+
verbs = []
|
16
|
+
|
17
|
+
lines[start_line..-1].each do |code|
|
18
|
+
verbs << :GET if code.include?("r.get") && !only_json
|
19
|
+
verbs << :POST if code.include?("r.post")
|
20
|
+
break if code.start_with?("#{indentation}end")
|
21
|
+
end
|
9
22
|
|
10
|
-
routes = auth_class.routes.map do |handle_method|
|
11
23
|
path_method = "#{handle_method.to_s.sub(/\Ahandle_/, "")}_path"
|
12
24
|
|
13
25
|
[
|
14
|
-
|
26
|
+
verbs.join("/"),
|
27
|
+
"#{rodauth.prefix}#{path}",
|
15
28
|
"rodauth#{configuration_name && "(:#{configuration_name})"}.#{path_method}",
|
16
29
|
]
|
17
30
|
end
|
18
31
|
|
19
|
-
|
32
|
+
verbs_padding = routes.map { |verbs, _, _| verbs.length }.max
|
33
|
+
path_padding = routes.map { |_, path, _| path.length }.max
|
20
34
|
|
21
|
-
route_lines = routes.map do |path, code|
|
22
|
-
"#{path.ljust(
|
35
|
+
route_lines = routes.map do |verbs, path, code|
|
36
|
+
"#{verbs.ljust(verbs_padding)} #{path.ljust(path_padding)} #{code}"
|
23
37
|
end
|
24
38
|
|
25
39
|
puts "\n #{route_lines.join("\n ")}" unless route_lines.empty?
|
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,
|
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)
|
data/rodauth-rails.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_dependency "railties", ">= 4.2", "< 8"
|
20
|
-
spec.add_dependency "rodauth", "~> 2.
|
20
|
+
spec.add_dependency "rodauth", "~> 2.25"
|
21
21
|
spec.add_dependency "roda", "~> 3.55"
|
22
22
|
spec.add_dependency "sequel-activerecord_connection", "~> 1.1"
|
23
23
|
spec.add_dependency "rodauth-model", "~> 0.2"
|
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
|
+
version: 1.5.2
|
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-
|
11
|
+
date: 2022-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '2.
|
39
|
+
version: '2.25'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '2.
|
46
|
+
version: '2.25'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: roda
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- lib/generators/rodauth/templates/app/misc/rodauth_app.rb
|
225
225
|
- lib/generators/rodauth/templates/app/misc/rodauth_main.rb
|
226
226
|
- lib/generators/rodauth/templates/app/models/account.rb
|
227
|
+
- lib/generators/rodauth/templates/app/test/fixtures/accounts.yml
|
227
228
|
- lib/generators/rodauth/templates/app/views/rodauth/_email_auth_request_form.html.erb
|
228
229
|
- lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb
|
229
230
|
- lib/generators/rodauth/templates/app/views/rodauth/_login_form_footer.html.erb
|