rodauth-rails 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e46466d584d7579c32e7d7e53335260dd137c04371f4b7c4680caa5c6a4e4147
4
- data.tar.gz: c0be8bdc56f5214c885fc5ad990a0be511251cab6dbf9b0ec7aa3fbd8631d0c9
3
+ metadata.gz: 1539e5f70a8cefa3c40e06b5b177152e4772f099deb11a077f07f59529622a62
4
+ data.tar.gz: 67c9a6829f8a9c45708cb1ab0781a2eebe1998d5f31f66b26d5c7f58cb37cdf8
5
5
  SHA512:
6
- metadata.gz: 8428739e888033efa811819ee8561fa3f2ae342074f6e27bbf257c18bf7029ab87380a82c75c6c08de2a0d4de49482eac74a32bc7aaf0579baf45978fe63811c
7
- data.tar.gz: d626ea202fe8e371e6c77364a9e3c1ef34fdccff0ce7794c54b3fc748b0e1a764e92b99b6b7f06aaa8e2f2f67b155b127c0b1314d4ec7420637013136170141c
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.16"
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
- If the account doesn't exist in the database, the session will be cleared and
161
- login required.
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 would
781
- like to perform Rodauth operations outside of request context, Rodauth ships
782
- with the [internal_request] feature just for that. The rodauth-rails gem
783
- additionally updates the internal rack env hash with your
784
- `config.action_mailer.default_url_options`, which is used for generating URLs.
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
- Rodauth::Rails.rodauth(
814
- env: { "HTTP_USER_AGENT" => "programmatic" },
815
- session: { two_factor_auth_setup: true },
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
- Secondary Rodauth configurations are specified by passing the configuration
822
- name:
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
- # delete_account_on_close? true
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 }
@@ -13,8 +13,7 @@ module Rodauth
13
13
  end
14
14
 
15
15
  def current_account(name = nil)
16
- table = rodauth(name).accounts_table
17
- model = table.to_s.classify.constantize
16
+ model = rodauth(name).rails_account_model
18
17
  id = rodauth(name).session_value
19
18
 
20
19
  @current_account ||= {}
@@ -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
@@ -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: :destroy,
80
+ dependent: type == :has_many ? :delete_all : :delete,
81
81
  inverse_of: :account,
82
82
  **options,
83
83
  **association_options(name)
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "0.16.0"
3
+ VERSION = "0.17.0"
4
4
  end
5
5
  end
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.16.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-09-26 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties