Initial commit
This commit is contained in:
13
app/models/concerns/trusty_agent_validator.rb
Normal file
13
app/models/concerns/trusty_agent_validator.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# User agent validator
|
||||
class TrustyAgentValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, _attribute, value)
|
||||
browser = Browser.new(value)
|
||||
return if browser.known?
|
||||
|
||||
return record.data = { note: 'Detected suspicious browser' }.to_json if record.data.nil?
|
||||
|
||||
record.data = JSON.parse(record.data).merge(note: 'Detected suspicious browser').to_json
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user