revise_auth 0.4.0 → 0.4.1

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: 4877361ed28001b736c2e6387f0c65fa402229e47b08d34af1feb05ac3d6e8f8
4
- data.tar.gz: 166a23ca4f1d792fa7af671bfcbc73bbb88cec68b611f1c1d9c17e84acd65940
3
+ metadata.gz: 0f24ed4142195b9a07307505fe8f3c5c88bd2da2c7740f69dc02ac4d65154d07
4
+ data.tar.gz: 2d1a7e07138b6806ac73dd290666542f8eab2ad3b83acb11a889339b19a59d23
5
5
  SHA512:
6
- metadata.gz: 891ca6da76f4a09caf6e169412a0c9a9cdc27ba6e641564a365bd8d2a623cf57cba9068fad9b4332424258f1cc95712139e7b9af242916718334782f4b8d5ae2
7
- data.tar.gz: 81400af06d8b1845487acd05a293b1bf101eee6b21b1e1b6908befda918982c18a01df63c70ab96aabc9eebd24514471841741001bcb834445d9d8b9c56242e0
6
+ metadata.gz: 426b8d1832b1ff2eab5e44da0f67833fdacfdd19fe8ed02690140005435554f05e287cc2ff048336a0ca58355fcf01eef85b598facff497aec397a14a4296647
7
+ data.tar.gz: e3eb35bed4d5484e566e575841bb5edff8c79c7e7c3a07875aa21d2bb97e7e21f8f1d0815167fd2cdd0517083a51b4a4eb389104b6ae2eb323abdeab44d77cf0
data/README.md CHANGED
@@ -55,6 +55,22 @@ class ApplicationController < ActionController::Base
55
55
  end
56
56
  ```
57
57
 
58
+ ### Routing Constraints
59
+
60
+ You can use any of the authentication functionality in your routes using the `ReviseAuth::RouteConstraint` class.
61
+
62
+ The following will draw routes only if the user is signed in:
63
+
64
+ ```ruby
65
+ authenticated ->{ _1.admin? } do
66
+ resource :admin
67
+ end
68
+
69
+ authenticated do
70
+ resource :dashboard
71
+ end
72
+ ```
73
+
58
74
  ## Contributing
59
75
 
60
76
  If you have an issue you'd like to submit, please do so using the issue tracker in GitHub. In order for us to help you in the best way possible, please be as detailed as you can.
@@ -8,6 +8,8 @@ module ReviseAuth
8
8
 
9
9
  include Authentication
10
10
 
11
+ delegate :session, to: :@request
12
+
11
13
  def initialize(request)
12
14
  @request = request
13
15
  end
@@ -1,5 +1,7 @@
1
1
  module ActionDispatch::Routing
2
2
  class Mapper
3
+ # Adds helpers for config/routes.rb to constraint routes with authentication
4
+
3
5
  def revise_auth
4
6
  scope module: :revise_auth do
5
7
  revise_registration
@@ -21,10 +23,11 @@ module ActionDispatch::Routing
21
23
  end
22
24
  end
23
25
 
24
- # Adds helpers for config/routes.rb to constraint routes with authentication
25
- #
26
- def authenticated
27
- constraints ->(request) { ReviseAuth::RouteConstraint.new(request).user_signed_in? } do
26
+ def authenticated(block = nil)
27
+ constraints ->(request) {
28
+ rc = ReviseAuth::RouteConstraint.new(request)
29
+ rc.user_signed_in? && (block.nil? || block.call(rc.current_user))
30
+ } do
28
31
  yield
29
32
  end
30
33
  end
@@ -1,3 +1,3 @@
1
1
  module ReviseAuth
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revise_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-27 00:00:00.000000000 Z
11
+ date: 2023-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  requirements: []
107
- rubygems_version: 3.4.19
107
+ rubygems_version: 3.4.20
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Simple authentication for Ruby on Rails apps