From e19fc42dacce30680d5ae9528fabeb565cc99fa4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 24 Aug 2022 10:35:06 +0200 Subject: [PATCH 1/6] Added qrcode library for totp qrcode generation https://www.npmjs.com/package/qrcode --- package.json | 2 ++ yarn.lock | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c8c3861..9de26ef 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "passport": "^0.6.0", "passport-jwt": "^4.0.0", "passport-local": "^1.0.0", + "qrcode": "^1.5.1", "reflect-metadata": "^0.1.13", "rxjs": "^7.5.6", "sqlite3": "^5.0.11", @@ -50,6 +51,7 @@ "@types/node": "^18.6.5", "@types/passport-jwt": "^3.0.6", "@types/passport-local": "^1.0.34", + "@types/qrcode": "^1.5.0", "@types/supertest": "^2.0.12", "@types/webpack": "^5.28.0", "@types/webpack-node-externals": "^2.5.3", diff --git a/yarn.lock b/yarn.lock index bb3f387..e7ee3e5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1148,6 +1148,13 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.0.tgz#ea03e9f0376a4446f44797ca19d9c46c36e352dc" integrity sha512-RI1L7N4JnW5gQw2spvL7Sllfuf1SaHdrZpCHiBlCXjIlufi1SMNnbu2teze3/QE67Fg2tBlH7W+mi4hVNk4p0A== +"@types/qrcode@^1.5.0": + version "1.5.0" + resolved "https://registry.yarnpkg.com/@types/qrcode/-/qrcode-1.5.0.tgz#6a98fe9a9a7b2a9a3167b6dde17eff999eabe40b" + integrity sha512-x5ilHXRxUPIMfjtM+1vf/GPTRWZ81nqscursm5gMznJeK9M0YnZ1c3bEvRLQ0zSSgedLx1J6MGL231ObQGGhaA== + dependencies: + "@types/node" "*" + "@types/qs@*": version "6.9.6" resolved "https://registry.yarnpkg.com/@types/qs/-/qs-6.9.6.tgz#df9c3c8b31a247ec315e6996566be3171df4b3b1" @@ -1871,7 +1878,7 @@ callsites@^3.0.0: resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== -camelcase@^5.3.1: +camelcase@^5.0.0, camelcase@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== @@ -1999,6 +2006,15 @@ cli-width@^3.0.0: resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== +cliui@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1" + integrity sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^6.2.0" + cliui@^7.0.2: version "7.0.4" resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" @@ -2188,6 +2204,11 @@ debug@4, debug@^4.0.0, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.3, d dependencies: ms "2.1.2" +decamelize@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" + integrity sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA== + dedent@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c" @@ -2263,6 +2284,11 @@ diff@^4.0.1: resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== +dijkstrajs@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/dijkstrajs/-/dijkstrajs-1.0.2.tgz#2e48c0d3b825462afe75ab4ad5e829c8ece36257" + integrity sha512-QV6PMaHTCNmKSeP6QoXhVTw9snc9VD8MulTT0Bd99Pacp4SS1cjcrYPgBPmibqKVtMJJfqC6XvOXgPMEEPH/fg== + dir-glob@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f" @@ -2309,6 +2335,11 @@ emoji-regex@^8.0.0: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== +encode-utf8@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/encode-utf8/-/encode-utf8-1.0.3.tgz#f30fdd31da07fb596f281beb2f6b027851994cda" + integrity sha512-ucAnuBEhUK4boH2HjVYG5Q2mQyPorvv0u/ocS+zhdw0S8AlHYY+GOFhP1Gio5z4icpP2ivFSvhtFjQi8+T9ppw== + encodeurl@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" @@ -2876,7 +2907,7 @@ gensync@^1.0.0-beta.2: resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" integrity sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg== -get-caller-file@^2.0.5: +get-caller-file@^2.0.1, get-caller-file@^2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== @@ -4569,6 +4600,11 @@ pluralize@8.0.0: resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1" integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA== +pngjs@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-5.0.0.tgz#e79dd2b215767fd9c04561c01236df960bce7fbb" + integrity sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw== + prelude-ls@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" @@ -4643,6 +4679,16 @@ punycode@^2.1.0: resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== +qrcode@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/qrcode/-/qrcode-1.5.1.tgz#0103f97317409f7bc91772ef30793a54cd59f0cb" + integrity sha512-nS8NJ1Z3md8uTjKtP+SGGhfqmTCs5flU/xR623oI0JX+Wepz9R8UrRVCTBTJm3qGw3rH6jJ6MUHjkDx15cxSSg== + dependencies: + dijkstrajs "^1.0.1" + encode-utf8 "^1.0.3" + pngjs "^5.0.0" + yargs "^15.3.1" + qs@6.9.3: version "6.9.3" resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.3.tgz#bfadcd296c2d549f1dffa560619132c977f5008e" @@ -4744,6 +4790,11 @@ require-from-string@^2.0.2: resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + resolve-cwd@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d" @@ -5707,6 +5758,11 @@ whatwg-url@^5.0.0: tr46 "~0.0.3" webidl-conversions "^3.0.0" +which-module@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" + integrity sha512-B+enWhmw6cjfVC7kS8Pj9pCrKSc5txArRyaYGe088shv/FGWH+0Rjx/xPgtsWfsUtS27FkP697E4DDhgrgoc0Q== + which@^2.0.1, which@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" @@ -5738,6 +5794,15 @@ word-wrap@^1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== +wrap-ansi@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" + integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" @@ -5773,6 +5838,11 @@ xmlbuilder@~11.0.0: resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA== +y18n@^4.0.0: + version "4.0.3" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.3.tgz#b5f259c82cd6e336921efd7bfd8bf560de9eeedf" + integrity sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ== + y18n@^5.0.5: version "5.0.8" resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" @@ -5793,6 +5863,14 @@ yargs-parser@21.0.1, yargs-parser@^21.0.0: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.0.1.tgz#0267f286c877a4f0f728fceb6f8a3e4cb95c6e35" integrity sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg== +yargs-parser@^18.1.2: + version "18.1.3" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.3.tgz#be68c4975c6b2abf469236b0c870362fab09a7b0" + integrity sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^20.2.2: version "20.2.9" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee" @@ -5803,6 +5881,23 @@ yargs-parser@^21.0.1: resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw== +yargs@^15.3.1: + version "15.4.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.4.1.tgz#0d87a16de01aee9d8bec2bfbf74f67851730f4f8" + integrity sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A== + dependencies: + cliui "^6.0.0" + decamelize "^1.2.0" + find-up "^4.1.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^4.2.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^18.1.2" + yargs@^16.0.0: version "16.2.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-16.2.0.tgz#1c82bf0f6b6a66eafce7ef30e376f49a12477f66" From 6ea51cf59344952d565eded950d99bf5659f29ce Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 24 Aug 2022 10:41:56 +0200 Subject: [PATCH 2/6] Added database info for 2fa --- src/entities/index.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/entities/index.ts b/src/entities/index.ts index 244a27d..0529684 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -13,6 +13,12 @@ export enum UserRole { DISABLED = 0 } +export enum tfaTypes { + NONE = 0, + EMAIL = 1, + TOTP = 2 +} + @Entity() export class INode { @PrimaryGeneratedColumn() @@ -59,6 +65,20 @@ export class User { rootId: number; @OneToOne(() => INode) root: Promise; + + @Column({ + type: 'int', + default: tfaTypes.NONE, + transformer: { + from: (db: number): tfaTypes => db, + to: (type: tfaTypes): number => type + } + }) + tfaType: tfaTypes; + + // base32 string + @Column({ nullable: true }) + tfaSecret: string; } @Entity() From 49257736b9fb065f8c698ad167209a1c1a3593a2 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 24 Aug 2022 11:30:54 +0200 Subject: [PATCH 3/6] Added nodemailer for sending mail 2fa https://www.npmjs.com/package/nodemailer --- package.json | 2 ++ yarn.lock | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/package.json b/package.json index 9de26ef..7ece3c8 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@nestjs/typeorm": "^9.0.0", "argon2": "^0.28.7", "jsonwebtoken": "^8.5.1", + "nodemailer": "^6.7.8", "passport": "^0.6.0", "passport-jwt": "^4.0.0", "passport-local": "^1.0.0", @@ -49,6 +50,7 @@ "@types/jest": "^28.1.6", "@types/jsonwebtoken": "^8.5.8", "@types/node": "^18.6.5", + "@types/nodemailer": "^6.4.5", "@types/passport-jwt": "^3.0.6", "@types/passport-local": "^1.0.34", "@types/qrcode": "^1.5.0", diff --git a/yarn.lock b/yarn.lock index e7ee3e5..fd82a06 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1105,6 +1105,13 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.7.11.tgz#486e72cfccde88da24e1f23ff1b7d8bfb64e6250" integrity sha512-KZhFpSLlmK/sdocfSAjqPETTMd0ug6HIMIAwkwUpU79olnZdQtMxpQP+G1wDzCH7na+FltSIhbaZuKdwZ8RDrw== +"@types/nodemailer@^6.4.5": + version "6.4.5" + resolved "https://registry.yarnpkg.com/@types/nodemailer/-/nodemailer-6.4.5.tgz#09011ac73259245475d1688e4ba101860567dc39" + integrity sha512-zuP3nBRQHI6M2PkXnGGy1Ww4VB+MyYHGgnfV2T+JR9KLkeWqPJuyVUgLpKXuFnA/b7pZaIDFh2sV4759B7jK1g== + dependencies: + "@types/node" "*" + "@types/parse-json@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" @@ -4270,6 +4277,11 @@ node-releases@^2.0.5: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.5.tgz#280ed5bc3eba0d96ce44897d8aee478bfb3d9666" integrity sha512-U9h1NLROZTq9uE1SNffn6WuPDg8icmi3ns4rEl/oTfIle4iLjTliCzgTsbaIFMq/Xn078/lfY/BL0GWZ+psK4Q== +nodemailer@^6.7.8: + version "6.7.8" + resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.7.8.tgz#9f1af9911314960c0b889079e1754e8d9e3f740a" + integrity sha512-2zaTFGqZixVmTxpJRCFC+Vk5eGRd/fYtvIR+dl5u9QXLTQWGIf48x/JXvo58g9sa0bU6To04XUv554Paykum3g== + nopt@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/nopt/-/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88" From af1df3e508422e2fff760cbbed0da5085117e9fb Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 24 Aug 2022 14:45:51 +0200 Subject: [PATCH 4/6] Added notp for totp generation https://www.npmjs.com/package/notp --- package.json | 2 ++ yarn.lock | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/package.json b/package.json index 7ece3c8..2114bda 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "argon2": "^0.28.7", "jsonwebtoken": "^8.5.1", "nodemailer": "^6.7.8", + "notp": "^2.0.3", "passport": "^0.6.0", "passport-jwt": "^4.0.0", "passport-local": "^1.0.0", @@ -51,6 +52,7 @@ "@types/jsonwebtoken": "^8.5.8", "@types/node": "^18.6.5", "@types/nodemailer": "^6.4.5", + "@types/notp": "^2.0.2", "@types/passport-jwt": "^3.0.6", "@types/passport-local": "^1.0.34", "@types/qrcode": "^1.5.0", diff --git a/yarn.lock b/yarn.lock index fd82a06..9710316 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1112,6 +1112,13 @@ dependencies: "@types/node" "*" +"@types/notp@^2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@types/notp/-/notp-2.0.2.tgz#7283f4918b2770555e0f2df72acc9f46ebd41ae9" + integrity sha512-JUcVYN9Tmw0AjoAfvjslS4hbv39fPBbZdftBK3b50g5z/DmhLsu6cd0UOEBiQuMwy2FirshF2Gk9gAvfWjshMw== + dependencies: + "@types/node" "*" + "@types/parse-json@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0" @@ -4294,6 +4301,11 @@ normalize-path@^3.0.0, normalize-path@~3.0.0: resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== +notp@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/notp/-/notp-2.0.3.tgz#a9fd11e25cfe1ccb39fc6689544ee4c10ef9a577" + integrity sha512-oBig/2uqkjQ5AkBuw4QJYwkEWa/q+zHxI5/I5z6IeP2NT0alpJFsP/trrfCC+9xOAgQSZXssNi962kp5KBmypQ== + npm-run-path@^4.0.0, npm-run-path@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea" From cd0d25ba4f77e24f1da22c6aeb851e47826d60a1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 24 Aug 2022 16:15:33 +0200 Subject: [PATCH 5/6] Added totp/mail otp, split up dto and api into multiple files --- dto/index.ts | 75 +----- dto/requests/auth.ts | 10 + dto/requests/base.ts | 2 + dto/requests/fs.ts | 12 + dto/requests/index.ts | 3 + dto/responses/auth.ts | 19 ++ dto/responses/base.ts | 12 + dto/responses/fs.ts | 30 +++ dto/responses/index.ts | 3 + frontend/src/App.vue | 4 +- frontend/src/api.ts | 221 ------------------ frontend/src/api/auth.ts | 30 +++ frontend/src/api/base.ts | 63 +++++ frontend/src/api/fs.ts | 95 ++++++++ frontend/src/api/index.ts | 4 + frontend/src/api/util.ts | 25 ++ frontend/src/components/FSView/DirEntry.vue | 14 +- frontend/src/components/FSView/DirViewer.vue | 21 +- frontend/src/components/FSView/FileViewer.vue | 14 +- .../components/UploadDialog/UploadEntry.vue | 4 +- frontend/src/views/FSView.vue | 14 +- frontend/src/views/HomeView.vue | 4 +- frontend/src/views/LoginView.vue | 32 ++- frontend/src/views/SignupView.vue | 4 +- package.json | 1 + src/controller/auth.ts | 90 ++++++- src/controller/filesystem.ts | 26 +-- src/entities/index.ts | 1 - src/services/auth.ts | 76 +++++- yarn.lock | 5 + 30 files changed, 535 insertions(+), 379 deletions(-) create mode 100644 dto/requests/auth.ts create mode 100644 dto/requests/base.ts create mode 100644 dto/requests/fs.ts create mode 100644 dto/requests/index.ts create mode 100644 dto/responses/auth.ts create mode 100644 dto/responses/base.ts create mode 100644 dto/responses/fs.ts create mode 100644 dto/responses/index.ts delete mode 100644 frontend/src/api.ts create mode 100644 frontend/src/api/auth.ts create mode 100644 frontend/src/api/base.ts create mode 100644 frontend/src/api/fs.ts create mode 100644 frontend/src/api/index.ts create mode 100644 frontend/src/api/util.ts diff --git a/dto/index.ts b/dto/index.ts index f7b0a1d..22f24bf 100644 --- a/dto/index.ts +++ b/dto/index.ts @@ -1,73 +1,2 @@ -// -// Responses -// - -export interface BaseResponse { - statusCode: number; -} - -export interface ErrorResponse extends BaseResponse { - statusCode: 400 | 401 | 403; - message?: string; -} - -export type RefreshResponse = LoginResponse; -export interface LoginResponse extends BaseResponse { - statusCode: 200; - jwt: string; -} - -export interface GetRootResponse extends BaseResponse { - statusCode: 200; - rootId: number; -} - -export interface GetNodeResponse extends BaseResponse { - statusCode: 200; - id: number; - name: string; - isFile: boolean; - parent: number | null; - children?: number[]; - size?: number; -} - -export interface GetPathResponse extends BaseResponse { - statusCode: 200; - path: string; -} - -export type CreateFileResponse = CreateFolderResponse; -export interface CreateFolderResponse extends BaseResponse { - statusCode: 200; - id: number; -} - -export type SignupResponse = DeleteResponse; -export type UploadFileResponse = DeleteResponse; -export interface DeleteResponse extends BaseResponse { - statusCode: 200; -} - -// -// Requests -// - -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface BaseRequest {} - -export type AuthSignUpRequest = AuthLoginRequest; -export interface AuthLoginRequest extends BaseRequest { - username: string; - password: string; -} - -export type CreateFileRequest = CreateFolderRequest; -export interface CreateFolderRequest extends BaseRequest { - parent: number; - name: string; -} - -export interface DeleteRequest extends BaseRequest { - node: number; -} +export * as Requests from './requests'; +export * as Responses from './responses'; diff --git a/dto/requests/auth.ts b/dto/requests/auth.ts new file mode 100644 index 0000000..ea1e6f7 --- /dev/null +++ b/dto/requests/auth.ts @@ -0,0 +1,10 @@ +import { BaseRequest } from './base'; + +export interface AuthSignUpRequest extends BaseRequest { + username: string; + password: string; +} + +export interface AuthLoginRequest extends AuthSignUpRequest { + otp?: string; +} diff --git a/dto/requests/base.ts b/dto/requests/base.ts new file mode 100644 index 0000000..9d6341d --- /dev/null +++ b/dto/requests/base.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface BaseRequest {} diff --git a/dto/requests/fs.ts b/dto/requests/fs.ts new file mode 100644 index 0000000..5cd1d06 --- /dev/null +++ b/dto/requests/fs.ts @@ -0,0 +1,12 @@ +import { BaseRequest } from './base'; + +export type CreateFileRequest = CreateFolderRequest; + +export interface CreateFolderRequest extends BaseRequest { + parent: number; + name: string; +} + +export interface DeleteRequest extends BaseRequest { + node: number; +} diff --git a/dto/requests/index.ts b/dto/requests/index.ts new file mode 100644 index 0000000..8f26264 --- /dev/null +++ b/dto/requests/index.ts @@ -0,0 +1,3 @@ +export * from './base'; +export * as Auth from './auth'; +export * as FS from './fs'; diff --git a/dto/responses/auth.ts b/dto/responses/auth.ts new file mode 100644 index 0000000..545a065 --- /dev/null +++ b/dto/responses/auth.ts @@ -0,0 +1,19 @@ +import { BaseResponse, SuccessResponse } from './base'; + +export type TfaRequiredResponse = SuccessResponse; +export type RemoveTfaResponse = SuccessResponse; +export type RequestEmailTfaResponse = SuccessResponse; +export type TfaCompletedResponse = SuccessResponse; +export type SignupResponse = SuccessResponse; +export type RefreshResponse = LoginResponse; + +export interface LoginResponse extends BaseResponse { + statusCode: 200; + jwt: string; +} + +export interface RequestTotpTfaResponse extends BaseResponse { + statusCode: 200; + qrCode: string; + secret: string; +} diff --git a/dto/responses/base.ts b/dto/responses/base.ts new file mode 100644 index 0000000..ce059ce --- /dev/null +++ b/dto/responses/base.ts @@ -0,0 +1,12 @@ +export interface BaseResponse { + statusCode: number; +} + +export interface SuccessResponse extends BaseResponse { + statusCode: 200; +} + +export interface ErrorResponse extends BaseResponse { + statusCode: 400 | 401 | 403; + message?: string; +} diff --git a/dto/responses/fs.ts b/dto/responses/fs.ts new file mode 100644 index 0000000..8432548 --- /dev/null +++ b/dto/responses/fs.ts @@ -0,0 +1,30 @@ +import { BaseResponse, SuccessResponse } from './base'; + +export type UploadFileResponse = SuccessResponse; +export type DeleteResponse = SuccessResponse; +export type CreateFileResponse = CreateFolderResponse; + +export interface GetRootResponse extends BaseResponse { + statusCode: 200; + rootId: number; +} + +export interface GetNodeResponse extends BaseResponse { + statusCode: 200; + id: number; + name: string; + isFile: boolean; + parent: number | null; + children?: number[]; + size?: number; +} + +export interface GetPathResponse extends BaseResponse { + statusCode: 200; + path: string; +} + +export interface CreateFolderResponse extends BaseResponse { + statusCode: 200; + id: number; +} diff --git a/dto/responses/index.ts b/dto/responses/index.ts new file mode 100644 index 0000000..8f26264 --- /dev/null +++ b/dto/responses/index.ts @@ -0,0 +1,3 @@ +export * from './base'; +export * as Auth from './auth'; +export * as FS from './fs'; diff --git a/frontend/src/App.vue b/frontend/src/App.vue index f5cd54d..60c8577 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,7 +1,7 @@ diff --git a/frontend/src/components/FSView/DirViewer.vue b/frontend/src/components/FSView/DirViewer.vue index d2164c9..d77fc14 100644 --- a/frontend/src/components/FSView/DirViewer.vue +++ b/frontend/src/components/FSView/DirViewer.vue @@ -1,18 +1,12 @@ diff --git a/frontend/src/components/UploadDialog/UploadEntry.vue b/frontend/src/components/UploadDialog/UploadEntry.vue index 3f857b1..392e0e9 100644 --- a/frontend/src/components/UploadDialog/UploadEntry.vue +++ b/frontend/src/components/UploadDialog/UploadEntry.vue @@ -1,6 +1,6 @@ diff --git a/frontend/src/views/SignupView.vue b/frontend/src/views/SignupView.vue index 481ff0c..438ef63 100644 --- a/frontend/src/views/SignupView.vue +++ b/frontend/src/views/SignupView.vue @@ -1,6 +1,6 @@