WIP
This commit is contained in:
parent
95fa296190
commit
cd1e9bdb66
4 changed files with 57 additions and 10 deletions
19
lib/error.js
Normal file
19
lib/error.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
const E = function generateError (name) {
|
||||||
|
var CustomErr = function (msg) {
|
||||||
|
this.message = msg
|
||||||
|
this.name = name
|
||||||
|
Error.captureStackTrace(this, CustomErr)
|
||||||
|
}
|
||||||
|
CustomErr.prototype = Object.create(Error.prototype)
|
||||||
|
CustomErr.prototype.constructor = CustomErr
|
||||||
|
|
||||||
|
return CustomErr
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = E
|
||||||
|
|
||||||
|
function register (errorName) {
|
||||||
|
E[errorName] = E(errorName)
|
||||||
|
}
|
||||||
|
|
||||||
|
register('BadNumberError')
|
||||||
|
|
@ -4,6 +4,7 @@ var _ = require('lodash')
|
||||||
var async = require('async')
|
var async = require('async')
|
||||||
|
|
||||||
var BigNumber = require('bignumber.js')
|
var BigNumber = require('bignumber.js')
|
||||||
|
BigNumber.config({CRYPTO: true})
|
||||||
|
|
||||||
var logger = require('./logger')
|
var logger = require('./logger')
|
||||||
var notifier = require('./notifier')
|
var notifier = require('./notifier')
|
||||||
|
|
@ -715,3 +716,16 @@ exports.startCheckingNotification = function startCheckingNotification () {
|
||||||
checkNotification()
|
checkNotification()
|
||||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getPhoneCode = function getPhoneCode (phone) {
|
||||||
|
const code = BigNumber.random().toFixed(6).slice(2)
|
||||||
|
const rec = {
|
||||||
|
sms: {
|
||||||
|
toNumber: phone,
|
||||||
|
body: 'Your cryptomat code: ' + code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return smsPlugin.sendMessage(rec)
|
||||||
|
.then(() => code)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -213,15 +213,15 @@ function pair (req, res) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function raqia (req, res) {
|
function phoneCode (req, res) {
|
||||||
var raqiaCreds
|
var phone = req.body.phone
|
||||||
try {
|
|
||||||
var raqiaRec = require('../raqia.json')
|
return plugins.getPhoneCode(phone)
|
||||||
raqiaCreds = raqiaRec[getFingerprint(req)].apiKeys[0]
|
.then(code => res.json({code: code}))
|
||||||
} catch (ex) {
|
.catch(err => {
|
||||||
raqiaCreds = null
|
if (err.name === 'BadNumberError') return res.send(410)
|
||||||
}
|
return res.send(500)
|
||||||
res.json(raqiaCreds || {})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function init (localConfig) {
|
function init (localConfig) {
|
||||||
|
|
@ -246,7 +246,8 @@ function init (localConfig) {
|
||||||
app.post('/verify_user', authMiddleware, verifyUser)
|
app.post('/verify_user', authMiddleware, verifyUser)
|
||||||
app.post('/verify_transaction', authMiddleware, verifyTx)
|
app.post('/verify_transaction', authMiddleware, verifyTx)
|
||||||
app.post('/pair', pair)
|
app.post('/pair', pair)
|
||||||
app.get('/raqia', raqia)
|
|
||||||
|
app.post('/phone_code', authMiddleware, phoneCode)
|
||||||
|
|
||||||
localApp.get('/pid', function (req, res) {
|
localApp.get('/pid', function (req, res) {
|
||||||
var machineFingerprint = req.query.fingerprint
|
var machineFingerprint = req.query.fingerprint
|
||||||
|
|
|
||||||
13
migrations/007-add-phone.js
Normal file
13
migrations/007-add-phone.js
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
var db = require('./db')
|
||||||
|
|
||||||
|
exports.up = function (next) {
|
||||||
|
var sql = [
|
||||||
|
'alter table transactions add phone text',
|
||||||
|
'create index on transactions (phone)'
|
||||||
|
]
|
||||||
|
db.multi(sql, next)
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.down = function (next) {
|
||||||
|
next()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue