rodauth-rails 0.12.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +119 -33
- data/lib/generators/rodauth/templates/app/lib/rodauth_app.rb +10 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_email_auth_request_form.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_field.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/_field_error.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/_global_logout_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_confirm_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_display.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_form.html.erb +3 -3
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_footer.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_form_header.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/_login_hidden_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_new_password_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_otp_auth_code_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_password_confirm_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_password_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_code_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_recovery_codes_form.html.erb +4 -4
- data/lib/generators/rodauth/templates/app/views/rodauth/_sms_code_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/_sms_phone_field.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/add_recovery_codes.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/change_login.html.erb +3 -3
- data/lib/generators/rodauth/templates/app/views/rodauth/change_password.html.erb +3 -3
- data/lib/generators/rodauth/templates/app/views/rodauth/close_account.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/confirm_password.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/create_account.html.erb +4 -4
- data/lib/generators/rodauth/templates/app/views/rodauth/email_auth.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/logout.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/multi_phase_login.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/otp_auth.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/otp_disable.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/otp_setup.html.erb +7 -7
- data/lib/generators/rodauth/templates/app/views/rodauth/recovery_auth.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/remember.html.erb +4 -4
- data/lib/generators/rodauth/templates/app/views/rodauth/reset_password.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/reset_password_request.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_auth.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_confirm.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_disable.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_request.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/sms_setup.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_auth.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_disable.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/two_factor_manage.html.erb +6 -6
- data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/unlock_account_request.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/verify_account.html.erb +3 -3
- data/lib/generators/rodauth/templates/app/views/rodauth/verify_account_resend.html.erb +2 -2
- data/lib/generators/rodauth/templates/app/views/rodauth/verify_login_change.html.erb +1 -1
- data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_auth.html.erb +7 -7
- data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_remove.html.erb +5 -5
- data/lib/generators/rodauth/templates/app/views/rodauth/webauthn_setup.html.erb +7 -7
- data/lib/generators/rodauth/views_generator.rb +25 -4
- data/lib/rodauth/rails/auth.rb +9 -12
- data/lib/rodauth/rails/feature/base.rb +8 -8
- data/lib/rodauth/rails/feature/render.rb +7 -0
- data/lib/rodauth/rails/version.rb +1 -1
- data/lib/rodauth/rails.rb +26 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d447d09fef8c29feb6240523286b8906049e85965f20a6410d1a475f913d9051
|
4
|
+
data.tar.gz: bca9b6eadec6b32f2193291c6922467a554105d290ffd7b34bc2606d62121926
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f512f9fe9a3e22dcddf477d8906d1ea63a548241fd93b43bbcaf274ff39e0104e20f64c6a2836e5b243e812ffde654deae55a0beca69f4ba917cd5943da8a3c
|
7
|
+
data.tar.gz: dbbd99959dfd42134cd3374f1f9767cf3e8d49327c195d4c35c4ecf281d0c3dad52db76b7e2fbf030c9e3ea2131bfcb1b6a120cc4a310983d8db564e63b97cda
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 0.14.0 (2021-07-10)
|
2
|
+
|
3
|
+
* Speed up template rendering by only searching formats accepted by the request (@janko)
|
4
|
+
|
5
|
+
* Add `--name` option to `rodauth:views` generator for specifying different rodauth configuration (@janko)
|
6
|
+
|
7
|
+
* Infer correct template path from configured controller in `rodauth:views` generator (@janko)
|
8
|
+
|
9
|
+
* Raise `ArgumentError` if undefined rodauth configuration is passed to `Rodauth::Rails.app` (@janko)
|
10
|
+
|
11
|
+
* Make `#rails_controller` method on the rodauth instance public (@janko)
|
12
|
+
|
13
|
+
* Remove `--directory` option from `rodauth:views` generator (@janko)
|
14
|
+
|
15
|
+
* Remove `#features` and `#routes` writer and `#configuration` reader from `Rodauth::Rails::Auth` (@janko)
|
16
|
+
|
17
|
+
## 0.13.0 (2021-06-10)
|
18
|
+
|
19
|
+
* Add `:query`, `:form`, `:session`, `:account`, and `:env` options to `Rodauth::Rails.rodauth` (@janko)
|
20
|
+
|
1
21
|
## 0.12.0 (2021-05-15)
|
2
22
|
|
3
23
|
* Include total view render time in logs for Rodauth requests (@janko)
|
data/README.md
CHANGED
@@ -41,27 +41,15 @@ Active Record's database connection][sequel-activerecord_connection].
|
|
41
41
|
|
42
42
|
## Upgrading
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
Starting from version 0.7.0, rodauth-rails now correctly detects Rails
|
47
|
-
application's `secret_key_base` when setting default `hmac_secret`, including
|
48
|
-
when it's set via credentials or `$SECRET_KEY_BASE` environment variable. This
|
49
|
-
means that your authentication will now be more secure by default, and Rodauth
|
50
|
-
features that require `hmac_secret` should now work automatically as well.
|
51
|
-
|
52
|
-
However, if you've already been using rodauth-rails in production, where the
|
53
|
-
`secret_key_base` is set via credentials or environment variable and `hmac_secret`
|
54
|
-
was not explicitly set, the fact that your authentication will now start using
|
55
|
-
HMACs has backwards compatibility considerations. See the [Rodauth
|
56
|
-
documentation][hmac] for instructions on how to safely transition, or just set
|
57
|
-
`hmac_secret nil` in your Rodauth configuration.
|
44
|
+
For instructions on upgrading from previous rodauth-rails versions, see
|
45
|
+
[UPGRADING.md](/UPGRADING.md).
|
58
46
|
|
59
47
|
## Installation
|
60
48
|
|
61
49
|
Add the gem to your Gemfile:
|
62
50
|
|
63
51
|
```rb
|
64
|
-
gem "rodauth-rails", "~> 0.
|
52
|
+
gem "rodauth-rails", "~> 0.14"
|
65
53
|
|
66
54
|
# gem "jwt", require: false # for JWT feature
|
67
55
|
# gem "rotp", require: false # for OTP feature
|
@@ -290,8 +278,8 @@ $ rails generate rodauth:views
|
|
290
278
|
```
|
291
279
|
|
292
280
|
This will generate views for the default set of Rodauth features into the
|
293
|
-
`app/views/rodauth` directory,
|
294
|
-
|
281
|
+
`app/views/rodauth` directory, provided that `RodauthController` is set for the
|
282
|
+
main configuration.
|
295
283
|
|
296
284
|
You can pass a list of Rodauth features to the generator to create views for
|
297
285
|
these features (this will not remove or overwrite any existing views):
|
@@ -306,12 +294,10 @@ Or you can generate views for all features:
|
|
306
294
|
$ rails generate rodauth:views --all
|
307
295
|
```
|
308
296
|
|
309
|
-
|
310
|
-
case make sure to rename the Rodauth controller accordingly):
|
297
|
+
Use `--name` to generate views for a different Rodauth configuration:
|
311
298
|
|
312
299
|
```sh
|
313
|
-
|
314
|
-
$ rails generate rodauth:views --name authentication
|
300
|
+
$ rails generate rodauth:views --name admin
|
315
301
|
```
|
316
302
|
|
317
303
|
#### Layout
|
@@ -404,14 +390,48 @@ end
|
|
404
390
|
This configuration calls `#deliver_later`, which uses Active Job to deliver
|
405
391
|
emails in a background job. It's generally recommended to send emails
|
406
392
|
asynchronously for better request throughput and the ability to retry
|
407
|
-
deliveries. However, if you want to send emails synchronously, modify
|
408
|
-
configuration to call `#deliver_now` instead.
|
393
|
+
deliveries. However, if you want to send emails synchronously, you can modify
|
394
|
+
the configuration to call `#deliver_now` instead.
|
409
395
|
|
410
396
|
If you're using a background processing library without an Active Job adapter,
|
411
397
|
or a 3rd-party service for sending transactional emails, this two-phase API
|
412
398
|
might not be suitable. In this case, instead of overriding `#create_*_email`
|
413
399
|
and `#send_email`, override the `#send_*_email` methods instead, which are
|
414
|
-
required to send the email immediately.
|
400
|
+
required to send the email immediately. For example:
|
401
|
+
|
402
|
+
```rb
|
403
|
+
# app/workers/rodauth_mailer_worker.rb
|
404
|
+
class RodauthMailerWorker
|
405
|
+
include Sidekiq::Worker
|
406
|
+
|
407
|
+
def perform(name, *args)
|
408
|
+
email = RodauthMailer.public_send(name, *args)
|
409
|
+
email.deliver_now
|
410
|
+
end
|
411
|
+
end
|
412
|
+
```
|
413
|
+
```rb
|
414
|
+
# app/lib/rodauth_app.rb
|
415
|
+
class RodauthApp < Rodauth::Rails::App
|
416
|
+
configure do
|
417
|
+
# ...
|
418
|
+
# use `#send_*_email` method to be able to immediately enqueue email delivery
|
419
|
+
send_reset_password_email do
|
420
|
+
enqueue_email(:reset_password, email_to, reset_password_email_link)
|
421
|
+
end
|
422
|
+
# ...
|
423
|
+
auth_class_eval do
|
424
|
+
# custom method for enqueuing email delivery using our worker
|
425
|
+
def enqueue_email(name, *args)
|
426
|
+
db.after_commit do
|
427
|
+
RodauthMailerWorker.perform_async(name, *args)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
# ...
|
432
|
+
end
|
433
|
+
end
|
434
|
+
```
|
415
435
|
|
416
436
|
### Migrations
|
417
437
|
|
@@ -452,10 +472,6 @@ class RodauthApp < Rodauth::Rails::App
|
|
452
472
|
prefix "/admin"
|
453
473
|
session_key_prefix "admin_"
|
454
474
|
remember_cookie_key "_admin_remember" # if using remember feature
|
455
|
-
|
456
|
-
# if you want separate tables
|
457
|
-
accounts_table :admin_accounts
|
458
|
-
password_hash_table :admin_account_password_hashes
|
459
475
|
# ...
|
460
476
|
end
|
461
477
|
|
@@ -464,7 +480,7 @@ class RodauthApp < Rodauth::Rails::App
|
|
464
480
|
|
465
481
|
r.on "admin" do
|
466
482
|
r.rodauth(:admin)
|
467
|
-
|
483
|
+
break # allow routing of other /admin/* requests to continue to Rails
|
468
484
|
end
|
469
485
|
|
470
486
|
# ...
|
@@ -478,6 +494,50 @@ Then in your application you can reference the secondary Rodauth instance:
|
|
478
494
|
rodauth(:admin).login_path #=> "/admin/login"
|
479
495
|
```
|
480
496
|
|
497
|
+
You'll likely want to save the information of which account belongs to which
|
498
|
+
configuration to the database. One way would be to have a separate table that
|
499
|
+
stores account types:
|
500
|
+
|
501
|
+
```sh
|
502
|
+
$ rails generate migration create_account_types
|
503
|
+
```
|
504
|
+
```rb
|
505
|
+
# db/migrate/*_create_account_types.rb
|
506
|
+
class CreateAccountTypes < ActiveRecord::Migration
|
507
|
+
def change
|
508
|
+
create_table :account_types do |t|
|
509
|
+
t.references :account, foreign_key: { on_delete: :cascade }, null: false
|
510
|
+
t.string :type, null: false
|
511
|
+
end
|
512
|
+
end
|
513
|
+
end
|
514
|
+
```
|
515
|
+
```sh
|
516
|
+
$ rails db:migrate
|
517
|
+
```
|
518
|
+
|
519
|
+
Then an entry would be inserted after account creation, and optionally whenever
|
520
|
+
Rodauth retrieves accounts you could filter only those belonging to the current
|
521
|
+
configuration:
|
522
|
+
|
523
|
+
```rb
|
524
|
+
# app/lib/rodauth_app.rb
|
525
|
+
class RodauthApp < Rodauth::Rails::App
|
526
|
+
configure(:admin) do
|
527
|
+
# ...
|
528
|
+
after_create_account do
|
529
|
+
db[:account_types].insert(account_id: account_id, type: "admin")
|
530
|
+
end
|
531
|
+
auth_class_eval do
|
532
|
+
def account_ds(*)
|
533
|
+
super.join(:account_types, account_id: :id).where(type: "admin")
|
534
|
+
end
|
535
|
+
end
|
536
|
+
# ...
|
537
|
+
end
|
538
|
+
end
|
539
|
+
```
|
540
|
+
|
481
541
|
#### Named auth classes
|
482
542
|
|
483
543
|
A `configure` block inside `Rodauth::Rails::App` will internally create an
|
@@ -599,8 +659,8 @@ end
|
|
599
659
|
### Rodauth instance
|
600
660
|
|
601
661
|
In some cases you might need to use Rodauth more programmatically, and perform
|
602
|
-
Rodauth operations outside of the request context. rodauth-rails gives you
|
603
|
-
|
662
|
+
Rodauth operations outside of the request context. rodauth-rails gives you a
|
663
|
+
helper method for building a Rodauth instance:
|
604
664
|
|
605
665
|
```rb
|
606
666
|
rodauth = Rodauth::Rails.rodauth # or Rodauth::Rails.rodauth(:admin)
|
@@ -612,8 +672,22 @@ rodauth.setup_account_verification
|
|
612
672
|
rodauth.close_account
|
613
673
|
```
|
614
674
|
|
615
|
-
|
616
|
-
|
675
|
+
The base URL is taken from Action Mailer's `default_url_options` setting if
|
676
|
+
configured. The `Rodauth::Rails.rodauth` method accepts additional keyword
|
677
|
+
arguments:
|
678
|
+
|
679
|
+
* `:account` – Active Record model instance from which to set `account` and `session[:account_id]`
|
680
|
+
* `:query` & `:form` – set specific query/form parameters
|
681
|
+
* `:session` – set any session values
|
682
|
+
* `:env` – set any additional Rack env values
|
683
|
+
|
684
|
+
```rb
|
685
|
+
Rodauth::Rails.rodauth(account: Account.find(account_id))
|
686
|
+
Rodauth::Rails.rodauth(query: { "param" => "value" })
|
687
|
+
Rodauth::Rails.rodauth(form: { "param" => "value" })
|
688
|
+
Rodauth::Rails.rodauth(session: { two_factor_auth_setup: true })
|
689
|
+
Rodauth::Rails.rodauth(env: { "HTTP_USER_AGENT" => "programmatic" })
|
690
|
+
```
|
617
691
|
|
618
692
|
## How it works
|
619
693
|
|
@@ -1176,6 +1250,18 @@ configure do
|
|
1176
1250
|
end
|
1177
1251
|
```
|
1178
1252
|
|
1253
|
+
### Deadline values
|
1254
|
+
|
1255
|
+
To simplify changes to the database schema, rodauth-rails configures Rodauth
|
1256
|
+
to set deadline values for various features in Ruby, instead of relying on
|
1257
|
+
the database to set default column values.
|
1258
|
+
|
1259
|
+
You can easily change this back:
|
1260
|
+
|
1261
|
+
```rb
|
1262
|
+
set_deadline_values? false
|
1263
|
+
```
|
1264
|
+
|
1179
1265
|
## License
|
1180
1266
|
|
1181
1267
|
The gem is available as open source under the terms of the [MIT
|
@@ -156,9 +156,18 @@ class RodauthApp < Rodauth::Rails::App
|
|
156
156
|
|
157
157
|
# ==> Multiple configurations
|
158
158
|
# configure(:admin) do
|
159
|
-
#
|
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|
|
@@ -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
|
8
|
-
aria: ({ invalid: "true", describedby: "#{name}_error_message" } if rodauth
|
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
|
2
|
-
<div class="invalid-feedback" id="<%%= name %>_error_message"><%%= rodauth
|
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
|
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
|
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
|
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
|
3
|
+
<%%= render "field", name: <%= rodauth %>.login_param, id: "login", type: :email, autocomplete: "email" %>
|
4
4
|
</div>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<%%= form_tag rodauth
|
2
|
-
<%% if rodauth
|
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
|
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
|
1
|
+
<%% unless <%= rodauth %>.login_form_footer_links.empty? %>
|
2
2
|
<h2>Other Options</h2>
|
3
3
|
<ul>
|
4
|
-
<%% rodauth
|
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
|
2
|
-
<%%= render template: "<%=
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
2
|
-
<%%= render "password_field" if rodauth
|
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
|
5
|
-
name: (rodauth
|
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
|
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
|
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
|
1
|
+
<pre id="recovery-codes"><%%= <%= rodauth %>.recovery_codes.map { |s| h(s) }.join("\n\n") %></pre>
|
2
2
|
|
3
|
-
<%% if rodauth
|
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
|
1
|
+
<%%= form_tag <%= rodauth %>.change_login_path, method: :post do %>
|
2
2
|
<%%= render "login_field" %>
|
3
|
-
<%%= render "login_confirm_field" if rodauth
|
4
|
-
<%%= render "password_field" if rodauth
|
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
|
2
|
-
<%%= render "password_field" if rodauth
|
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
|
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
|
2
|
-
<%%= render "password_field" if rodauth
|
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,7 +1,7 @@
|
|
1
|
-
<%%= form_tag rodauth
|
1
|
+
<%%= form_tag <%= rodauth %>.create_account_path, method: :post do %>
|
2
2
|
<%%= render "login_field" %>
|
3
|
-
<%%= render "login_confirm_field" if rodauth
|
4
|
-
<%%= render "password_field" if rodauth
|
5
|
-
<%%= render "password_confirm_field" if rodauth
|
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,4 +1,4 @@
|
|
1
|
-
<%%= form_tag rodauth
|
2
|
-
<%%= render "global_logout_field" if rodauth
|
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,4 +1,4 @@
|
|
1
|
-
<%%= form_tag rodauth
|
2
|
-
<%%= render "password_field" if rodauth
|
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
|
2
|
-
<%%= hidden_field_tag rodauth
|
3
|
-
<%%= hidden_field_tag rodauth
|
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
|
7
|
-
<p>Provisioning URL: <%%= rodauth
|
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
|
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
|
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,17 +1,17 @@
|
|
1
|
-
<%%= form_tag rodauth
|
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
|
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
|
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
|
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
|
1
|
+
<%%= form_tag <%= rodauth %>.reset_password_path, method: :post do %>
|
2
2
|
<%%= render "password_field" %>
|
3
|
-
<%%= render "password_confirm_field" if rodauth
|
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
|
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
|
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
|
2
|
-
<%%= render "password_field" if rodauth
|
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,5 +1,5 @@
|
|
1
|
-
<%%= form_tag rodauth
|
2
|
-
<%%= render "password_field" if rodauth
|
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,4 +1,4 @@
|
|
1
|
-
<%%= form_tag rodauth
|
2
|
-
<%%= render "password_field" if rodauth
|
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
|
1
|
+
<%% if <%= rodauth %>.two_factor_setup_links.any? %>
|
2
2
|
<h2>Setup Multifactor Authentication</h2>
|
3
3
|
|
4
4
|
<ul>
|
5
|
-
<%% rodauth
|
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
|
11
|
+
<%% if <%= rodauth %>.two_factor_remove_links.any? %>
|
12
12
|
<h2>Remove Multifactor Authentication</h2>
|
13
13
|
|
14
14
|
<ul>
|
15
|
-
<%% rodauth
|
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
|
19
|
-
<li><%%= link_to "Remove All Multifactor Authentication Methods", rodauth
|
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
|
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
|
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
|
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
|
2
|
-
<%%= render "password_field" if rodauth
|
3
|
-
<%%= render "password_confirm_field" if rodauth
|
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
|
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
|
3
|
+
<%% if params[<%= rodauth %>.login_param] %>
|
4
4
|
<%%= render "login_hidden_field" %>
|
5
5
|
<%% else %>
|
6
6
|
<%%= render "login_field" %>
|
@@ -1,13 +1,13 @@
|
|
1
|
-
<%% cred = rodauth
|
1
|
+
<%% cred = <%= rodauth %>.webauth_credential_options_for_get %>
|
2
2
|
|
3
|
-
<%%= form_tag rodauth
|
4
|
-
<%%= render "login_hidden_field" if params[rodauth
|
5
|
-
<%%= hidden_field_tag rodauth
|
6
|
-
<%%= hidden_field_tag rodauth
|
7
|
-
<%%= text_field_tag rodauth
|
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
|
13
|
+
<%%= javascript_include_tag <%= rodauth %>.webauthn_auth_js_path %>
|
@@ -1,11 +1,11 @@
|
|
1
|
-
<%%= form_tag rodauth
|
2
|
-
<%%= render "password_field" if rodauth
|
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
|
4
|
+
<%% (usage = <%= rodauth %>.account_webauthn_usage).each do |id, last_use| %>
|
5
5
|
<div class="form-check">
|
6
|
-
<%%= render "field", name: rodauth
|
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
|
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
|
1
|
+
<%% cred = <%= rodauth %>.new_webauthn_credential %>
|
2
2
|
|
3
|
-
<%%= form_tag rodauth
|
4
|
-
<%%= hidden_field_tag rodauth
|
5
|
-
<%%= hidden_field_tag rodauth
|
6
|
-
<%%= text_field_tag rodauth
|
7
|
-
<%%= render "password_field" if rodauth
|
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
|
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 :
|
22
|
-
desc: "The
|
23
|
-
default:
|
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/#{
|
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/auth.rb
CHANGED
@@ -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
|
-
|
18
|
-
auth_class.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
data/lib/rodauth/rails.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require "rodauth/rails/version"
|
2
2
|
require "rodauth/rails/railtie"
|
3
3
|
|
4
|
+
require "rack/utils"
|
5
|
+
require "stringio"
|
6
|
+
|
4
7
|
module Rodauth
|
5
8
|
module Rails
|
6
9
|
class Error < StandardError
|
@@ -14,7 +17,11 @@ module Rodauth
|
|
14
17
|
@middleware = true
|
15
18
|
|
16
19
|
class << self
|
17
|
-
def rodauth(name = nil)
|
20
|
+
def rodauth(name = nil, query: {}, form: {}, session: {}, account: nil, env: {})
|
21
|
+
unless app.rodauth(name)
|
22
|
+
fail ArgumentError, "undefined rodauth configuration: #{name.inspect}"
|
23
|
+
end
|
24
|
+
|
18
25
|
url_options = ActionMailer::Base.default_url_options
|
19
26
|
|
20
27
|
scheme = url_options[:protocol] || "http"
|
@@ -23,14 +30,29 @@ module Rodauth
|
|
23
30
|
host = url_options[:host]
|
24
31
|
host += ":#{port}" if port
|
25
32
|
|
33
|
+
content_type = "application/x-www-form-urlencoded" if form.any?
|
34
|
+
|
26
35
|
rack_env = {
|
36
|
+
"QUERY_STRING" => Rack::Utils.build_nested_query(query),
|
37
|
+
"rack.input" => StringIO.new(Rack::Utils.build_nested_query(form)),
|
38
|
+
"CONTENT_TYPE" => content_type,
|
39
|
+
"rack.session" => {},
|
27
40
|
"HTTP_HOST" => host,
|
28
41
|
"rack.url_scheme" => scheme,
|
29
|
-
}
|
42
|
+
}.merge(env)
|
30
43
|
|
31
|
-
scope
|
44
|
+
scope = app.new(rack_env)
|
45
|
+
instance = scope.rodauth(name)
|
46
|
+
|
47
|
+
# update session hash here to make it work with JWT session
|
48
|
+
instance.session.merge!(session)
|
49
|
+
|
50
|
+
if account
|
51
|
+
instance.instance_variable_set(:@account, account.attributes.symbolize_keys)
|
52
|
+
instance.session[instance.session_key] = instance.account_session_value
|
53
|
+
end
|
32
54
|
|
33
|
-
|
55
|
+
instance
|
34
56
|
end
|
35
57
|
|
36
58
|
# routing constraint that requires authentication
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rodauth-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
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-
|
11
|
+
date: 2021-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -237,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
- !ruby/object:Gem::Version
|
238
238
|
version: '0'
|
239
239
|
requirements: []
|
240
|
-
rubygems_version: 3.2.
|
240
|
+
rubygems_version: 3.2.15
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: Provides Rails integration for Rodauth.
|