feat: update the customer's last_used_machine on auth attempt

This commit is contained in:
siiky 2024-07-18 16:47:59 +01:00
parent bb303a38cf
commit 53830aba52
2 changed files with 8 additions and 7 deletions

View file

@ -930,9 +930,9 @@ function disableTestCustomer (customerId) {
return db.none(sql, [customerId])
}
function updateLastAuthAttempt (customerId) {
const sql = `UPDATE customers SET last_auth_attempt=NOW() WHERE id=$1`
return db.none(sql, [customerId])
function updateLastAuthAttempt (customerId, deviceId) {
const sql = `UPDATE customers SET last_auth_attempt=NOW(), last_used_machine=$2 WHERE id=$1`
return db.none(sql, [customerId, deviceId])
}
function getExternalComplianceMachine (customer) {

View file

@ -257,7 +257,7 @@ function getExternalComplianceLink (req, res, next) {
.then(url => respond(req, res, { url }))
}
function addOrUpdateCustomer (customerData, config, isEmailAuth) {
function addOrUpdateCustomer (customerData, deviceId, config, isEmailAuth) {
const triggers = configManager.getTriggers(config)
const maxDaysThreshold = complianceTriggers.maxDaysThreshold(triggers)
@ -273,7 +273,7 @@ function addOrUpdateCustomer (customerData, config, isEmailAuth) {
})
.then(customer => customers.getById(customer.id))
.then(customer => {
customers.updateLastAuthAttempt(customer.id).catch(() => {
customers.updateLastAuthAttempt(customer.id, deviceId).catch(() => {
logger.info('failure updating last auth attempt for customer ', customer.id)
})
return customer
@ -292,14 +292,15 @@ function addOrUpdateCustomer (customerData, config, isEmailAuth) {
}
function getOrAddCustomerPhone (req, res, next) {
const deviceId = req.deviceId
const customerData = req.body
const pi = plugins(req.settings, req.deviceId)
const pi = plugins(req.settings, deviceId)
const phone = req.body.phone
return pi.getPhoneCode(phone)
.then(code => {
return addOrUpdateCustomer(customerData, req.settings.config, false)
return addOrUpdateCustomer(customerData, deviceId, req.settings.config, false)
.then(customer => respond(req, res, { code, customer }))
})
.catch(err => {