format for latest standard

This commit is contained in:
Josh Harvey 2018-03-10 18:59:40 +00:00
parent 4108efd9c7
commit c2af183911
77 changed files with 1697 additions and 1693 deletions

View file

@ -8,7 +8,7 @@ function generateOTP (name) {
const sql = 'insert into one_time_passes (token, name) values ($1, $2)'
return db.none(sql, [otp, name])
.then(() => otp)
.then(() => otp)
}
function validateOTP (otp) {
@ -17,22 +17,22 @@ function validateOTP (otp) {
returning name, created < now() - interval '1 hour' as expired`
return db.one(sql, [otp])
.then(r => ({success: !r.expired, expired: r.expired, name: r.name}))
.catch(() => ({success: false, expired: false}))
.then(r => ({success: !r.expired, expired: r.expired, name: r.name}))
.catch(() => ({success: false, expired: false}))
}
function register (otp) {
return validateOTP(otp)
.then(r => {
if (!r.success) return r
.then(r => {
if (!r.success) return r
const token = crypto.randomBytes(32).toString('hex')
const sql = 'insert into user_tokens (token, name) values ($1, $2)'
const token = crypto.randomBytes(32).toString('hex')
const sql = 'insert into user_tokens (token, name) values ($1, $2)'
return db.none(sql, [token, r.name])
.then(() => ({success: true, token: token}))
})
.catch(() => ({success: false, expired: false}))
return db.none(sql, [token, r.name])
.then(() => ({success: true, token: token}))
})
.catch(() => ({success: false, expired: false}))
}
function authenticate (token) {