authtrail 0.1.3 → 0.2.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: 5d58f1c05f2177c5a9dd84c1aeed638ce17b5d601f8b8b9a677f5046cad5f239
4
- data.tar.gz: 79b099d5edba1165e553c35aa8ed43040ca58c2d1ff2616f76cd020da48b15d5
3
+ metadata.gz: 9ad9a6df032f6b55c8bea0b3ee70bb9248d349abe1277e4debcf658af1f4b3f0
4
+ data.tar.gz: a0d8162b461e5ed2caf2c3d2d6ab5aee10d51c31a64f475de306f5dc94c1a522
5
5
  SHA512:
6
- metadata.gz: bc289ab35e5bddd7ea8043fe771787f737bc6661444921485a0b86d13c741c39e4812277718246d612f17bd63cd9719543d23f57803b17cdd30e20f948eeb1ae
7
- data.tar.gz: 8ba5999ed1ed9f96a225d4f16ce94117204045d3375080ca6dbac0f4020a5e0b00279e69175ef0845403707ea5a1c9b89fe709a0b613666bf207f04cea2c46b2
6
+ metadata.gz: 60b80bfe92e7c351bbc80f7019dfe074e1dc5071a0af31940afdcf330d4b0481b8b020fbe1c3e32b50999781018a89c336a19130713e48045cf90e9d4451aad3
7
+ data.tar.gz: 5507b63ddd85c0dc97a4d6cbd6b7d1fd972df6980f0d232d925a7312d02c2e65b93a6448d9dc38bf8baf61354665eda951540e031c18979fc376ee0acf19a54a
@@ -1,3 +1,9 @@
1
+ ## 0.2.0
2
+
3
+ - Added latitude and longitude
4
+ - `AuthTrail::GeocodeJob` now inherits from `ActiveJob::Base` instead of `ApplicationJob`
5
+ - Removed support for Rails 4.2
6
+
1
7
  ## 0.1.3
2
8
 
3
9
  - Added support for Rails 4.2
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2018 Andrew Kane
1
+ Copyright (c) 2017-2019 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -32,7 +32,7 @@ A `LoginActivity` record is created every time a user tries to login. You can th
32
32
  - `context` - controller and action
33
33
  - `ip` - IP address
34
34
  - `user_agent` and `referrer` - from browser
35
- - `city`, `region`, and `country` - from IP
35
+ - `city`, `region`, `country`, `latitude`, and `longitude` - from IP
36
36
  - `created_at` - time of event
37
37
 
38
38
  ## Features
@@ -53,7 +53,7 @@ AuthTrail.track_method = lambda do |info|
53
53
  end
54
54
  ```
55
55
 
56
- Use a custom identity method [master]
56
+ Use a custom identity method
57
57
 
58
58
  ```ruby
59
59
  AuthTrail.identity_method = lambda do |request, opts, user|
@@ -73,7 +73,7 @@ class User < ApplicationRecord
73
73
  end
74
74
  ```
75
75
 
76
- The `LoginActivity` model uses a [polymorphic association](http://guides.rubyonrails.org/association_basics.html#polymorphic-associations) so it can be associated with different user models.
76
+ The `LoginActivity` model uses a [polymorphic association](https://guides.rubyonrails.org/association_basics.html#polymorphic-associations) so it can be associated with different user models.
77
77
 
78
78
  ## Geocoding
79
79
 
@@ -112,24 +112,34 @@ Geocoder.configure(
112
112
 
113
113
  ## Data Protection
114
114
 
115
- Protect the privacy of your users by encrypting fields that contain personal information, such as `identity` and `ip`. [attr_encrypted](https://github.com/attr-encrypted/attr_encrypted) is great for this.
115
+ Protect the privacy of your users by encrypting fields that contain personal information, such as `identity` and `ip`. [attr_encrypted](https://github.com/attr-encrypted/attr_encrypted) is great for this. Use [blind_index](https://github.com/ankane/blind_index) so you can still query the fields.
116
116
 
117
117
  ```ruby
118
118
  class LoginActivity < ApplicationRecord
119
- attr_encrypted :identity, ...
120
- attr_encrypted :ip, ...
119
+ attr_encrypted :identity, key: ...
120
+ attr_encrypted :ip, key: ...
121
+
122
+ blind_index :identity, key: ...
123
+ blind_index :ip, key: ...
121
124
  end
122
125
  ```
123
126
 
124
- You should also make it clear that you collect this information in your privacy policy.
125
-
126
127
  ## Other Notes
127
128
 
128
129
  We recommend using this in addition to Devise’s `Lockable` module and [Rack::Attack](https://github.com/kickstarter/rack-attack).
129
130
 
130
- Check out [Hardening Devise](https://github.com/ankane/shorts/blob/master/Hardening-Devise.md) and [Secure Rails](https://github.com/ankane/secure_rails) for more best practices.
131
+ Check out [Hardening Devise](https://ankane.org/hardening-devise) and [Secure Rails](https://github.com/ankane/secure_rails) for more best practices.
132
+
133
+ ## Upgrading
134
+
135
+ ### 0.2.0
131
136
 
132
- Works with Rails 4.2+
137
+ To store latitude and longitude, create a migration with:
138
+
139
+ ```ruby
140
+ add_column :login_activities, :latitude, :float
141
+ add_column :login_activities, :longitude, :float
142
+ ```
133
143
 
134
144
  ## History
135
145
 
@@ -1,5 +1,5 @@
1
1
  module AuthTrail
2
- class GeocodeJob < Rails::VERSION::MAJOR >= 5 ? ApplicationJob : ActiveJob::Base
2
+ class GeocodeJob < ActiveJob::Base
3
3
  def perform(login_activity)
4
4
  result =
5
5
  begin
@@ -10,11 +10,17 @@ module AuthTrail
10
10
  end
11
11
 
12
12
  if result
13
- login_activity.update!(
14
- city: result.try(:city).presence,
15
- region: result.try(:state).presence,
16
- country: result.try(:country).presence
17
- )
13
+ attributes = {
14
+ city: result.try(:city),
15
+ region: result.try(:state),
16
+ country: result.try(:country),
17
+ latitude: result.try(:latitude),
18
+ longitude: result.try(:longitude)
19
+ }
20
+ attributes.each do |k, v|
21
+ login_activity.try("#{k}=", v.presence)
22
+ end
23
+ login_activity.save!
18
24
  end
19
25
  end
20
26
  end
@@ -1,3 +1,3 @@
1
1
  module AuthTrail
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,51 +1,21 @@
1
- # taken from https://github.com/collectiveidea/audited/blob/master/lib/generators/audited/install_generator.rb
2
- require "rails/generators"
3
- require "rails/generators/migration"
4
- require "active_record"
5
1
  require "rails/generators/active_record"
6
2
 
7
3
  module Authtrail
8
4
  module Generators
9
5
  class InstallGenerator < Rails::Generators::Base
10
- include Rails::Generators::Migration
11
- source_root File.expand_path("../templates", __FILE__)
12
-
13
- # Implement the required interface for Rails::Generators::Migration.
14
- def self.next_migration_number(dirname) #:nodoc:
15
- next_migration_number = current_migration_number(dirname) + 1
16
- if ::ActiveRecord::Base.timestamped_migrations
17
- [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
18
- else
19
- "%.3d" % next_migration_number
20
- end
21
- end
6
+ include ActiveRecord::Generators::Migration
7
+ source_root File.join(__dir__, "templates")
22
8
 
23
9
  def copy_migration
24
10
  migration_template "login_activities_migration.rb", "db/migrate/create_login_activities.rb", migration_version: migration_version
25
11
  end
26
12
 
27
13
  def generate_model
28
- template "login_activity_model.rb", "app/models/login_activity.rb", model_base_class: model_base_class, ar_optional_flag: ar_optional_flag
14
+ template "login_activity_model.rb", "app/models/login_activity.rb"
29
15
  end
30
16
 
31
17
  def migration_version
32
- if rails5?
33
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
34
- end
35
- end
36
-
37
- def rails5?
38
- Rails::VERSION::MAJOR >= 5
39
- end
40
-
41
- def model_base_class
42
- rails5? ? "ApplicationRecord" : "ActiveRecord::Base"
43
- end
44
-
45
- def ar_optional_flag
46
- if rails5?
47
- ", optional: true"
48
- end
18
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
49
19
  end
50
20
  end
51
21
  end
@@ -14,6 +14,8 @@ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version
14
14
  t.string :city
15
15
  t.string :region
16
16
  t.string :country
17
+ t.float :latitude
18
+ t.float :longitude
17
19
  t.datetime :created_at
18
20
  end
19
21
 
@@ -1,3 +1,3 @@
1
- class LoginActivity < <%= model_base_class %>
2
- belongs_to :user, polymorphic: true<%= ar_optional_flag %>
1
+ class LoginActivity < ApplicationRecord
2
+ belongs_to :user, polymorphic: true, optional: true
3
3
  end
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.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-28 00:00:00.000000000 Z
11
+ date: 2019-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '4.2'
33
+ version: '5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '4.2'
40
+ version: '5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: warden
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -137,15 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: '2.2'
140
+ version: '2.4'
141
141
  required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubyforge_project:
148
- rubygems_version: 2.7.7
147
+ rubygems_version: 3.0.3
149
148
  signing_key:
150
149
  specification_version: 4
151
150
  summary: Track Devise login activity