mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2025-10-03 09:49:32 +02:00
Remove tokgen
This commit is contained in:
parent
b9b6f2ad35
commit
5555c00c2c
3 changed files with 19 additions and 98 deletions
64
package-lock.json
generated
64
package-lock.json
generated
|
@ -25,7 +25,6 @@
|
||||||
"sequelize": "^6.11.0",
|
"sequelize": "^6.11.0",
|
||||||
"socket.io": "^4.0.1",
|
"socket.io": "^4.0.1",
|
||||||
"sqlite3": "^4.0.0",
|
"sqlite3": "^4.0.0",
|
||||||
"tokgen": "^1.0.0",
|
|
||||||
"umzug": "^2.3.0"
|
"umzug": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -38,7 +37,6 @@
|
||||||
"@types/lodash": "^4.14.166",
|
"@types/lodash": "^4.14.166",
|
||||||
"@types/node": "^14.14.16",
|
"@types/node": "^14.14.16",
|
||||||
"@types/nodemailer": "^6.4.4",
|
"@types/nodemailer": "^6.4.4",
|
||||||
"@types/tokgen": "^1.0.0",
|
|
||||||
"@types/umzug": "^2.3.0",
|
"@types/umzug": "^2.3.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
||||||
"@typescript-eslint/parser": "^5.10.0",
|
"@typescript-eslint/parser": "^5.10.0",
|
||||||
|
@ -456,12 +454,6 @@
|
||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/tokgen": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/tokgen/-/tokgen-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-Z5O2np23clViCB52VrQ49yxeJSYT7y2NHVTw2vYdA9egCovACMK2lT/rwGSpuT3cYUVe2quZh8+GdMpJwJt4dg==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"node_modules/@types/umzug": {
|
"node_modules/@types/umzug": {
|
||||||
"version": "2.3.3",
|
"version": "2.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/umzug/-/umzug-2.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/umzug/-/umzug-2.3.3.tgz",
|
||||||
|
@ -1679,17 +1671,6 @@
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/expand-string": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/expand-string/-/expand-string-1.1.1.tgz",
|
|
||||||
"integrity": "sha1-fBHCis10tezZkluPKezSeT+HFU4=",
|
|
||||||
"dependencies": {
|
|
||||||
"lodash.defaults": "^4.0.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/express": {
|
"node_modules/express": {
|
||||||
"version": "4.17.2",
|
"version": "4.17.2",
|
||||||
"resolved": "https://registry.npmjs.org/express/-/express-4.17.2.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-4.17.2.tgz",
|
||||||
|
@ -2421,11 +2402,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||||
},
|
},
|
||||||
"node_modules/lodash.defaults": {
|
|
||||||
"version": "4.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz",
|
|
||||||
"integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw="
|
|
||||||
},
|
|
||||||
"node_modules/lodash.isplainobject": {
|
"node_modules/lodash.isplainobject": {
|
||||||
"version": "4.0.6",
|
"version": "4.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
||||||
|
@ -4678,18 +4654,6 @@
|
||||||
"node": ">=0.6"
|
"node": ">=0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/tokgen": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/tokgen/-/tokgen-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-5wmIWfbnzKXwGSoFW0GN6kJQBOM=",
|
|
||||||
"dependencies": {
|
|
||||||
"expand-string": "^1.1.1",
|
|
||||||
"lodash.defaults": "^4.0.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/toposort-class": {
|
"node_modules/toposort-class": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz",
|
||||||
|
@ -5724,12 +5688,6 @@
|
||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@types/tokgen": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/tokgen/-/tokgen-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-Z5O2np23clViCB52VrQ49yxeJSYT7y2NHVTw2vYdA9egCovACMK2lT/rwGSpuT3cYUVe2quZh8+GdMpJwJt4dg==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"@types/umzug": {
|
"@types/umzug": {
|
||||||
"version": "2.3.3",
|
"version": "2.3.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/umzug/-/umzug-2.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/@types/umzug/-/umzug-2.3.3.tgz",
|
||||||
|
@ -6600,14 +6558,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
||||||
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
|
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
|
||||||
},
|
},
|
||||||
"expand-string": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/expand-string/-/expand-string-1.1.1.tgz",
|
|
||||||
"integrity": "sha1-fBHCis10tezZkluPKezSeT+HFU4=",
|
|
||||||
"requires": {
|
|
||||||
"lodash.defaults": "^4.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"express": {
|
"express": {
|
||||||
"version": "4.17.2",
|
"version": "4.17.2",
|
||||||
"resolved": "https://registry.npmjs.org/express/-/express-4.17.2.tgz",
|
"resolved": "https://registry.npmjs.org/express/-/express-4.17.2.tgz",
|
||||||
|
@ -7179,11 +7129,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||||
},
|
},
|
||||||
"lodash.defaults": {
|
|
||||||
"version": "4.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz",
|
|
||||||
"integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw="
|
|
||||||
},
|
|
||||||
"lodash.isplainobject": {
|
"lodash.isplainobject": {
|
||||||
"version": "4.0.6",
|
"version": "4.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
|
||||||
|
@ -8779,15 +8724,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
|
||||||
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="
|
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="
|
||||||
},
|
},
|
||||||
"tokgen": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/tokgen/-/tokgen-1.0.0.tgz",
|
|
||||||
"integrity": "sha1-5wmIWfbnzKXwGSoFW0GN6kJQBOM=",
|
|
||||||
"requires": {
|
|
||||||
"expand-string": "^1.1.1",
|
|
||||||
"lodash.defaults": "^4.0.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"toposort-class": {
|
"toposort-class": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz",
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
"@types/lodash": "^4.14.166",
|
"@types/lodash": "^4.14.166",
|
||||||
"@types/node": "^14.14.16",
|
"@types/node": "^14.14.16",
|
||||||
"@types/nodemailer": "^6.4.4",
|
"@types/nodemailer": "^6.4.4",
|
||||||
"@types/tokgen": "^1.0.0",
|
|
||||||
"@types/umzug": "^2.3.0",
|
"@types/umzug": "^2.3.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
"@typescript-eslint/eslint-plugin": "^5.10.0",
|
||||||
"@typescript-eslint/parser": "^5.10.0",
|
"@typescript-eslint/parser": "^5.10.0",
|
||||||
|
@ -64,7 +63,6 @@
|
||||||
"sequelize": "^6.11.0",
|
"sequelize": "^6.11.0",
|
||||||
"socket.io": "^4.0.1",
|
"socket.io": "^4.0.1",
|
||||||
"sqlite3": "^4.0.0",
|
"sqlite3": "^4.0.0",
|
||||||
"tokgen": "^1.0.0",
|
|
||||||
"umzug": "^2.3.0"
|
"umzug": "^2.3.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -15,22 +15,26 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as TokenGenerator from 'tokgen'
|
import { randomInt } from 'crypto'
|
||||||
import { ValidationException } from '../exception'
|
import { ValidationException } from '../exception'
|
||||||
|
|
||||||
const authTokenGenerator = new TokenGenerator({
|
const defaultAlphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
length: 32,
|
|
||||||
chars: 'a-zA-Z0-9'
|
|
||||||
})
|
|
||||||
|
|
||||||
export const generateAuthToken = () => authTokenGenerator.generate()
|
function randomString(chars: string, length: number) {
|
||||||
|
let result = ''
|
||||||
|
|
||||||
const idWithinFamilyGenerator = new TokenGenerator({
|
for (let i = 0; i < length; i++) {
|
||||||
length: 6,
|
result += chars[randomInt(chars.length)]
|
||||||
chars: 'a-zA-Z0-9'
|
}
|
||||||
})
|
|
||||||
|
|
||||||
export const generateIdWithinFamily = () => idWithinFamilyGenerator.generate()
|
if (result.length !== length) throw new Error()
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateAuthToken = randomString.bind(null, defaultAlphabet, 32)
|
||||||
|
|
||||||
|
export const generateIdWithinFamily = randomString.bind(null, defaultAlphabet, 6)
|
||||||
export const isIdWithinFamily = (id: string) => id.length === 6 && /^[a-zA-Z0-9]+$/.test(id)
|
export const isIdWithinFamily = (id: string) => id.length === 6 && /^[a-zA-Z0-9]+$/.test(id)
|
||||||
export const assertIdWithinFamily = (id: string) => {
|
export const assertIdWithinFamily = (id: string) => {
|
||||||
if (!isIdWithinFamily(id)) {
|
if (!isIdWithinFamily(id)) {
|
||||||
|
@ -41,23 +45,6 @@ export const assertIdWithinFamily = (id: string) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const versionIdGenerator = new TokenGenerator({
|
export const generateVersionId = randomString.bind(null, defaultAlphabet, 4)
|
||||||
length: 4,
|
export const generateFamilyId = randomString.bind(null, defaultAlphabet, 10)
|
||||||
chars: 'a-zA-Z0-9'
|
export const generatePurchaseId = randomString.bind(null, defaultAlphabet, 10)
|
||||||
})
|
|
||||||
|
|
||||||
export const generateVersionId = () => versionIdGenerator.generate()
|
|
||||||
|
|
||||||
const familyIdGenerator = new TokenGenerator({
|
|
||||||
length: 10,
|
|
||||||
chars: 'a-zA-Z0-9'
|
|
||||||
})
|
|
||||||
|
|
||||||
export const generateFamilyId = () => familyIdGenerator.generate()
|
|
||||||
|
|
||||||
const purchaseIdGenerator = new TokenGenerator({
|
|
||||||
length: 10,
|
|
||||||
chars: 'a-zA-Z0-9'
|
|
||||||
})
|
|
||||||
|
|
||||||
export const generatePurchaseId = () => purchaseIdGenerator.generate()
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue