mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00

This reverts commit 43d0715238
.
save() returns false only when validations failed. In this case, validations are
not performed. Therefore save() may never return a falsy value.
If save() fails, the appropriate exception is raised.
With certain ORMs, such as NoBrainer, save() never returns true/false, but
always raise an exception. This commit lift the incompatiblity.
37 lines
1.3 KiB
Ruby
37 lines
1.3 KiB
Ruby
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)
|
|
# * 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
|
|
#
|
|
module Trackable
|
|
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
|
|
|
|
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, request.remote_ip
|
|
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
|
|
|
|
def update_tracked_fields!(request)
|
|
update_tracked_fields(request)
|
|
save(validate: false)
|
|
end
|
|
end
|
|
end
|
|
end
|