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
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue