rails_jwt_auth 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/app/models/concerns/rails_jwt_auth/trackable.rb +16 -0
- data/lib/rails_jwt_auth/engine.rb +6 -0
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6422dfa2844d4062fa9da57c3db332748728dc20
|
4
|
+
data.tar.gz: 3dcf6e65015ce00d28e65d4e0c40b85fff629d6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26d8f71f79d84c7bce92ce40e94e6694bcef9cd681be8bc2e28d83569524ea72666b9e0142e8109540311b6de1cad7faca502fdd0267cf6e5ddecbc829fb5023
|
7
|
+
data.tar.gz: 452c77aea5c9c3e34efc52d71cc0bbb0a712b78cf54d376d9bf85486e3d852190c4a4358292c9cfcf312f9cd9fb028196986fe46aae91b3c56495c11f72af9c3
|
data/README.md
CHANGED
@@ -169,6 +169,45 @@ class User
|
|
169
169
|
end
|
170
170
|
```
|
171
171
|
|
172
|
+
## Trackable
|
173
|
+
|
174
|
+
Tracks sign in timestamps and IP address.
|
175
|
+
|
176
|
+
### ActiveRecord
|
177
|
+
|
178
|
+
Include `RailsJwtAuth::Trackable` module into your User class:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
# app/models/user.rb
|
182
|
+
class User < ApplicationRecord
|
183
|
+
include RailsJwtAuth::Authenticatable
|
184
|
+
include RailsJwtAuth::Trackable
|
185
|
+
end
|
186
|
+
```
|
187
|
+
|
188
|
+
and create a migration to add recoverable fields to User model:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
# example migration
|
192
|
+
change_table :users do |t|
|
193
|
+
t.string :last_sign_in_ip
|
194
|
+
t.datetime :last_sign_in_at
|
195
|
+
end
|
196
|
+
```
|
197
|
+
|
198
|
+
### Mongoid
|
199
|
+
|
200
|
+
Include `RailsJwtAuth::Trackable` module into your User class:
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
# app/models/user.rb
|
204
|
+
class User
|
205
|
+
include Mongoid::Document
|
206
|
+
include RailsJwtAuth::Authenticatable
|
207
|
+
include RailsJwtAuth::Trackable
|
208
|
+
end
|
209
|
+
```
|
210
|
+
|
172
211
|
## Controller helpers
|
173
212
|
|
174
213
|
RailsJwtAuth will create some helpers to use inside your controllers.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RailsJwtAuth
|
2
|
+
module Trackable
|
3
|
+
def update_tracked_fields!(request)
|
4
|
+
self.last_sign_in_at = Time.now.utc
|
5
|
+
self.last_sign_in_ip = request.respond_to?(:remote_ip) ? request.remote_ip : request.ip
|
6
|
+
save(validate: false)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
if defined?(Mongoid) && base.ancestors.include?(Mongoid::Document)
|
11
|
+
base.send(:field, :last_sign_in_at, type: Time)
|
12
|
+
base.send(:field, :last_sign_in_ip, type: String)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -14,6 +14,12 @@ module RailsJwtAuth
|
|
14
14
|
end
|
15
15
|
|
16
16
|
Warden::Strategies.add(:authentication_token, Strategies::Jwt)
|
17
|
+
|
18
|
+
Warden::Manager.after_set_user except: :fetch do |record, warden, options|
|
19
|
+
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope])
|
20
|
+
record.update_tracked_fields!(warden.request)
|
21
|
+
end
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_jwt_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- app/models/concerns/rails_jwt_auth/authenticatable.rb
|
90
90
|
- app/models/concerns/rails_jwt_auth/confirmable.rb
|
91
91
|
- app/models/concerns/rails_jwt_auth/recoverable.rb
|
92
|
+
- app/models/concerns/rails_jwt_auth/trackable.rb
|
92
93
|
- app/validators/email_validator.rb
|
93
94
|
- app/views/rails_jwt_auth/mailer/confirmation_instructions.html.erb
|
94
95
|
- app/views/rails_jwt_auth/mailer/reset_password_instructions.html.erb
|