free-be-account 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -13
- package/package.json +5 -5
- package/sms/index.js +7 -4
package/index.js
CHANGED
|
@@ -1121,18 +1121,20 @@ module.exports = (app) => ({
|
|
|
1121
1121
|
const phone = crypto.encoder.desDecode(req.body.PhoneNumber, m.config.desKey);
|
|
1122
1122
|
|
|
1123
1123
|
// check user existance if necessary
|
|
1124
|
-
|
|
1125
|
-
{
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1124
|
+
if (req.body.exists !== 'all') {
|
|
1125
|
+
const existsCount = await res.app.models.account.countDocuments({$or: [
|
|
1126
|
+
{ PhoneNumber: phone },
|
|
1127
|
+
{ 'Profile.Email': phone },
|
|
1128
|
+
]});
|
|
1129
|
+
|
|
1130
|
+
if (req.body.exists && existsCount <= 0) {
|
|
1131
|
+
res.makeError(409, 'User not exists!', m);
|
|
1132
|
+
return next('route');
|
|
1133
|
+
}
|
|
1134
|
+
if (!req.body.exists && existsCount > 0) {
|
|
1135
|
+
res.makeError(410, 'User aleady exists!', m);
|
|
1136
|
+
return next('route');
|
|
1137
|
+
}
|
|
1136
1138
|
}
|
|
1137
1139
|
|
|
1138
1140
|
const result = await m.sms.sendRandom(phone, undefined, true, req.body.smsTemp || 'register');
|
|
@@ -1142,7 +1144,7 @@ module.exports = (app) => ({
|
|
|
1142
1144
|
return next('route');
|
|
1143
1145
|
}
|
|
1144
1146
|
} catch (ex) {
|
|
1145
|
-
res.makeError(
|
|
1147
|
+
res.makeError(502, ex.message || 'Failed to send sms!', m);
|
|
1146
1148
|
return next('route');
|
|
1147
1149
|
}
|
|
1148
1150
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "free-be-account",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@alicloud/pop-core": "^1.7.12",
|
|
12
|
-
"axios": "^1.3.
|
|
13
|
-
"bcrypt": "^5.0
|
|
12
|
+
"axios": "^1.3.5",
|
|
13
|
+
"bcrypt": "^5.1.0",
|
|
14
14
|
"crypto-js": "^4.1.1",
|
|
15
15
|
"js-md5": "^0.7.3",
|
|
16
16
|
"nodemailer": "^6.9.1",
|
|
17
|
-
"passport": "^0.
|
|
17
|
+
"passport": "^0.6.0",
|
|
18
18
|
"passport-local": "^1.0.0",
|
|
19
19
|
"svg-captcha": "^1.4.0",
|
|
20
|
-
"uuid": "^
|
|
20
|
+
"uuid": "^9.0.0"
|
|
21
21
|
}
|
|
22
22
|
}
|
package/sms/index.js
CHANGED
|
@@ -5,8 +5,8 @@ const nodemailer = require('nodemailer');
|
|
|
5
5
|
|
|
6
6
|
let global;
|
|
7
7
|
|
|
8
|
-
if (fs.existsSync(path.resolve(__dirname, '
|
|
9
|
-
global = require('
|
|
8
|
+
if (fs.existsSync(path.resolve(__dirname, '../../../global.js'))) {
|
|
9
|
+
global = require('../../../global');
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
let MAIL_TRANS = undefined;
|
|
@@ -132,10 +132,12 @@ module.exports = (app) => ({
|
|
|
132
132
|
const keys = (global && global.sms && global.sms[t]) || app.modules.account.config.sms.keys[t] || app.modules.account.config.sms.keys;
|
|
133
133
|
|
|
134
134
|
if (keys.platform) {
|
|
135
|
-
//
|
|
136
|
-
|
|
135
|
+
// should not send too frequent!
|
|
136
|
+
const lastSentTime = await app.cache.get(`${p}_lastSentTime`);
|
|
137
|
+
if (lastSentTime && (Date.now() - lastSentTime) < (keys.resentGap || (60 * 1000))) {
|
|
137
138
|
throw new Error('Cannot send too frequently!');
|
|
138
139
|
}
|
|
140
|
+
|
|
139
141
|
if (_sms_lib[keys.platform]) {
|
|
140
142
|
let sent = true;
|
|
141
143
|
const v = keys.fixedCode || value;
|
|
@@ -150,6 +152,7 @@ module.exports = (app) => ({
|
|
|
150
152
|
if (c) {
|
|
151
153
|
const cTime = keys.cacheTime || (5 * 60 * 1000)
|
|
152
154
|
await app.cache.put(p, v, cTime);
|
|
155
|
+
await app.cache.put(`${p}_lastSentTime`, Date.now(), cTime);
|
|
153
156
|
}
|
|
154
157
|
return true;
|
|
155
158
|
} else {
|