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

@ -37,7 +37,7 @@ export const testUser = {
avaiblePWRequests: 645,
pwRequestCount: 19,
created: new Date(),
pw: 'secret',
pw: '5d146f72-e1b8-4440-a6e3-f22f31810316',
loginCount: 3,
createdBy: 1,
}

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))

View file

@ -372,7 +372,7 @@ function difference({ dbA, dbB }) {
hr()
log(
`Result length: ${getResultDbLength()}, original length: ${dbLength}, removed ${removedTotal} questions`
`Result length: ${getResultDbLength().toLocaleString()}, original length: ${dbLength.toLocaleString()}, removed ${removedTotal.toLocaleString()} questions`
)
return resultDb
}

@ -1 +1 @@
Subproject commit ed507dc39f5d34703e53585a75a0138e70bcee3a
Subproject commit 32522097c0c0f442e93e00b54ed5dad495f8b093