veri 0.2.1 → 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: 6119b194fd813a1aad85a20b8513a15fe30143f601e1f2ce6cefa5d46085af70
4
- data.tar.gz: c05d56946b5a010977bee885a807f2986e6d811eb3e9cc96cc0cc44ffe98b9f2
3
+ metadata.gz: 02bcadafc5e2561e169ce65e920a7009f7549a0dfc1b5199cd471c01a8deac6f
4
+ data.tar.gz: 9e8b74e83ea6882c5289f6109c9b4f2e8c492874f4ff9794315be7602410ea4a
5
5
  SHA512:
6
- metadata.gz: eb7c6dfd8fe97b4c7a29b11cb06d01f29dc1ee86cf962512a6db239fcc2f3be1f0ebabc9875c4122843970daab8250d75cde8f4c63016f4580cae1169a41c3c7
7
- data.tar.gz: a96429440653c18be22e9f425ef3dac167fc773666b0f99fb1ab0a08df747c8f27aa4f7d812d76f420a2974a48b46b916a14795f0445307dd0d73cc0f21e2f8b
6
+ metadata.gz: d7dedc00870041d1271c9c680226533030672546666bfac8a4fc0f5c7d26b4ff0eacd138b9edcb4418e017fd09e642e011b1dd06bb68ec69e2e3a4b96fc9805d
7
+ data.tar.gz: 492b0c906f34d2f091030c1d3425d21fbc5442c18080107deafe1397079f8b060609be0fd224324987ff502f1f55dcf0a9be08434f387dca2579e148ce478966
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## v0.3.0
2
+
3
+ ### Breaking
4
+
5
+ - Added account lockout feature
6
+
7
+ ## v0.2.2
8
+
9
+ ### Bugs
10
+
11
+ - Fixed class resolution in `current_user` method
12
+
1
13
  ## v0.2.1
2
14
 
3
15
  ### Misc
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 }
@@ -23,7 +23,9 @@ module Veri
23
23
  end
24
24
 
25
25
  def current_user
26
- @current_user ||= current_session&.identity
26
+ user_model = Veri::Configuration.user_model
27
+ primary_key = user_model.primary_key
28
+ @current_user ||= current_session ? user_model.find_by(primary_key => current_session.authenticatable_id) : nil
27
29
  end
28
30
 
29
31
  def current_session
@@ -37,8 +39,12 @@ module Veri
37
39
  as: :authenticatable,
38
40
  message: "Expected an instance of #{Veri::Configuration.user_model_name}, got `#{authenticatable.inspect}`"
39
41
  )
42
+
43
+ return false if processed_authenticatable.locked?
44
+
40
45
  token = Veri::Session.establish(processed_authenticatable, request)
41
46
  cookies.encrypted.permanent[:veri_token] = { value: token, httponly: true }
47
+ true
42
48
  end
43
49
 
44
50
  def log_out
@@ -61,9 +67,18 @@ module Veri
61
67
  private
62
68
 
63
69
  def with_authentication
64
- 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
65
80
 
66
- current_session&.terminate
81
+ log_out
67
82
 
68
83
  cookies.signed[:veri_return_path] = { value: request.fullpath, expires: 15.minutes.from_now } if request.get? && request.format.html?
69
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.1".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.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - enjaku4