rodauth-model 0.2.1 → 0.4.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 +10 -0
- data/README.md +25 -13
- data/lib/rodauth/model/active_record.rb +9 -1
- data/lib/rodauth/model/associations.rb +3 -0
- data/lib/rodauth/model/sequel.rb +9 -1
- data/rodauth-model.gemspec +4 -4
- metadata +10 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea9e15f1d5a320dba7b2e4cb959b9c8c4358146ac04a09c1bfb2e719a0fb826
|
4
|
+
data.tar.gz: 5765f24048e014d3cefd3b46bd82d08cdcc98ff0c2d362865fa2e6f17597b3f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cfe79f030285164d1f3fc36fb1be09a3ca067b282b633870af1a17b341fc9be836d1a93d983dbf211f8e78d9416cc0fd808465470b5256e8e4f9a1b31ed03e0
|
7
|
+
data.tar.gz: e6ce5e3c754233554c95609405e512ebcf53ce3a608701bc93ebadd63b9aca994404a25feda89669cf20082d9215710d4d6dcf8d958cff4faa82b4227ff00082
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 0.4.0 (2024-12-16)
|
2
|
+
|
3
|
+
* Add `password?` model method that returns whether a password is set (@janko)
|
4
|
+
|
5
|
+
* Drop support for Ruby 2.3 and 2.4 (@janko)
|
6
|
+
|
7
|
+
## 0.3.0 (2024-10-12)
|
8
|
+
|
9
|
+
* Add support for OTP Unlock feature (@janko)
|
10
|
+
|
1
11
|
## 0.2.1 (2022-10-26)
|
2
12
|
|
3
13
|
* Fix `elsif` warning in sequel code (@janko)
|
data/README.md
CHANGED
@@ -27,14 +27,6 @@ class Account < ActiveRecord::Base # Sequel::Model
|
|
27
27
|
end
|
28
28
|
```
|
29
29
|
|
30
|
-
If you have multiple Rodauth configurations, pass the one for which you want associations to be defined.
|
31
|
-
|
32
|
-
```rb
|
33
|
-
class Account < ActiveRecord::Base # Sequel::Model
|
34
|
-
include Rodauth::Model(RodauthApp.rodauth(:admin))
|
35
|
-
end
|
36
|
-
```
|
37
|
-
|
38
30
|
### Password attribute
|
39
31
|
|
40
32
|
Regardless of whether you're storing the password hash in a column in the accounts table, or in a separate table, the `#password` attribute can be used to set or clear the password hash.
|
@@ -49,8 +41,12 @@ account.password_hash #=> "$2a$12$k/Ub1I2iomi84RacqY89Hu4.M0vK7klRnRtzorDyvOkVI.
|
|
49
41
|
account.password_hash #=> #<Account::PasswordHash...> (record from `account_password_hashes` table)
|
50
42
|
account.password_hash.password_hash #=> "$2a$12$k/Ub1..." (inaccessible when using database authentication functions)
|
51
43
|
|
44
|
+
# whether a password is set
|
45
|
+
account.password? #=> true
|
46
|
+
|
52
47
|
account.password = nil # clears password hash
|
53
48
|
account.password_hash #=> nil
|
49
|
+
account.password? #=> false
|
54
50
|
```
|
55
51
|
|
56
52
|
Note that the password attribute doesn't come with validations, making it unsuitable for forms. It was primarily intended to allow easily creating accounts in development console and in tests.
|
@@ -91,6 +87,20 @@ Rodauth::Model(RodauthApp.rodauth, association_options: -> (name) {
|
|
91
87
|
})
|
92
88
|
```
|
93
89
|
|
90
|
+
### Extending models
|
91
|
+
|
92
|
+
When using Zeitwerk autoloading, extending an associated model in a separate file won't work, because Zeitwerk has no reason to load it, since the constant was already defined. You can work around this by extending the model in the parent file:
|
93
|
+
|
94
|
+
```rb
|
95
|
+
class Account < ActiveRecord::Base
|
96
|
+
include Rodauth::Model(RodauthApp.rodauth) # defines associated models
|
97
|
+
|
98
|
+
class ActiveSessionKey < ActiveRecord::Base
|
99
|
+
# extend the model
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
94
104
|
## Association reference
|
95
105
|
|
96
106
|
Below is a list of all associations defined depending on the features loaded:
|
@@ -106,6 +116,7 @@ Below is a list of all associations defined depending on the features loaded:
|
|
106
116
|
| lockout | `:lockout` | `has_one` | `Lockout` | `account_lockouts` |
|
107
117
|
| lockout | `:login_failure` | `has_one` | `LoginFailure` | `account_login_failures` |
|
108
118
|
| otp | `:otp_key` | `has_one` | `OtpKey` | `account_otp_keys` |
|
119
|
+
| otp_unlock | `:otp_unlock` | `has_one` | `OtpUnlock` | `account_otp_unlocks` |
|
109
120
|
| password_expiration | `:password_change_time` | `has_one` | `PasswordChangeTime` | `account_password_change_times` |
|
110
121
|
| recovery_codes | `:recovery_codes` | `has_many` | `RecoveryCode` | `account_recovery_codes` |
|
111
122
|
| remember | `:remember_key` | `has_one` | `RememberKey` | `account_remember_keys` |
|
@@ -117,7 +128,8 @@ Below is a list of all associations defined depending on the features loaded:
|
|
117
128
|
| webauthn | `:webauthn_keys` | `has_many` | `WebauthnKey` | `account_webauthn_keys` |
|
118
129
|
| webauthn | `:webauthn_user_id` | `has_one` | `WebauthnUserId` | `account_webauthn_user_ids` |
|
119
130
|
|
120
|
-
|
131
|
+
> [!NOTE]
|
132
|
+
> Some Rodauth tables use composite primary keys, which are supported in Active Record 7.1+. If you're on an older version of Active Record, you might need to add the [composite_primary_keys] gem to your Gemfile. Sequel has always natively supported composite primary keys.
|
121
133
|
|
122
134
|
## Extending associations
|
123
135
|
|
@@ -131,11 +143,11 @@ module Rodauth
|
|
131
143
|
auth_value_method :foo_id_column, :id
|
132
144
|
# ...
|
133
145
|
end
|
146
|
+
end
|
134
147
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
148
|
+
if defined?(Rodauth::Model)
|
149
|
+
Rodauth::Model.register_association(:foo) do
|
150
|
+
{ name: :foo, type: :one, table: foo_table, key: foo_id_column }
|
139
151
|
end
|
140
152
|
end
|
141
153
|
```
|
@@ -16,7 +16,7 @@ module Rodauth
|
|
16
16
|
|
17
17
|
define_method(:password=) do |password|
|
18
18
|
@password = password
|
19
|
-
password_hash = rodauth.
|
19
|
+
password_hash = rodauth.password_hash(password) if password
|
20
20
|
set_password_hash(password_hash)
|
21
21
|
end
|
22
22
|
|
@@ -32,6 +32,14 @@ module Rodauth
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
define_method(:password?) do
|
37
|
+
if rodauth.account_password_hash_column
|
38
|
+
!!public_send(rodauth.account_password_hash_column)
|
39
|
+
else
|
40
|
+
!!password_hash
|
41
|
+
end
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
45
|
def define_associations(model)
|
@@ -46,6 +46,9 @@ module Rodauth
|
|
46
46
|
Model.register_association(:otp) do
|
47
47
|
{ name: :otp_key, type: :one, table: otp_keys_table, key: otp_keys_id_column }
|
48
48
|
end
|
49
|
+
Model.register_association(:otp_unlock) do
|
50
|
+
{ name: :otp_unlock, type: :one, table: otp_unlock_table, key: otp_unlock_id_column }
|
51
|
+
end
|
49
52
|
Model.register_association(:sms_codes) do
|
50
53
|
{ name: :sms_code, type: :one, table: sms_codes_table, key: sms_id_column }
|
51
54
|
end
|
data/lib/rodauth/model/sequel.rb
CHANGED
@@ -23,7 +23,7 @@ module Rodauth
|
|
23
23
|
|
24
24
|
define_method(:password=) do |password|
|
25
25
|
@password = password
|
26
|
-
password_hash = rodauth.
|
26
|
+
password_hash = rodauth.password_hash(password) if password
|
27
27
|
set_password_hash(password_hash)
|
28
28
|
end
|
29
29
|
|
@@ -42,6 +42,14 @@ module Rodauth
|
|
42
42
|
self.password_hash_attributes = attributes
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
define_method(:password?) do
|
47
|
+
if rodauth.account_password_hash_column
|
48
|
+
!!public_send(rodauth.account_password_hash_column)
|
49
|
+
else
|
50
|
+
!!password_hash
|
51
|
+
end
|
52
|
+
end
|
45
53
|
end
|
46
54
|
|
47
55
|
def define_associations(model)
|
data/rodauth-model.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "rodauth-model"
|
5
|
-
spec.version = "0.
|
5
|
+
spec.version = "0.4.0"
|
6
6
|
spec.authors = ["Janko Marohnić"]
|
7
7
|
spec.email = ["janko@hey.com"]
|
8
8
|
|
@@ -10,19 +10,19 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.summary = spec.description
|
11
11
|
spec.homepage = "https://github.com/janko/rodauth-model"
|
12
12
|
spec.license = "MIT"
|
13
|
-
spec.required_ruby_version = ">= 2.
|
13
|
+
spec.required_ruby_version = ">= 2.5"
|
14
14
|
|
15
15
|
spec.metadata["source_code_uri"] = "https://github.com/janko/rodauth-model"
|
16
16
|
|
17
17
|
spec.files = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "lib/**/*", "*.gemspec"]
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "rodauth", "~> 2.
|
20
|
+
spec.add_dependency "rodauth", "~> 2.28"
|
21
21
|
|
22
22
|
spec.add_development_dependency "minitest"
|
23
23
|
spec.add_development_dependency "minitest-hooks"
|
24
24
|
spec.add_development_dependency "bcrypt"
|
25
|
-
spec.add_development_dependency "jwt"
|
25
|
+
spec.add_development_dependency "jwt", "< 2.10"
|
26
26
|
spec.add_development_dependency "rotp"
|
27
27
|
spec.add_development_dependency "rqrcode"
|
28
28
|
spec.add_development_dependency "webauthn" unless RUBY_ENGINE == "jruby"
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rodauth-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2024-12-26 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rodauth
|
@@ -16,14 +15,14 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
18
|
+
version: '2.28'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
25
|
+
version: '2.28'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: minitest
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,16 +69,16 @@ dependencies:
|
|
70
69
|
name: jwt
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
72
71
|
requirements:
|
73
|
-
- - "
|
72
|
+
- - "<"
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
74
|
+
version: '2.10'
|
76
75
|
type: :development
|
77
76
|
prerelease: false
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
79
78
|
requirements:
|
80
|
-
- - "
|
79
|
+
- - "<"
|
81
80
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
81
|
+
version: '2.10'
|
83
82
|
- !ruby/object:Gem::Dependency
|
84
83
|
name: rotp
|
85
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,7 +143,6 @@ licenses:
|
|
144
143
|
- MIT
|
145
144
|
metadata:
|
146
145
|
source_code_uri: https://github.com/janko/rodauth-model
|
147
|
-
post_install_message:
|
148
146
|
rdoc_options: []
|
149
147
|
require_paths:
|
150
148
|
- lib
|
@@ -152,15 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
150
|
requirements:
|
153
151
|
- - ">="
|
154
152
|
- !ruby/object:Gem::Version
|
155
|
-
version: '2.
|
153
|
+
version: '2.5'
|
156
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
155
|
requirements:
|
158
156
|
- - ">="
|
159
157
|
- !ruby/object:Gem::Version
|
160
158
|
version: '0'
|
161
159
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
163
|
-
signing_key:
|
160
|
+
rubygems_version: 3.6.2
|
164
161
|
specification_version: 4
|
165
162
|
summary: Provides model mixin for Active Record and Sequel that defines password attribute
|
166
163
|
and associations based on Rodauth configuration.
|