mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
18 lines
709 B
Ruby
18 lines
709 B
Ruby
# After each sign in, update sign in time, sign in count and sign in IP.
|
|
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
|
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
|