forked from paritytech/sms-verification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.js
39 lines (35 loc) · 1006 Bytes
/
verify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
const postToContract = require('./post-to-contract')
const sendSMS = require('./send-sms')
const shortid = require('shortid')
module.exports = (req, res) => {
const number = req.params.number
const anonymized = number.slice(-3)
const code = shortid.generate()
postToContract(number, code)
.then((address) => {
console.info(`Challenge sent to contract (tx ${address}).`)
sendSMS(number, code)
.then((msg) => {
console.info(`Verification code sent to …${anonymized}.`)
res.status(202).json({
status: 'ok',
message: `Verification code sent to ${number}.`
})
})
.catch((err) => {
console.error(err.message)
res.status(500).json({
status: 'error',
message: 'An error occured while sending the SMS.'
})
})
})
.catch((err) => {
console.error(err.message)
res.status(500).json({
status: 'error',
message: 'An error occured while sending to the contract.'
})
})
}