veri 0.2.2 → 0.3.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02bcadafc5e2561e169ce65e920a7009f7549a0dfc1b5199cd471c01a8deac6f
|
4
|
+
data.tar.gz: 9e8b74e83ea6882c5289f6109c9b4f2e8c492874f4ff9794315be7602410ea4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7dedc00870041d1271c9c680226533030672546666bfac8a4fc0f5c7d26b4ff0eacd138b9edcb4418e017fd09e642e011b1dd06bb68ec69e2e3a4b96fc9805d
|
7
|
+
data.tar.gz: 492b0c906f34d2f091030c1d3425d21fbc5442c18080107deafe1397079f8b060609be0fd224324987ff502f1f55dcf0a9be08434f387dca2579e148ce478966
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,10 +8,11 @@ Veri is a cookie-based authentication library for Ruby on Rails that provides es
|
|
8
8
|
**Key Features:**
|
9
9
|
|
10
10
|
- Cookie-based authentication with database-stored sessions
|
11
|
-
-
|
11
|
+
- Multiple password hashing algorithms (argon2, bcrypt, scrypt)
|
12
12
|
- Granular session management and control
|
13
|
-
-
|
13
|
+
- Return path handling
|
14
14
|
- User impersonation feature
|
15
|
+
- Account lockout functionality
|
15
16
|
|
16
17
|
> ⚠️ **Development Notice**<br>
|
17
18
|
> Veri is functional but in early development. Breaking changes may occur in minor releases until v1.0!
|
@@ -24,11 +25,12 @@ Veri is a cookie-based authentication library for Ruby on Rails that provides es
|
|
24
25
|
- [Password Management](#password-management)
|
25
26
|
- [Controller Integration](#controller-integration)
|
26
27
|
- [Authentication Sessions](#authentication-sessions)
|
28
|
+
- [Account Lockout](#account-lockout)
|
27
29
|
- [View Helpers](#view-helpers)
|
28
30
|
- [Testing](#testing)
|
29
31
|
|
30
32
|
**Community Resources:**
|
31
|
-
- [Contributing](#contributing)
|
33
|
+
- [Getting Help and Contributing](#getting-help-and-contributing)
|
32
34
|
- [License](#license)
|
33
35
|
- [Code of Conduct](#code-of-conduct)
|
34
36
|
|
@@ -108,7 +110,7 @@ end
|
|
108
110
|
|
109
111
|
### Authentication Methods
|
110
112
|
|
111
|
-
This is a simplified example of how to use Veri's authentication methods
|
113
|
+
This is a simplified example of how to use Veri's authentication methods:
|
112
114
|
|
113
115
|
```rb
|
114
116
|
class SessionsController < ApplicationController
|
@@ -137,7 +139,7 @@ Available methods:
|
|
137
139
|
|
138
140
|
- `current_user` - Returns authenticated user or `nil`
|
139
141
|
- `logged_in?` - Returns `true` if user is authenticated
|
140
|
-
- `log_in(user)` - Authenticates user and creates session
|
142
|
+
- `log_in(user)` - Authenticates user and creates session, returns `true` on success or `false` if account is locked
|
141
143
|
- `log_out` - Terminates current session
|
142
144
|
- `return_path` - Returns path user was accessing before authentication
|
143
145
|
- `current_session` - Returns current authentication session
|
@@ -249,6 +251,23 @@ Veri::Session.prune # All sessions
|
|
249
251
|
Veri::Session.prune(user) # Specific user's sessions
|
250
252
|
```
|
251
253
|
|
254
|
+
## Account Lockout
|
255
|
+
|
256
|
+
Veri provides account lockout functionality to temporarily disable user accounts (for example, after too many failed login attempts or for security reasons).
|
257
|
+
|
258
|
+
```rb
|
259
|
+
# Lock a user account
|
260
|
+
user.lock!
|
261
|
+
|
262
|
+
# Unlock a user account
|
263
|
+
user.unlock!
|
264
|
+
|
265
|
+
# Check if account is locked
|
266
|
+
user.locked?
|
267
|
+
```
|
268
|
+
|
269
|
+
When an account is locked, users cannot log in. If they're already logged in, their sessions will be terminated and they'll be treated as unauthenticated users.
|
270
|
+
|
252
271
|
## View Helpers
|
253
272
|
|
254
273
|
Access authentication state in your views:
|
@@ -310,7 +329,7 @@ RSpec.configure do |config|
|
|
310
329
|
end
|
311
330
|
```
|
312
331
|
|
313
|
-
## Contributing
|
332
|
+
## Getting Help and Contributing
|
314
333
|
|
315
334
|
### Getting Help
|
316
335
|
Have a question or need assistance? Open a discussion in our [discussions section](https://github.com/brownboxdev/veri/discussions) for:
|
@@ -330,7 +349,7 @@ Ready to contribute? You can:
|
|
330
349
|
- Improve documentation
|
331
350
|
- Add new features (please discuss first in our [discussions section](https://github.com/brownboxdev/veri/discussions))
|
332
351
|
|
333
|
-
Before contributing, please read the [contributing guidelines](https://github.com/brownboxdev/veri/blob/
|
352
|
+
Before contributing, please read the [contributing guidelines](https://github.com/brownboxdev/veri/blob/main/CONTRIBUTING.md)
|
334
353
|
|
335
354
|
## License
|
336
355
|
|
@@ -2,6 +2,8 @@ class AddVeriAuthentication < ActiveRecord::Migration[<%= ActiveRecord::Migratio
|
|
2
2
|
def change
|
3
3
|
add_column <%= table_name.to_sym.inspect %>, :hashed_password, :text
|
4
4
|
add_column <%= table_name.to_sym.inspect %>, :password_updated_at, :datetime
|
5
|
+
add_column <%= table_name.to_sym.inspect %>, :locked, :boolean, default: false, null: false
|
6
|
+
add_column <%= table_name.to_sym.inspect %>, :locked_at, :datetime
|
5
7
|
|
6
8
|
create_table :veri_sessions<%= ", id: :uuid" if options[:uuid] %> do |t|
|
7
9
|
t.string :hashed_token, null: false, index: { unique: true }
|
@@ -39,8 +39,12 @@ module Veri
|
|
39
39
|
as: :authenticatable,
|
40
40
|
message: "Expected an instance of #{Veri::Configuration.user_model_name}, got `#{authenticatable.inspect}`"
|
41
41
|
)
|
42
|
+
|
43
|
+
return false if processed_authenticatable.locked?
|
44
|
+
|
42
45
|
token = Veri::Session.establish(processed_authenticatable, request)
|
43
46
|
cookies.encrypted.permanent[:veri_token] = { value: token, httponly: true }
|
47
|
+
true
|
44
48
|
end
|
45
49
|
|
46
50
|
def log_out
|
@@ -63,9 +67,18 @@ module Veri
|
|
63
67
|
private
|
64
68
|
|
65
69
|
def with_authentication
|
66
|
-
|
70
|
+
if logged_in? && current_session.active?
|
71
|
+
if current_user.locked?
|
72
|
+
log_out
|
73
|
+
when_unauthenticated
|
74
|
+
else
|
75
|
+
current_session.update_info(request)
|
76
|
+
end
|
77
|
+
|
78
|
+
return
|
79
|
+
end
|
67
80
|
|
68
|
-
|
81
|
+
log_out
|
69
82
|
|
70
83
|
cookies.signed[:veri_return_path] = { value: request.fullpath, expires: 15.minutes.from_now } if request.get? && request.format.html?
|
71
84
|
|
data/lib/veri/version.rb
CHANGED