ilp-core
Version:
ILP core module managing ledger abstraction
53 lines (45 loc) • 1.61 kB
JavaScript
const requestIp = require('request-ip')
const superagent = require('superagent-promise')(require('superagent'), Promise)
const Log = require('./log')
const Config = require('../lib/config')
const ServerError = require('../errors/server-error')
module.exports = class Antifraud {
static constitute () { return [Config, Log] }
constructor (config, log) {
this.config = config
this.log = log('antifraud')
}
* checkRisk (userObj) {
// Check for fraud
const serviceUrl = this.config.data.getIn(['antifraud', 'service_url'])
if (serviceUrl) {
const maxRisk = this.config.data.getIn(['antifraud', 'max_risk'])
let response
try {
response = yield superagent.post(serviceUrl, {
email: userObj.email || '',
username: userObj.username || '',
name: userObj.name || '',
phone: userObj.phone || '',
address1: userObj.address1 || '',
address2: userObj.address2 || '',
city: userObj.city || '',
region: userObj.region || '',
country: userObj.country || '',
zip_code: userObj.zip_code || '',
ip_address: requestIp.getClientIp(this.req),
augurio_unique_id: userObj.fingerprint
})
} catch (err) {
this.log.error('Antifraud service error: ', err)
}
if (response.body && response.body.risklevel) {
this.log.debug('Signup try: risk level is', response.body.risklevel)
if (response.body.risklevel > maxRisk) {
throw new ServerError('Signup denied')
}
}
}
}
}