activeadmin-logins 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 660b33b13a5aea62eedc1070443bed656e408885
4
+ data.tar.gz: 4ad4856afb5ea844a9e76e1d8de71038d42af637
5
+ SHA512:
6
+ metadata.gz: 63a7ebeee7dafc5477e15d36dd2a9d17843bffabf59ffab9fd118987165141a65531148219758a463fdc361781be35fa199cd6bfb24a69c12eecc8184dbe5830
7
+ data.tar.gz: 2c9e0701948bdf42049c1aca46ffaf8c106bce2fac7b9baebf85266a2ba92ba3f9d6d8e439a1987cbb16e332e0cd91b8ff3d4de714499f311bdca3f8bdf00ae4
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activeadmin-logins.gemspec
4
+ gemspec
5
+
6
+ gem "sinatra", ">= 1.3.0", :require => nil
7
+ gem "activeadmin", github: "gregbell/active_admin", branch: "master"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ivan Novosad
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Activeadmin::Logins
2
+
3
+ Logs login details after a user signs in, it stores IP address, user agent, country and city.
4
+ Uses [GeoIP](https://github.com/cjheath/geoip) gem for retrieving the location.
5
+
6
+ ![](https://raw.githubusercontent.com/kollegorna/activeadmin-logins/master/screenshot.png)
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'activeadmin-logins'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install activeadmin-logins
24
+
25
+ ## Usage
26
+
27
+ rails generate active_admin:logins:install
28
+ rake db:migrate
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/[my-github-username]/activeadmin-logins/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin/logins/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activeadmin-logins"
8
+ spec.version = ActiveAdmin::Logins::VERSION
9
+ spec.authors = ["Ivan Novosad"]
10
+ spec.email = ["ivan.novosad@gmail.com"]
11
+ spec.summary = %q{Write a short summary. Required.}
12
+ spec.description = %q{Write a longer description. Optional.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "app", "data"]
20
+
21
+ spec.add_runtime_dependency 'rails', '~> 4.1.5', '~> 4.1.5'
22
+ spec.add_runtime_dependency "sidekiq", ">= 3.0.0"
23
+ spec.add_runtime_dependency "devise", ">= 3.2.4"
24
+ spec.add_runtime_dependency "geoip", "~> 1.5.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.7"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
@@ -0,0 +1,6 @@
1
+ class UserLogin < ActiveRecord::Base
2
+ belongs_to :user
3
+
4
+ validates :user_id, presence: true
5
+ validates :ip, presence: true
6
+ end
@@ -0,0 +1,25 @@
1
+ require 'geoip'
2
+
3
+ class UserLoginWorker
4
+ include Sidekiq::Worker
5
+
6
+ def perform(user_id, ip, user_agent)
7
+ user = User.find(user_id)
8
+
9
+ geo_ip_city = geo_ip.city(ip)
10
+
11
+ country, city = nil, nil
12
+ if geo_ip_city
13
+ country = geo_ip_city.country_name
14
+ city = geo_ip_city.city_name
15
+ end
16
+
17
+ UserLogin.create! user: user, user_agent: user_agent, ip: ip, country: country, city: city
18
+ end
19
+
20
+ private
21
+
22
+ def geo_ip
23
+ GeoIP.new Gem.find_files("**/GeoLiteCity.dat").first
24
+ end
25
+ end
Binary file
@@ -0,0 +1,6 @@
1
+ module ActiveAdmin
2
+ module Logins
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveAdmin
2
+ module Logins
3
+ VERSION = "0.0.5"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'active_admin/logins/version'
2
+ require 'active_admin/logins/engine'
3
+
4
+ module ActiveAdmin
5
+ module Logins
6
+ end
7
+ end
@@ -0,0 +1,90 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module ActiveAdmin
5
+ module Logins
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
9
+
10
+ desc "Generates the necessary migrations and routes"
11
+
12
+ source_root File.expand_path("../templates", __FILE__)
13
+
14
+ def create_user_login_file
15
+ create_file "app/admin/user_login.rb" do
16
+ %Q{
17
+ ActiveAdmin.register UserLogin do
18
+ config.batch_actions = false
19
+ config.sort_order = 'created_at_desc'
20
+
21
+ filter :ip, as: :string
22
+ filter :user_agent
23
+ filter :created_at
24
+ filter :country
25
+ filter :city
26
+
27
+ # In order to hack the heroku issue with collations
28
+ # We're sorting in rails and not on the DB level
29
+ filter :user, collection: proc { User.all.sort_by { |u| u.first_name.downcase } }
30
+
31
+ index do
32
+ column(:user, sortable: "users.last_name") do |login|
33
+ link_to login.user.full_name, admin_user_path(login.user)
34
+ end
35
+ column :ip
36
+ column :user_agent
37
+ column :country
38
+ column :city
39
+ column(:date, sortable: "created_at") do |login|
40
+ login.created_at
41
+ end
42
+ column(:filter) do |login|
43
+ link_to(I18n.t("messages.filters.this_user", default: "Filter by this user"),
44
+ admin_logins_path({ q: { user_id_eq: login.user.id } }))
45
+ end
46
+ end
47
+
48
+ controller do
49
+ def scoped_collection
50
+ super.includes :user # prevents N+1 queries to your database
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ }
57
+ end
58
+ end
59
+
60
+ def inject_into_user_model
61
+ inject_into_file 'app/models/user.rb', after: "class User < ActiveRecord::Base\n" do <<-'RUBY'
62
+
63
+ has_many :user_logins, dependent: :destroy
64
+
65
+ def update_tracked_fields!(request)
66
+ super
67
+ UserLoginWorker.perform_async(self.id, request.remote_ip, request.user_agent)
68
+ end
69
+
70
+ def full_name
71
+ "#{first_name} #{last_name}"
72
+ end
73
+
74
+ RUBY
75
+ end
76
+ end
77
+
78
+ def create_migrations
79
+ migration_template 'migrations/create_user_logins.rb', 'db/migrate/create_user_logins.rb'
80
+ end
81
+
82
+ private
83
+
84
+ def self.next_migration_number(path)
85
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,19 @@
1
+ class CreateUserLogins < ActiveRecord::Migration
2
+ def self.up
3
+ create_table "user_logins" do |t|
4
+ t.integer "user_id"
5
+ t.string "ip", null: false
6
+ t.string "user_agent"
7
+ t.datetime "created_at"
8
+ t.datetime "updated_at"
9
+ t.string "country"
10
+ t.string "city"
11
+ end
12
+
13
+ add_index "user_logins", ["user_id"]
14
+ end
15
+
16
+ def self.down
17
+ drop_table :user_logins
18
+ end
19
+ end
data/screenshot.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-logins
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Novosad
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: sidekiq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: devise
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: geoip
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ description: Write a longer description. Optional.
98
+ email:
99
+ - ivan.novosad@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - activeadmin-logins.gemspec
110
+ - app/models/user_login.rb
111
+ - app/workers/user_login_worker.rb
112
+ - data/GeoLiteCity.dat
113
+ - lib/active_admin/logins/engine.rb
114
+ - lib/active_admin/logins/version.rb
115
+ - lib/activeadmin-logins.rb
116
+ - lib/generators/active_admin/logins/install/install_generator.rb
117
+ - lib/generators/active_admin/logins/install/templates/migrations/create_user_logins.rb
118
+ - screenshot.png
119
+ homepage: ''
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ - app
128
+ - data
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.5
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Write a short summary. Required.
145
+ test_files: []