rodauth-rails 0.16.0 → 0.17.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +71 -20
- data/lib/generators/rodauth/templates/app/lib/rodauth_app.rb +1 -1
- data/lib/rodauth/rails/controller_methods.rb +1 -2
- data/lib/rodauth/rails/feature/base.rb +9 -0
- data/lib/rodauth/rails/model.rb +1 -1
- data/lib/rodauth/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1539e5f70a8cefa3c40e06b5b177152e4772f099deb11a077f07f59529622a62
|
4
|
+
data.tar.gz: 67c9a6829f8a9c45708cb1ab0781a2eebe1998d5f31f66b26d5c7f58cb37cdf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf1f132504de2266dc4ef7f71ffdd630e348119f6681f84288aeb6ba24481336948c78183d4fa7e90100dedc85e04c4bb98f915de3ecf156630d523d91d74c00
|
7
|
+
data.tar.gz: e1858507c3ee9a2855e04fa67957859f41347adbf448793b8cebe263a0bd95517ef913b4132470a31609be9741ff73e4769309df5924f19b0db0503a1a25fa2a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.17.0 (2021-10-05)
|
2
|
+
|
3
|
+
* Set `delete_account_on_close?` to `true` in generated `rodauth_app.rb` (@janko)
|
4
|
+
|
5
|
+
* Change default `:dependent` option for associations to `:delete`/`:delete_all` (@janko)
|
6
|
+
|
7
|
+
* Add `rails_account_model` configuration method for when the account model cannot be inferred (@janko)
|
8
|
+
|
1
9
|
## 0.16.0 (2021-09-26)
|
2
10
|
|
3
11
|
* Add `#current_account` to methods defined on `ActionController::Base` (@janko)
|
data/README.md
CHANGED
@@ -49,7 +49,7 @@ For instructions on upgrading from previous rodauth-rails versions, see
|
|
49
49
|
Add the gem to your Gemfile:
|
50
50
|
|
51
51
|
```rb
|
52
|
-
gem "rodauth-rails", "~> 0.
|
52
|
+
gem "rodauth-rails", "~> 0.17"
|
53
53
|
|
54
54
|
# gem "jwt", require: false # for JWT feature
|
55
55
|
# gem "rotp", require: false # for OTP feature
|
@@ -150,6 +150,9 @@ current_account #=> #<Account id=123 email="user@example.com">
|
|
150
150
|
current_account.email #=> "user@example.com"
|
151
151
|
```
|
152
152
|
|
153
|
+
If the account doesn't exist in the database, the session will be cleared and
|
154
|
+
login required.
|
155
|
+
|
153
156
|
Pass the configuration name to retrieve accounts belonging to other Rodauth
|
154
157
|
configurations:
|
155
158
|
|
@@ -157,8 +160,19 @@ configurations:
|
|
157
160
|
current_account(:admin)
|
158
161
|
```
|
159
162
|
|
160
|
-
|
161
|
-
|
163
|
+
The `#current_account` method will try to infer the account model class from
|
164
|
+
the configured table name. If that fails, you can set the account model
|
165
|
+
manually:
|
166
|
+
|
167
|
+
```rb
|
168
|
+
# app/lib/rodauth_app.rb
|
169
|
+
class RodauthApp < Rodauth::Rails::App
|
170
|
+
configure do
|
171
|
+
# ...
|
172
|
+
rails_account_model Authentication::Account # custom model name
|
173
|
+
end
|
174
|
+
end
|
175
|
+
```
|
162
176
|
|
163
177
|
### Requiring authentication
|
164
178
|
|
@@ -777,11 +791,52 @@ end
|
|
777
791
|
|
778
792
|
### Outside of a request
|
779
793
|
|
780
|
-
In some cases you might need to use Rodauth more programmatically. If you
|
781
|
-
|
782
|
-
with the [internal_request] feature just for that.
|
783
|
-
|
784
|
-
|
794
|
+
In some cases you might need to use Rodauth more programmatically. If you want
|
795
|
+
to perform authentication operations outside of request context, Rodauth ships
|
796
|
+
with the [internal_request] feature just for that.
|
797
|
+
|
798
|
+
```rb
|
799
|
+
# app/lib/rodauth_app.rb
|
800
|
+
class RodauthApp < Rodauth::Rails::App
|
801
|
+
configure do
|
802
|
+
enable :internal_request
|
803
|
+
end
|
804
|
+
end
|
805
|
+
```
|
806
|
+
```rb
|
807
|
+
# main configuration
|
808
|
+
RodauthApp.rodauth.create_account(login: "user@example.com", password: "secret")
|
809
|
+
RodauthApp.rodauth.verify_account(account_login: "user@example.com")
|
810
|
+
|
811
|
+
# secondary configuration
|
812
|
+
RodauthApp.rodauth(:admin).close_account(account_login: "admin@example.com")
|
813
|
+
```
|
814
|
+
|
815
|
+
The rodauth-rails gem additionally updates the internal rack env hash with your
|
816
|
+
`config.action_mailer.default_url_options`, which is used for generating email
|
817
|
+
links.
|
818
|
+
|
819
|
+
For generating authentication URLs outside of a request use the
|
820
|
+
[path_class_methods] plugin:
|
821
|
+
|
822
|
+
```rb
|
823
|
+
# app/lib/rodauth_app.rb
|
824
|
+
class RodauthApp < Rodauth::Rails::App
|
825
|
+
configure do
|
826
|
+
enable :path_class_methods
|
827
|
+
end
|
828
|
+
end
|
829
|
+
```
|
830
|
+
```rb
|
831
|
+
# main configuration
|
832
|
+
RodauthApp.rodauth.create_account_path
|
833
|
+
RodauthApp.rodauth.verify_account_url(key: "abc123")
|
834
|
+
|
835
|
+
# secondary configuration
|
836
|
+
RodauthApp.rodauth(:admin).close_account_path
|
837
|
+
```
|
838
|
+
|
839
|
+
#### Calling instance methods
|
785
840
|
|
786
841
|
If you need to access Rodauth methods not exposed as internal requests, you can
|
787
842
|
use `Rodauth::Rails.rodauth` to retrieve the Rodauth instance used by the
|
@@ -810,19 +865,12 @@ In addition to the `:account` option, the `Rodauth::Rails.rodauth`
|
|
810
865
|
method accepts any options supported by the internal_request feature.
|
811
866
|
|
812
867
|
```rb
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
params: { "param" => "value" },
|
817
|
-
# ...
|
818
|
-
)
|
819
|
-
```
|
868
|
+
# main configuration
|
869
|
+
Rodauth::Rails.rodauth(env: { "HTTP_USER_AGENT" => "programmatic" })
|
870
|
+
Rodauth::Rails.rodauth(session: { two_factor_auth_setup: true })
|
820
871
|
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
```rb
|
825
|
-
Rodauth::Rails.rodauth(:admin)
|
872
|
+
# secondary configuration
|
873
|
+
Rodauth::Rails.rodauth(:admin, params: { "param" => "value" })
|
826
874
|
```
|
827
875
|
|
828
876
|
## How it works
|
@@ -1107,6 +1155,7 @@ methods:
|
|
1107
1155
|
| `rails_check_csrf!` | Verifies the authenticity token for the current request. |
|
1108
1156
|
| `rails_controller_instance` | Instance of the controller with the request env context. |
|
1109
1157
|
| `rails_controller` | Controller class to use for rendering and CSRF protection. |
|
1158
|
+
| `rails_account_model` | Model class connected with the accounts table. |
|
1110
1159
|
|
1111
1160
|
The `Rodauth::Rails` module has a few config settings available as well:
|
1112
1161
|
|
@@ -1423,3 +1472,5 @@ conduct](https://github.com/janko/rodauth-rails/blob/master/CODE_OF_CONDUCT.md).
|
|
1423
1472
|
[account_expiration]: http://rodauth.jeremyevans.net/rdoc/files/doc/account_expiration_rdoc.html
|
1424
1473
|
[simple_ldap_authenticator]: https://github.com/jeremyevans/simple_ldap_authenticator
|
1425
1474
|
[internal_request]: http://rodauth.jeremyevans.net/rdoc/files/doc/internal_request_rdoc.html
|
1475
|
+
[composite_primary_keys]: https://github.com/composite-primary-keys/composite_primary_keys
|
1476
|
+
[path_class_methods]: https://rodauth.jeremyevans.net/rdoc/files/doc/path_class_methods_rdoc.html
|
@@ -52,7 +52,7 @@ class RodauthApp < Rodauth::Rails::App
|
|
52
52
|
# reset_password_autologin? true
|
53
53
|
|
54
54
|
# Delete the account record when the user has closed their account.
|
55
|
-
|
55
|
+
delete_account_on_close? true
|
56
56
|
|
57
57
|
# Redirect to the app from login and registration pages if already logged in.
|
58
58
|
# already_logged_in { redirect login_redirect }
|
@@ -4,6 +4,7 @@ module Rodauth
|
|
4
4
|
module Base
|
5
5
|
def self.included(feature)
|
6
6
|
feature.auth_methods :rails_controller
|
7
|
+
feature.auth_value_methods :rails_account_model
|
7
8
|
feature.auth_cached_method :rails_controller_instance
|
8
9
|
end
|
9
10
|
|
@@ -30,6 +31,14 @@ module Rodauth
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
def rails_account_model
|
35
|
+
table = accounts_table
|
36
|
+
table = table.column if table.is_a?(Sequel::SQL::QualifiedIdentifier) # schema is specified
|
37
|
+
table.to_s.classify.constantize
|
38
|
+
rescue NameError
|
39
|
+
raise Error, "cannot infer account model, please set `rails_account_model` in your rodauth configuration"
|
40
|
+
end
|
41
|
+
|
33
42
|
delegate :rails_routes, :rails_request, to: :scope
|
34
43
|
|
35
44
|
private
|
data/lib/rodauth/rails/model.rb
CHANGED
@@ -77,7 +77,7 @@ module Rodauth
|
|
77
77
|
model.public_send type, name, scope,
|
78
78
|
class_name: associated_model.name,
|
79
79
|
foreign_key: foreign_key,
|
80
|
-
dependent: :
|
80
|
+
dependent: type == :has_many ? :delete_all : :delete,
|
81
81
|
inverse_of: :account,
|
82
82
|
**options,
|
83
83
|
**association_options(name)
|
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.17.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-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|