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: 33fc3ba81b0ff4f44df7e5bf8e6f6e25c5c318d8b1ca02988f200bf0039d19b9
4
- data.tar.gz: 1433809afa4da2090dac9c75d8e1d6a14579c3ad77ff8ae6db49a5291e708b68
3
+ metadata.gz: 02bcadafc5e2561e169ce65e920a7009f7549a0dfc1b5199cd471c01a8deac6f
4
+ data.tar.gz: 9e8b74e83ea6882c5289f6109c9b4f2e8c492874f4ff9794315be7602410ea4a
5
5
  SHA512:
6
- metadata.gz: 86fcd9a468d1f4fcb0c7fbe820c4e67d40a6c5e96a50bb2804141c4ad9960c5f42e0678bdd6bdf8284e9403c7d77e41fb0f756c78cf4acd019d6094aef95212a
7
- data.tar.gz: e50a7bd3673bc9d806e2ed8f3e50820b75373df52720407ccf400073de0ff726ec1e8e89694369878f06b83f8cf8516fdad5ece1645dd62f0afd6ff74e36df95
6
+ metadata.gz: d7dedc00870041d1271c9c680226533030672546666bfac8a4fc0f5c7d26b4ff0eacd138b9edcb4418e017fd09e642e011b1dd06bb68ec69e2e3a4b96fc9805d
7
+ data.tar.gz: 492b0c906f34d2f091030c1d3425d21fbc5442c18080107deafe1397079f8b060609be0fd224324987ff502f1f55dcf0a9be08434f387dca2579e148ce478966
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.3.0
2
+
3
+ ### Breaking
4
+
5
+ - Added account lockout feature
6
+
1
7
  ## v0.2.2
2
8
 
3
9
  ### Bugs
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
- - Supports multiple password hashing algorithms (argon2, bcrypt, scrypt)
11
+ - Multiple password hashing algorithms (argon2, bcrypt, scrypt)
12
12
  - Granular session management and control
13
- - Built-in return path handling
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 in your controllers:
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/master/CONTRIBUTING.md)
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
- current_session.update_info(request) and return if logged_in? && current_session.active?
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
- current_session&.terminate
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
 
@@ -34,6 +34,14 @@ module Veri
34
34
  )
35
35
  end
36
36
 
37
+ def lock!
38
+ update!(locked: true, locked_at: Time.current)
39
+ end
40
+
41
+ def unlock!
42
+ update!(locked: false, locked_at: nil)
43
+ end
44
+
37
45
  private
38
46
 
39
47
  def hasher
data/lib/veri/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Veri
2
- VERSION = "0.2.2".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4