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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 324dfc68613286f41877c2f6d3f9af318fefa637acb15bd3b0067d000a33624f
4
- data.tar.gz: 5e555ffaa34f030dff9804988d0667d300cd4016272032ddd495a5aa714decdf
3
+ metadata.gz: aa81dd6aeae73a0e57f33b846b3e7b776bbf65bd2e43ba83c2f45d330b3e42c1
4
+ data.tar.gz: 7d573076b55c64bd65145fe4326bafe5182e8efd6175d45f771805dc43349c68
5
5
  SHA512:
6
- metadata.gz: dff55e8aacf6c36c5128ec482cfb40eea2d8857a7459a7fa65ce9d0c784892dad4429602474b479abbc504c274b16c5a7e946573c191b43ebe234da63ec4277d
7
- data.tar.gz: 4174686cbe74e108af22f08b4d1a6fbcde9407df0a856e52eb41a17d63d053803db05c629950d19e791b8824e5e620121dca14582abd8b2638fcadd91b15ba8d
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
- key = resource_params.keys.first
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
- user_traits: {
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 username
7
- key = serialize_options(resource)[:methods].first
8
- username = sign_in_params[key]
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 => username)
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(username: username, user: user)
15
+ super.merge(user_traits: user_traits, user: user)
15
16
  end
16
17
  end
@@ -3,7 +3,8 @@ require 'devise'
3
3
  require 'devise_castle/hooks'
4
4
  require 'devise_castle/mapping'
5
5
  require 'devise_castle/routes'
6
- require 'castle-rb'
6
+ require 'castle'
7
+ require 'castle/support/rails'
7
8
 
8
9
  module Devise
9
10
  mattr_accessor :castle_api_secret
@@ -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[:username]
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
- 'email' => opts[:username]
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(user_id: record._castle_id, event: '$login.succeeded')
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)
@@ -42,6 +42,10 @@
42
42
  def castle_do_not_track?
43
43
  @castle_do_not_track || false
44
44
  end
45
+
46
+ def castle_user_traits
47
+ attributes.slice(*Devise.authentication_keys.map(&:to_s))
48
+ end
45
49
  end
46
50
  end
47
51
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseCastle
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "2.1.0".freeze
3
3
  end
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.0.0
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: '2'
40
+ version: '3'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '3'
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: '2'
50
+ version: '3'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '3'
53
+ version: '4'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: bundler
56
56
  requirement: !ruby/object:Gem::Requirement