From 4bcd5120c93c8c6ce5002502975f58b9a717fa4a Mon Sep 17 00:00:00 2001 From: zboss <2628716267@qq.com> Date: Fri, 7 Jun 2024 21:23:18 +0800 Subject: [PATCH] znl --- model/znl.js | 17 ++- package-lock.json | 368 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 3 +- routes/znl.js | 173 +++++++++++++++++----- 4 files changed, 516 insertions(+), 45 deletions(-) diff --git a/model/znl.js b/model/znl.js index 2a5b78d..0272a54 100644 --- a/model/znl.js +++ b/model/znl.js @@ -86,12 +86,21 @@ const UserInfoSchema = new Schema({ status: { type: String }, permissions: [{ type: Schema.Types.ObjectId, ref: 'Permission' }] }); -const Permission = mongoose.model('db_permission', PermissionSchema,'db_permission') -const Role = mongoose.model('db_role', RoleSchema,'db_role') -const UserInfo = mongoose.model('db_user', UserInfoSchema,'db_user') +//验证码存储 +const VerificationCodeSchema = new Schema({ + phone: { type: String, required: true }, + code: { type: Number, required: true }, + time: { type: Date, required: true }, + status: { type: Boolean, default: false } +}); +const Permission = mongoose.model('db_permission', PermissionSchema, 'db_permission') +const Role = mongoose.model('db_role', RoleSchema, 'db_role') +const UserInfo = mongoose.model('db_user', UserInfoSchema, 'db_user') +const VerificationCode = mongoose.model('db_verification', VerificationCodeSchema, 'db_verification') module.exports = { Permission, Role, - UserInfo + UserInfo, + VerificationCode }; diff --git a/package-lock.json b/package-lock.json index b32a8a3..a181e8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,8 @@ "jsonwebtoken": "^9.0.2", "mongoose": "^8.4.0", "morgan": "~1.9.1", - "socket.io": "^4.7.5" + "socket.io": "^4.7.5", + "tencentcloud-sdk-nodejs": "^4.0.870" } }, "node_modules/@mongodb-js/saslprep": { @@ -98,6 +99,38 @@ "acorn": "^2.1.0" } }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmmirror.com/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/agent-base/node_modules/debug": { + "version": "4.3.5", + "resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/agent-base/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "node_modules/align-text": { "version": "0.1.4", "resolved": "https://registry.npmmirror.com/align-text/-/align-text-0.1.4.tgz", @@ -129,6 +162,11 @@ "resolved": "https://registry.npmmirror.com/asap/-/asap-1.0.0.tgz", "integrity": "sha512-Ej9qjcXY+8Tuy1cNqiwNMwFRXOy9UwgTeMA8LxreodygIPV48lx8PU1ecFxb5ZeU1DpMKxiq6vGLTxcitWZPbA==" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "node_modules/base64id": { "version": "2.0.0", "resolved": "https://registry.npmmirror.com/base64id/-/base64id-2.0.0.tgz", @@ -148,6 +186,14 @@ "node": ">= 0.8" } }, + "node_modules/bignumber.js": { + "version": "9.1.2", + "resolved": "https://registry.npmmirror.com/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", + "engines": { + "node": "*" + } + }, "node_modules/body-parser": { "version": "1.18.3", "resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.18.3.tgz", @@ -258,6 +304,17 @@ "node": ">=0.4.0" } }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "2.6.0", "resolved": "https://registry.npmmirror.com/commander/-/commander-2.6.0.tgz", @@ -363,6 +420,14 @@ "node": ">=0.10.0" } }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmmirror.com/depd/-/depd-1.1.2.tgz", @@ -524,6 +589,19 @@ "node": ">= 0.8" } }, + "node_modules/form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz", @@ -540,6 +618,17 @@ "node": ">= 0.6" } }, + "node_modules/get-stream": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/graceful-readlink": { "version": "1.0.1", "resolved": "https://registry.npmmirror.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz", @@ -559,6 +648,39 @@ "node": ">= 0.6" } }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/https-proxy-agent/node_modules/debug": { + "version": "4.3.5", + "resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/https-proxy-agent/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "node_modules/iconv-lite": { "version": "0.4.23", "resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.23.tgz", @@ -593,6 +715,17 @@ "resolved": "https://registry.npmmirror.com/is-promise/-/is-promise-2.2.2.tgz", "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" }, + "node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/jade": { "version": "1.11.0", "resolved": "https://registry.npmmirror.com/jade/-/jade-1.11.0.tgz", @@ -614,6 +747,14 @@ "jade": "bin/jade.js" } }, + "node_modules/json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "dependencies": { + "bignumber.js": "^9.0.0" + } + }, "node_modules/jsonwebtoken": { "version": "9.0.2", "resolved": "https://registry.npmmirror.com/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", @@ -958,6 +1099,44 @@ "node": ">= 0.6" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/node-fetch/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmmirror.com/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/node-fetch/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/node-fetch/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmmirror.com/object-assign/-/object-assign-4.1.1.tgz", @@ -1279,6 +1458,24 @@ "node": ">= 0.6" } }, + "node_modules/tencentcloud-sdk-nodejs": { + "version": "4.0.870", + "resolved": "https://registry.npmmirror.com/tencentcloud-sdk-nodejs/-/tencentcloud-sdk-nodejs-4.0.870.tgz", + "integrity": "sha512-nvTFasYkHFGTuqO3W8xgKcpwIs3hAVrS0M8O2a/h02KmIPvzWz/tAjDF1/b/hFuVTYp/CnIznBZNC41TZZPfsw==", + "dependencies": { + "form-data": "^3.0.0", + "get-stream": "^6.0.0", + "https-proxy-agent": "^5.0.0", + "is-stream": "^2.0.0", + "json-bigint": "^1.0.0", + "node-fetch": "^2.2.0", + "tslib": "1.13.0", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/tr46": { "version": "4.1.1", "resolved": "https://registry.npmmirror.com/tr46/-/tr46-4.1.1.tgz", @@ -1340,6 +1537,11 @@ "node": ">=0.4.0" } }, + "node_modules/tslib": { + "version": "1.13.0", + "resolved": "https://registry.npmmirror.com/tslib/-/tslib-1.13.0.tgz", + "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==" + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmmirror.com/type-is/-/type-is-1.6.18.tgz", @@ -1405,6 +1607,18 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmmirror.com/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz", @@ -1579,6 +1793,29 @@ "acorn": "^2.1.0" } }, + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmmirror.com/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "requires": { + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.3.5", + "resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, "align-text": { "version": "0.1.4", "resolved": "https://registry.npmmirror.com/align-text/-/align-text-0.1.4.tgz", @@ -1604,6 +1841,11 @@ "resolved": "https://registry.npmmirror.com/asap/-/asap-1.0.0.tgz", "integrity": "sha512-Ej9qjcXY+8Tuy1cNqiwNMwFRXOy9UwgTeMA8LxreodygIPV48lx8PU1ecFxb5ZeU1DpMKxiq6vGLTxcitWZPbA==" }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, "base64id": { "version": "2.0.0", "resolved": "https://registry.npmmirror.com/base64id/-/base64id-2.0.0.tgz", @@ -1617,6 +1859,11 @@ "safe-buffer": "5.1.2" } }, + "bignumber.js": { + "version": "9.1.2", + "resolved": "https://registry.npmmirror.com/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==" + }, "body-parser": { "version": "1.18.3", "resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.18.3.tgz", @@ -1704,6 +1951,14 @@ } } }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmmirror.com/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "2.6.0", "resolved": "https://registry.npmmirror.com/commander/-/commander-2.6.0.tgz", @@ -1787,6 +2042,11 @@ "resolved": "https://registry.npmmirror.com/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==" }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==" + }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmmirror.com/depd/-/depd-1.1.2.tgz", @@ -1920,6 +2180,16 @@ "unpipe": "~1.0.0" } }, + "form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "forwarded": { "version": "0.2.0", "resolved": "https://registry.npmmirror.com/forwarded/-/forwarded-0.2.0.tgz", @@ -1930,6 +2200,11 @@ "resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz", "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==" }, + "get-stream": { + "version": "6.0.1", + "resolved": "https://registry.npmmirror.com/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==" + }, "graceful-readlink": { "version": "1.0.1", "resolved": "https://registry.npmmirror.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz", @@ -1946,6 +2221,30 @@ "statuses": ">= 1.4.0 < 2" } }, + "https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmmirror.com/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "requires": { + "agent-base": "6", + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.3.5", + "resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.5.tgz", + "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + } + } + }, "iconv-lite": { "version": "0.4.23", "resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.23.tgz", @@ -1974,6 +2273,11 @@ "resolved": "https://registry.npmmirror.com/is-promise/-/is-promise-2.2.2.tgz", "integrity": "sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==" }, + "is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==" + }, "jade": { "version": "1.11.0", "resolved": "https://registry.npmmirror.com/jade/-/jade-1.11.0.tgz", @@ -1991,6 +2295,14 @@ "with": "~4.0.0" } }, + "json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmmirror.com/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "requires": { + "bignumber.js": "^9.0.0" + } + }, "jsonwebtoken": { "version": "9.0.2", "resolved": "https://registry.npmmirror.com/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", @@ -2242,6 +2554,35 @@ "resolved": "https://registry.npmmirror.com/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, + "node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmmirror.com/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "requires": { + "whatwg-url": "^5.0.0" + }, + "dependencies": { + "tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmmirror.com/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmmirror.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmmirror.com/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "requires": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + } + } + }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmmirror.com/object-assign/-/object-assign-4.1.1.tgz", @@ -2488,6 +2829,21 @@ "resolved": "https://registry.npmmirror.com/statuses/-/statuses-1.4.0.tgz", "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" }, + "tencentcloud-sdk-nodejs": { + "version": "4.0.870", + "resolved": "https://registry.npmmirror.com/tencentcloud-sdk-nodejs/-/tencentcloud-sdk-nodejs-4.0.870.tgz", + "integrity": "sha512-nvTFasYkHFGTuqO3W8xgKcpwIs3hAVrS0M8O2a/h02KmIPvzWz/tAjDF1/b/hFuVTYp/CnIznBZNC41TZZPfsw==", + "requires": { + "form-data": "^3.0.0", + "get-stream": "^6.0.0", + "https-proxy-agent": "^5.0.0", + "is-stream": "^2.0.0", + "json-bigint": "^1.0.0", + "node-fetch": "^2.2.0", + "tslib": "1.13.0", + "uuid": "^9.0.1" + } + }, "tr46": { "version": "4.1.1", "resolved": "https://registry.npmmirror.com/tr46/-/tr46-4.1.1.tgz", @@ -2538,6 +2894,11 @@ } } }, + "tslib": { + "version": "1.13.0", + "resolved": "https://registry.npmmirror.com/tslib/-/tslib-1.13.0.tgz", + "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==" + }, "type-is": { "version": "1.6.18", "resolved": "https://registry.npmmirror.com/type-is/-/type-is-1.6.18.tgz", @@ -2585,6 +2946,11 @@ "resolved": "https://registry.npmmirror.com/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, + "uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmmirror.com/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==" + }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmmirror.com/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 0cc73b7..e16e90e 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "jsonwebtoken": "^9.0.2", "mongoose": "^8.4.0", "morgan": "~1.9.1", - "socket.io": "^4.7.5" + "socket.io": "^4.7.5", + "tencentcloud-sdk-nodejs": "^4.0.870" } } diff --git a/routes/znl.js b/routes/znl.js index aed88cb..2646327 100644 --- a/routes/znl.js +++ b/routes/znl.js @@ -1,7 +1,8 @@ const express = require('express'); const router = express.Router(); -const { UserModel, NavModel } = require('../model/znl'); +const { UserModel, NavModel, VerificationCode } = require('../model/znl'); const jwt = require('jsonwebtoken'); +const tencentcloud = require('tencentcloud-sdk-nodejs') const SECRET = 'ice'; // 生成Token的函数 @@ -62,26 +63,6 @@ router.post('/refresh', (req, res) => { } }); -// 注册接口 -router.post('/register', async (req, res) => { - let { username, password } = req.body; - const userInfo = await UserModel.find({ username }); - if (userInfo.length) { - res.send({ - status: 0, - message: '用户名已存在' - }); - } else { - const user = new UserModel({ username, password }); - await user.save(); - res.send({ - status: 0, - message: '注册成功', - data: user - }); - } -}); - // 获取导航数据接口 router.get('/getNav', async (req, res) => { let data = await NavModel.find().lean(); @@ -107,25 +88,139 @@ router.get('/getNav', async (req, res) => { }); }); -router.get('/getAll',async (req,res)=>{ +router.get('/getAll', async (req, res) => { let userId = req.body await UserInfo.findOne({ _id: userId }) - .populate('role') - .populate({ - path: 'permissions', - model: 'Permission', - populate: { - path: 'children', - model: 'Permission' - } + .populate('role') + .populate({ + path: 'permissions', + model: 'Permission', + populate: { + path: 'children', + model: 'Permission' + } + }) + .exec((err, user) => { + if (err) { + console.error(err); + return; + } + // `user`现在包含了完整的信息,包括其角色和所有权限 + console.log(user); + }); +}) +//注册接口 +router.post('/register', async (req, res) => { + let { phone, password, code } = req.body; + const userInfo = await UserModel.find({ username }); + if (userInfo.length) { + return res.send({ + status: 0, + message: '用户名已存在' + }); + } else { + const { time } = await VerificationCode.find({ phone }); + if (code == captchaTemp && phoneTemp == phone && Date.now() < time) { + await UserModel.create({ username: phone, password }); + return res.send({ + status: 0, + message: '注册成功', + }); + } else { + return res.send({ + status: 0, + message: '验证码错误' + }); + } + } +}) +//重置密码接口 +router.post('/resetPassword', async (req, res) => { + let { phone, password } = req.body; + const userInfo = await UserModel.find({ username: phone }); + if (userInfo.length) { + res.send({ + status: 0, + message: '用户名不存在' + }); + } else { + await UserModel.updateOne(username, { password: password }); + res.send({ + status: 0, + message: '重置成功', + }); + } +}) + +let captchaTemp = '' +let phoneTemp = '' + +//获取腾讯短信验证码 +const smsClient = tencentcloud.sms.v20210111.Client +const client = new smsClient({ + credential: { + /* 必填:腾讯云账户密钥对secretId,secretKey。 */ + secretId: 'AKIDLoKoBCRgyMj4a2U8naSI0Y6fVN6wrqrr', + secretKey: 'BRMEvfdZOExjfYXarLtV910uxALfwAUu' + }, + region: 'ap-beijing', + profile: { + signMethod: 'HmacSHA256', + httpProfile: { + reqMethod: 'POST', + reqTimeout: 30, + endpoint: 'sms.tencentcloudapi.com' + }, + }, +}) + +const params = { + SmsSdkAppId: '1400864231', + SignName: 'Come二水公众号', + TemplateId: '2023700', + TemplateParamSet: ['1'], + PhoneNumberSet: ['要发送的手机号'], +}; +//保存发出的验证码 +async function saveSvg(phone, code) { + const expirationTimeInSeconds = 300; // 假设验证码有效期为5分钟 + const expirationTime = Date.now() + expirationTimeInSeconds * 1000; + // console.log(1); + + const verificode = await VerificationCode.create({ + phone: phone, + code: code, + time: expirationTime, // 设置过期时间为当前时间加上有效期(以毫秒为单位) }) - .exec((err, user) => { - if (err) { - console.error(err); - return; - } - // `user`现在包含了完整的信息,包括其角色和所有权限 - console.log(user); - }); - }) + return verificode; +} +router.post('/getSvg', async (req, res) => { + const { phone } = req.body; + captchaTemp = '' + for (let i = 0; i < 6; i++) { + captchaTemp += String(Math.ceil(Math.random() * 9)) + } + params.TemplateParamSet[0] = captchaTemp + params.PhoneNumberSet = [phone] + console.log(params.PhoneNumberSet); + // 设置定时器,在一分钟后清除验证码变量 + setTimeout(() => { + captchaTemp = '' + }, 30000) + //发送请求 + // console.log('params',params); + client.SendSms(params, function (err, response) { + // 请求异常返回,打印异常信息 + if (err) { + return res.json({ success: false, message: "验证码发送失败", error: err }); + } + // 请求正常返回,打印response对象 + // console.log(response) + saveSvg(phoneTemp, captchaTemp) + .then((newCode) => console.log('验证码储存成功:')) + .catch((err) => console.error('验证码储存失败:', err)); + 返回前端验证码 + res.json({ status: 0, message: "验证码发送成功", data: captchaTemp }); + }) +}) module.exports = router; -- Gitee