heartcombo--devise/lib/devise/models/trackable.rb

40 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'devise/hooks/trackable'
module Devise
module Models
# 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)
2011-09-09 09:46:35 +00:00
# * 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
2011-07-23 22:03:10 +00:00
# * last_sign_in_ip - Holds the remote ip of the previous sign in
#
module Trackable
2012-02-19 00:50:59 +00:00
def self.required_fields(klass)
[:current_sign_in_at, :current_sign_in_ip, :last_sign_in_at, :last_sign_in_ip, :sign_in_count]
2012-02-17 19:43:15 +00:00
end
def update_tracked_fields(request)
old_current, new_current = self.current_sign_in_at, Time.now.utc
2010-03-03 11:03:09 +00:00
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, request.remote_ip
2010-03-03 11:03:09 +00:00
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
2010-03-03 11:03:09 +00:00
def update_tracked_fields!(request)
update_tracked_fields(request)
save
2010-03-03 11:03:09 +00:00
end
end
end
end