added validation token endpoint

This commit is contained in:
mrfry 2023-03-09 17:11:52 +01:00
parent ab33a2e059
commit da8edb7081
4 changed files with 34 additions and 4 deletions

View file

@ -18,7 +18,7 @@
------------------------------------------------------------------------- */
import { v4 as uuidv4 } from 'uuid'
import { v4 as uuidv4, v5 } from 'uuid'
import type { Database } from 'better-sqlite3'
import logger from '../../../utils/logger'
@ -280,6 +280,36 @@ function setup(data: SubmoduleData): Submodule {
})
})
const name = 'qmining'
app.get(
'/validationtoken',
(req: Request<{ token: string; userid: string }>, res: any) => {
logger.LogReq(req)
const user: User = req.session.user
const { token, userid } = req.query
if (token && userid) {
const specifiedUser: User = dbtools.Select(userDB, 'users', {
id: +userid,
})[0]
const key = v5(name, specifiedUser.pw)
const isValid = key === token
res.json({
result: 'success',
isValid: isValid,
})
} else {
const key = v5(name, user.pw)
res.json({
result: 'success',
key: key,
})
}
}
)
function getDayDiff(dateString: string | Date) {
const msdiff = new Date().getTime() - new Date(dateString).getTime()
return Math.floor(msdiff / (1000 * 3600 * 24))