devise_castle 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/devise_castle/passwords_controller.rb +4 -8
- data/app/controllers/devise_castle/registrations_controller.rb +2 -1
- data/app/controllers/devise_castle/sessions_controller.rb +6 -5
- data/lib/devise_castle.rb +2 -1
- data/lib/devise_castle/hooks.rb +9 -7
- data/lib/devise_castle/model.rb +4 -0
- data/lib/devise_castle/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa81dd6aeae73a0e57f33b846b3e7b776bbf65bd2e43ba83c2f45d330b3e42c1
|
4
|
+
data.tar.gz: 7d573076b55c64bd65145fe4326bafe5182e8efd6175d45f771805dc43349c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0ee13d07f74d6bea5d0ed5eedec68eba66ca5de33b0cb09bc038acdb71953a6b24780f4a7e67523475a7dc607ddd63de06864c714596592c86a1ec7ac4c0cfc
|
7
|
+
data.tar.gz: b7a171552e5b54324a67ef6db6e2008642c0b89c033bd878dac17c504a8805e9e8d16d0d753a82a9fe897cb00d68de3a069e5c68c52c9a07b866be4df25d76de
|
@@ -1,19 +1,15 @@
|
|
1
1
|
class DeviseCastle::PasswordsController < Devise::PasswordsController
|
2
2
|
def create
|
3
|
-
|
4
|
-
|
5
|
-
username = if Devise.reset_password_keys.include?(key.to_sym)
|
6
|
-
resource_params.values.first
|
3
|
+
user_traits = Devise.reset_password_keys.each_with_object({}) do |key, acc|
|
4
|
+
acc[key] = resource_params[key] if resource_params.has?(key)
|
7
5
|
end
|
8
6
|
|
9
7
|
super do |resource|
|
10
8
|
unless resource.respond_to?(:castle_do_not_track?) && resource.castle_do_not_track?
|
11
9
|
begin
|
12
10
|
castle.track(
|
13
|
-
event: '$password_reset.requested'
|
14
|
-
|
15
|
-
'email' => username
|
16
|
-
})
|
11
|
+
{ event: '$password_reset.requested' }.merge({ user_traits: user_traits })
|
12
|
+
)
|
17
13
|
rescue ::Castle::Error => e
|
18
14
|
if Devise.castle_error_handler.is_a?(Proc)
|
19
15
|
Devise.castle_error_handler.call(e)
|
@@ -5,7 +5,8 @@ class DeviseCastle::RegistrationsController < Devise::RegistrationsController
|
|
5
5
|
if resource.persisted?
|
6
6
|
castle.track(
|
7
7
|
event: '$registration.succeeded',
|
8
|
-
user_id: resource._castle_id
|
8
|
+
user_id: resource._castle_id,
|
9
|
+
user_traits: resource.castle_user_traits
|
9
10
|
)
|
10
11
|
else
|
11
12
|
castle.track(
|
@@ -3,14 +3,15 @@ class DeviseCastle::SessionsController < Devise::SessionsController
|
|
3
3
|
protected
|
4
4
|
|
5
5
|
def auth_options
|
6
|
-
# find the
|
7
|
-
|
8
|
-
|
6
|
+
# find the auth params
|
7
|
+
user_traits = sign_in_params.slice(*resource_class.authentication_keys)
|
8
|
+
# there should be one key related to auth
|
9
|
+
key = user_traits.keys.first
|
9
10
|
|
10
11
|
# find the user if any
|
11
|
-
user = resource_class.find_for_authentication(key =>
|
12
|
+
user = resource_class.find_for_authentication(key => sign_in_params[key])
|
12
13
|
|
13
14
|
# make it available to Warden hooks
|
14
|
-
super.merge(
|
15
|
+
super.merge(user_traits: user_traits, user: user)
|
15
16
|
end
|
16
17
|
end
|
data/lib/devise_castle.rb
CHANGED
data/lib/devise_castle/hooks.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Instantiate Castle client on every request
|
2
2
|
Warden::Manager.on_request do |warden|
|
3
|
-
warden.request.env['castle'] =
|
4
|
-
Castle::Client.new(warden.request, warden.cookies)
|
3
|
+
warden.request.env['castle'] = Castle::Client.from_request(warden.request)
|
5
4
|
end
|
6
5
|
|
7
6
|
# Track logout.succeeded
|
@@ -22,7 +21,7 @@ end
|
|
22
21
|
|
23
22
|
# Track login.failed
|
24
23
|
Warden::Manager.before_failure do |env, opts|
|
25
|
-
if opts[:action] == 'unauthenticated' && opts[:
|
24
|
+
if opts[:action] == 'unauthenticated' && opts[:user_traits]
|
26
25
|
|
27
26
|
user_id = if opts[:user].respond_to?(:castle_id)
|
28
27
|
opts[:user]._castle_id
|
@@ -33,9 +32,8 @@ Warden::Manager.before_failure do |env, opts|
|
|
33
32
|
castle.track(
|
34
33
|
event: '$login.failed',
|
35
34
|
user_id: user_id,
|
36
|
-
user_traits:
|
37
|
-
|
38
|
-
})
|
35
|
+
user_traits: opts[:user_traits]
|
36
|
+
)
|
39
37
|
rescue ::Castle::Error => e
|
40
38
|
if Devise.castle_error_handler.is_a?(Proc)
|
41
39
|
Devise.castle_error_handler.call(e)
|
@@ -50,7 +48,11 @@ Warden::Manager.after_set_user :except => :fetch do |record, warden, opts|
|
|
50
48
|
unless record.respond_to?(:castle_do_not_track?) && record.castle_do_not_track?
|
51
49
|
castle = warden.request.env['castle']
|
52
50
|
begin
|
53
|
-
castle.authenticate(
|
51
|
+
castle.authenticate(
|
52
|
+
user_id: record._castle_id,
|
53
|
+
event: '$login.succeeded',
|
54
|
+
user_traits: record.castle_user_traits
|
55
|
+
)
|
54
56
|
rescue ::Castle::Error => e
|
55
57
|
if Devise.castle_error_handler.is_a?(Proc)
|
56
58
|
Devise.castle_error_handler.call(e)
|
data/lib/devise_castle/model.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_castle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Brissmyr
|
@@ -37,20 +37,20 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3'
|
41
41
|
- - "<"
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '4'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
46
|
version_requirements: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: '
|
50
|
+
version: '3'
|
51
51
|
- - "<"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '4'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: bundler
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|