2009-11-24 12:18:42 -05:00
|
|
|
# After each sign in, update sign in time, sign in count and sign in IP.
|
2010-01-13 11:45:02 -05:00
|
|
|
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
2009-11-24 12:18:42 -05:00
|
|
|
scope = options[:scope]
|
|
|
|
if Devise.mappings[scope].try(:trackable?) && warden.authenticated?(scope)
|
|
|
|
old_current, new_current = record.current_sign_in_at, Time.now
|
|
|
|
record.last_sign_in_at = old_current || new_current
|
|
|
|
record.current_sign_in_at = new_current
|
|
|
|
|
|
|
|
old_current, new_current = record.current_sign_in_ip, warden.request.remote_ip
|
|
|
|
record.last_sign_in_ip = old_current || new_current
|
|
|
|
record.current_sign_in_ip = new_current
|
|
|
|
|
|
|
|
record.sign_in_count ||= 0
|
|
|
|
record.sign_in_count += 1
|
|
|
|
|
|
|
|
record.save(false)
|
|
|
|
end
|
|
|
|
end
|