feat: add request data to user_tokens and token filtering
This commit is contained in:
parent
c4e7547c45
commit
791b275cdf
9 changed files with 61 additions and 16 deletions
|
|
@ -1,5 +1,6 @@
|
|||
const crypto = require('crypto')
|
||||
|
||||
const browserOS = require('../../new-lamassu-admin/src/utils/browser-os')
|
||||
const db = require('../db')
|
||||
|
||||
function generateOTP (name) {
|
||||
|
|
@ -21,15 +22,18 @@ function validateOTP (otp) {
|
|||
.catch(() => ({ success: false, expired: false }))
|
||||
}
|
||||
|
||||
function register (otp) {
|
||||
function register (req) {
|
||||
const otp = req.query.otp
|
||||
|
||||
return validateOTP(otp)
|
||||
.then(r => {
|
||||
if (!r.success) return r
|
||||
|
||||
const deviceInfo = browserOS.getInformation(req.headers['user-agent'])
|
||||
const token = crypto.randomBytes(32).toString('hex')
|
||||
const sql = 'insert into user_tokens (token, name) values ($1, $2)'
|
||||
const sql = 'insert into user_tokens (token, name, browser_version, os_version, ip_address) values ($1, $2, $3, $4, $5)'
|
||||
|
||||
return db.none(sql, [token, r.name])
|
||||
return db.none(sql, [token, r.name, deviceInfo.browser, deviceInfo.OS, browserOS.getRequestIP(req)])
|
||||
.then(() => ({ success: true, token: token }))
|
||||
})
|
||||
.catch(() => ({ success: false, expired: false }))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue