mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
added validation token endpoint
This commit is contained in:
parent
ab33a2e059
commit
da8edb7081
4 changed files with 34 additions and 4 deletions
|
@ -37,7 +37,7 @@ export const testUser = {
|
||||||
avaiblePWRequests: 645,
|
avaiblePWRequests: 645,
|
||||||
pwRequestCount: 19,
|
pwRequestCount: 19,
|
||||||
created: new Date(),
|
created: new Date(),
|
||||||
pw: 'secret',
|
pw: '5d146f72-e1b8-4440-a6e3-f22f31810316',
|
||||||
loginCount: 3,
|
loginCount: 3,
|
||||||
createdBy: 1,
|
createdBy: 1,
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
import { v4 as uuidv4 } from 'uuid'
|
import { v4 as uuidv4, v5 } from 'uuid'
|
||||||
import type { Database } from 'better-sqlite3'
|
import type { Database } from 'better-sqlite3'
|
||||||
|
|
||||||
import logger from '../../../utils/logger'
|
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) {
|
function getDayDiff(dateString: string | Date) {
|
||||||
const msdiff = new Date().getTime() - new Date(dateString).getTime()
|
const msdiff = new Date().getTime() - new Date(dateString).getTime()
|
||||||
return Math.floor(msdiff / (1000 * 3600 * 24))
|
return Math.floor(msdiff / (1000 * 3600 * 24))
|
||||||
|
|
|
@ -372,7 +372,7 @@ function difference({ dbA, dbB }) {
|
||||||
|
|
||||||
hr()
|
hr()
|
||||||
log(
|
log(
|
||||||
`Result length: ${getResultDbLength()}, original length: ${dbLength}, removed ${removedTotal} questions`
|
`Result length: ${getResultDbLength().toLocaleString()}, original length: ${dbLength.toLocaleString()}, removed ${removedTotal.toLocaleString()} questions`
|
||||||
)
|
)
|
||||||
return resultDb
|
return resultDb
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit ed507dc39f5d34703e53585a75a0138e70bcee3a
|
Subproject commit 32522097c0c0f442e93e00b54ed5dad495f8b093
|
Loading…
Add table
Add a link
Reference in a new issue