Module: Devise::Models::Trackable
- Defined in:
- lib/devise/models/trackable.rb
Overview
Track information about your user sign in. It tracks the following columns:
-
sign_in_count - Increased every time a sign in is made (by form, openid, oauth)
-
current_sign_in_at - A timestamp updated when the user signs in
-
last_sign_in_at - Holds the timestamp of the previous sign in
-
current_sign_in_ip - The remote ip updated when the user sign in
-
last_sign_in_ip - Holds the remote ip of the previous sign in
Class Method Summary collapse
Instance Method Summary collapse
- #extract_ip_from(request) ⇒ Object protected
- #update_tracked_fields(request) ⇒ Object
- #update_tracked_fields!(request) ⇒ Object
Class Method Details
.required_fields(klass) ⇒ Object
16 17 18 |
# File 'lib/devise/models/trackable.rb', line 16 def self.required_fields(klass) [:current_sign_in_at, :current_sign_in_ip, :last_sign_in_at, :last_sign_in_ip, :sign_in_count] end |
Instance Method Details
#extract_ip_from(request) ⇒ Object (protected)
45 46 47 |
# File 'lib/devise/models/trackable.rb', line 45 def extract_ip_from(request) request.remote_ip end |
#update_tracked_fields(request) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/devise/models/trackable.rb', line 20 def update_tracked_fields(request) old_current, new_current = self.current_sign_in_at, Time.now.utc self.last_sign_in_at = old_current || new_current self.current_sign_in_at = new_current old_current, new_current = self.current_sign_in_ip, extract_ip_from(request) self.last_sign_in_ip = old_current || new_current self.current_sign_in_ip = new_current self.sign_in_count ||= 0 self.sign_in_count += 1 end |
#update_tracked_fields!(request) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/devise/models/trackable.rb', line 33 def update_tracked_fields!(request) # We have to check if the user is already persisted before running # `save` here because invalid users can be saved if we don't. # See https://github.com/heartcombo/devise/issues/4673 for more details. return if new_record? update_tracked_fields(request) save(validate: false) end |