quo_vadis 2.2.3 → 2.2.4

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: e38d43ca3eb42e7fe421725da06631c57c15308a0ee0fcb395043b3c8d922bde
4
- data.tar.gz: 2e09223593c598cdfcad8cb5947dc4065b499e9a9dee06e8eec1a7cd6124003a
3
+ metadata.gz: 0d059bd573146f59fff8f4fff1ef953c4da0bff83b07125efafadfd40334a9a8
4
+ data.tar.gz: 744bd5ac56082016453309608721c76e37dcb8827f1c7111102d8a0d06961608
5
5
  SHA512:
6
- metadata.gz: 69048fb28b48d94329ee3269cb706f583796893a2a8a6d7177adfb2b9b022f7fe84e4076044816d33d6e4a02b6529b3413c12b38f6dc6a3f3672095683a04610
7
- data.tar.gz: fd2a1c93a899e07d1e9bb2a393a52eccbdb5f9256c894d03ca1eb34bc867f351dfe12149d45879ab5bc5960f9d393cdbbe7f5dc24ab43a46cc3cfa50a6454b44
6
+ metadata.gz: 746819329e2b544e00ca92ccf75cd5293f58160da3243db0c0d6b9dba6d70fde94e59492fd2d73387e20d5f60487dbb98f56eb8c618573215a6b9efd027b4442
7
+ data.tar.gz: caf55aa31161fe96980ab58b2a3d477202e03b80fa2a4a684477bfb6f3aef4c4033ff670b03f2d434cbda45ff4bc23291d288b196440f372545c1eaccd89732f
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@
4
4
  ## HEAD
5
5
 
6
6
 
7
+ ## 2.2.4 (25 June 2024)
8
+
9
+ * Add logged-{in, out} routing constraints.
10
+
11
+
7
12
  ## 2.2.3 (22 May 2024)
8
13
 
9
14
  * Add login shortcut for speedier tests.
data/README.md CHANGED
@@ -137,6 +137,23 @@ Call this to find out whether a user has authenticated with a password.
137
137
  Available in controllers and views.
138
138
 
139
139
 
140
+ ### Routes
141
+
142
+ You can use routing constraints to restrict routes to logged-in or logged-out users. For example:
143
+
144
+ ```ruby
145
+ Rails.application.routes.draw do
146
+ constraints(QuoVadis::Constraints::LoggedOut) do
147
+ root "pages#index"
148
+ end
149
+
150
+ constraints(QuoVadis::Constraints::LoggedIn) do
151
+ root "dashboard#show", as: :dashboard
152
+ end
153
+ end
154
+ ```
155
+
156
+
140
157
  ### Views
141
158
 
142
159
  You can use `authenticated_model` and `logged_in?` in your views. For example:
@@ -0,0 +1,13 @@
1
+ module QuoVadis
2
+ module Constraints
3
+
4
+ class LoggedIn
5
+ def self.matches?(request)
6
+ cookies = ActionDispatch::Cookies::CookieJar.build(request, request.cookies)
7
+ session_id = cookies.encrypted[QuoVadis.cookie_name]
8
+ session_id && QuoVadis::Session.find_by(id: session_id)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module QuoVadis
2
+ module Constraints
3
+
4
+ class LoggedOut
5
+ def self.matches?(request)
6
+ cookies = ActionDispatch::Cookies::CookieJar.build(request, request.cookies)
7
+ session_id = cookies.encrypted[QuoVadis.cookie_name]
8
+ session_id.nil? || QuoVadis::Session.find_by(id: session_id).nil?
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QuoVadis
4
- VERSION = '2.2.3'
4
+ VERSION = '2.2.4'
5
5
  end
data/lib/quo_vadis.rb CHANGED
@@ -117,6 +117,8 @@ require_relative 'quo_vadis/ip_masking'
117
117
  require_relative 'quo_vadis/model'
118
118
  require_relative 'quo_vadis/current_request_details'
119
119
  require_relative 'quo_vadis/controller'
120
+ require_relative 'quo_vadis/constraints/logged_in'
121
+ require_relative 'quo_vadis/constraints/logged_out'
120
122
 
121
123
  ActiveSupport.on_load(:action_controller) do
122
124
  include QuoVadis::Controller
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quo_vadis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-22 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -125,6 +125,8 @@ files:
125
125
  - db/migrate/202102150904_setup.rb
126
126
  - lib/generators/quo_vadis/install_generator.rb
127
127
  - lib/quo_vadis.rb
128
+ - lib/quo_vadis/constraints/logged_in.rb
129
+ - lib/quo_vadis/constraints/logged_out.rb
128
130
  - lib/quo_vadis/controller.rb
129
131
  - lib/quo_vadis/crypt.rb
130
132
  - lib/quo_vadis/current_request_details.rb
@@ -219,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
221
  - !ruby/object:Gem::Version
220
222
  version: '0'
221
223
  requirements: []
222
- rubygems_version: 3.5.3
224
+ rubygems_version: 3.5.11
223
225
  signing_key:
224
226
  specification_version: 4
225
227
  summary: Multifactor authentication for Rails 6 and 7.