Sha256: 8043e507da132320164f452f6a354568fc209c0367626b51808d5fc249de7be5

Contents?: true

Size: 1.31 KB

Versions: 24

Compression:

Stored size: 1.31 KB

Contents

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

Version data entries

24 entries across 24 versions & 4 rubygems

Version Path
devise-4.3.0 lib/devise/models/trackable.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/devise-4.2.1/lib/devise/models/trackable.rb
devise-4.2.1 lib/devise/models/trackable.rb
devise-4.2.0 lib/devise/models/trackable.rb
devise-3.5.10 lib/devise/models/trackable.rb
devise-4.0.3 lib/devise/models/trackable.rb
devise-4.1.1 lib/devise/models/trackable.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/devise-4.1.0/lib/devise/models/trackable.rb
devise-4.1.0 lib/devise/models/trackable.rb
devise-3.5.9 lib/devise/models/trackable.rb
devise-4.0.2 lib/devise/models/trackable.rb
devise-4.0.1 lib/devise/models/trackable.rb
devise-3.5.8 lib/devise/models/trackable.rb
devise-3.5.7 lib/devise/models/trackable.rb
devise-4.0.0 lib/devise/models/trackable.rb
devise-4.0.0.rc2 lib/devise/models/trackable.rb
devise-4.0.0.rc1 lib/devise/models/trackable.rb
devise-3.5.6 lib/devise/models/trackable.rb
devise-3.5.5 lib/devise/models/trackable.rb
devise-3.5.4 lib/devise/models/trackable.rb