authtrail 0.2.1 → 0.2.2

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: 6ca58a6ac201b761a2cf30bed995135a44690ac7616770f9f1d2e74c45e23080
4
- data.tar.gz: 3ab3c476d2b75e1697a0a1e08cdc6e0356c07e266b1839c74eea1c1c4d818023
3
+ metadata.gz: f88e2c20a95601d9da18766155a4eb0300ac193d7be16c56b8f293e42237163b
4
+ data.tar.gz: a74f7435a461fce5c2f2c12d98cc3329aeb6f45c6e54eac6192cd5d04dd1a857
5
5
  SHA512:
6
- metadata.gz: b7a769b8963f67a9cc0d37e194dd1e9b936271cfbc7c88ee0f1fe72252926fc6184c01bd9abad0420231507bc99e54fc22b85916c9a0cb3cc1611c402e3436f3
7
- data.tar.gz: 5cad0685a4773c31ef10f78380c9e64b4ca56828f9ba9eae8b4471a1b7cdd5d827b6f33c27a4963926003b199bbffad3971c98269e87c7cb850db33ad342a352
6
+ metadata.gz: 3a572225e8e080da90c400293ebccbb6a7808f642f2469b79e0777ed37470ccec13ebd31a6f6b57d4fc6b89d037f25c1ae1980298b68b04bdc258ff71037e578
7
+ data.tar.gz: 6558512fa9aa0b95932a95165c79533672f91c612116666cec6afe2743fcb7cd8357e9b230dadcab6ce503d8d8e622566c0d188d9b92cb016c37de5b46e3a09e
@@ -1,3 +1,7 @@
1
+ ## 0.2.2 (2020-11-21)
2
+
3
+ - Added `transform_method` option
4
+
1
5
  ## 0.2.1 (2020-08-17)
2
6
 
3
7
  - Added `job_queue` option
data/README.md CHANGED
@@ -4,7 +4,7 @@ Track Devise login activity
4
4
 
5
5
  :tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
6
6
 
7
- [![Build Status](https://travis-ci.org/ankane/authtrail.svg?branch=master)](https://travis-ci.org/ankane/authtrail)
7
+ [![Build Status](https://github.com/ankane/authtrail/workflows/build/badge.svg?branch=master)](https://github.com/ankane/authtrail/actions)
8
8
 
9
9
  ## Installation
10
10
 
@@ -42,15 +42,31 @@ A `LoginActivity` record is created every time a user tries to login. You can th
42
42
  Exclude certain attempts from tracking - useful if you run acceptance tests
43
43
 
44
44
  ```ruby
45
- AuthTrail.exclude_method = lambda do |info|
46
- info[:identity] == "capybara@example.org"
45
+ AuthTrail.exclude_method = lambda do |data|
46
+ data[:identity] == "capybara@example.org"
47
+ end
48
+ ```
49
+
50
+ Add or modify data (also add new fields to the `login_activities` table)
51
+
52
+ ```ruby
53
+ AuthTrail.transform_method = lambda do |data, request|
54
+ data[:request_id] = request.request_id
55
+ end
56
+ ```
57
+
58
+ Store the user on failed attempts
59
+
60
+ ```ruby
61
+ AuthTrail.transform_method = lambda do |data, request|
62
+ data[:user] ||= User.find_by(email: data[:identity])
47
63
  end
48
64
  ```
49
65
 
50
66
  Write data somewhere other than the `login_activities` table
51
67
 
52
68
  ```ruby
53
- AuthTrail.track_method = lambda do |info|
69
+ AuthTrail.track_method = lambda do |data|
54
70
  # code
55
71
  end
56
72
  ```
@@ -1,3 +1,3 @@
1
1
  module AuthTrail
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -9,7 +9,7 @@ require "auth_trail/version"
9
9
 
10
10
  module AuthTrail
11
11
  class << self
12
- attr_accessor :exclude_method, :geocode, :track_method, :identity_method, :job_queue
12
+ attr_accessor :exclude_method, :geocode, :track_method, :identity_method, :job_queue, :transform_method
13
13
  end
14
14
  self.geocode = true
15
15
  self.identity_method = lambda do |request, opts, user|
@@ -22,7 +22,7 @@ module AuthTrail
22
22
  end
23
23
 
24
24
  def self.track(strategy:, scope:, identity:, success:, request:, user: nil, failure_reason: nil)
25
- info = {
25
+ data = {
26
26
  strategy: strategy,
27
27
  scope: scope,
28
28
  identity: identity,
@@ -35,18 +35,22 @@ module AuthTrail
35
35
  }
36
36
 
37
37
  if request.params[:controller]
38
- info[:context] = "#{request.params[:controller]}##{request.params[:action]}"
38
+ data[:context] = "#{request.params[:controller]}##{request.params[:action]}"
39
39
  end
40
40
 
41
+ # add request data before exclude_method since exclude_method doesn't have access to request
42
+ # could also add 2nd argument to exclude_method when arity > 1
43
+ AuthTrail.transform_method.call(data, request) if AuthTrail.transform_method
44
+
41
45
  # if exclude_method throws an exception, default to not excluding
42
- exclude = AuthTrail.exclude_method && AuthTrail.safely(default: false) { AuthTrail.exclude_method.call(info) }
46
+ exclude = AuthTrail.exclude_method && AuthTrail.safely(default: false) { AuthTrail.exclude_method.call(data) }
43
47
 
44
48
  unless exclude
45
49
  if AuthTrail.track_method
46
- AuthTrail.track_method.call(info)
50
+ AuthTrail.track_method.call(data)
47
51
  else
48
52
  login_activity = LoginActivity.new
49
- info.each do |k, v|
53
+ data.each do |k, v|
50
54
  login_activity.try("#{k}=", v)
51
55
  end
52
56
  login_activity.save!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authtrail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-17 00:00:00.000000000 Z
11
+ date: 2020-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -164,7 +164,7 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description:
167
+ description:
168
168
  email: andrew@chartkick.com
169
169
  executables: []
170
170
  extensions: []
@@ -185,7 +185,7 @@ homepage: https://github.com/ankane/authtrail
185
185
  licenses:
186
186
  - MIT
187
187
  metadata: {}
188
- post_install_message:
188
+ post_install_message:
189
189
  rdoc_options: []
190
190
  require_paths:
191
191
  - lib
@@ -200,8 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubygems_version: 3.1.2
204
- signing_key:
203
+ rubygems_version: 3.1.4
204
+ signing_key:
205
205
  specification_version: 4
206
206
  summary: Track Devise login activity
207
207
  test_files: []