35 lines
1.1 KiB
Ruby
35 lines
1.1 KiB
Ruby
|
|
module JamRuby
|
||
|
|
class MachineFingerprint < ActiveRecord::Base
|
||
|
|
|
||
|
|
@@log = Logging.logger[MachineFingerprint]
|
||
|
|
|
||
|
|
belongs_to :user, :class_name => "JamRuby::User"
|
||
|
|
belongs_to :jam_track_right, :class_name => "JamRuby::JamTrackRight"
|
||
|
|
|
||
|
|
TAKEN_ON_SUCCESSFUL_DOWNLOAD = 'dl'
|
||
|
|
TAKEN_ON_FRAUD_CONFLICT = 'fc'
|
||
|
|
|
||
|
|
PRINT_TYPE_ALL = 'a'
|
||
|
|
PRINT_TYPE_ACTIVE = 'r'
|
||
|
|
|
||
|
|
|
||
|
|
validates :user, presence:true
|
||
|
|
validates :when_taken, :inclusion => {:in => [TAKEN_ON_SUCCESSFUL_DOWNLOAD, TAKEN_ON_FRAUD_CONFLICT]}
|
||
|
|
validates :fingerprint, presence: true, uniqueness:true
|
||
|
|
validates :print_type, presence: true, :inclusion => {:in =>[PRINT_TYPE_ALL, PRINT_TYPE_ACTIVE]}
|
||
|
|
validates :remote_ip, presence: true
|
||
|
|
|
||
|
|
def self.create(fingerprint, user, when_taken, print_type, remote_ip, jam_track_right = nil)
|
||
|
|
mf = MachineFingerprint.new
|
||
|
|
mf.fingerprint = fingerprint
|
||
|
|
mf.user = user
|
||
|
|
mf.when_taken = when_taken
|
||
|
|
mf.print_type = print_type
|
||
|
|
mf.remote_ip = remote_ip
|
||
|
|
mf.jam_track_right = jam_track_right
|
||
|
|
unless mf.save
|
||
|
|
@@log.error("unable to create machine fingerprint: #{mf.errors.inspect}")
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|