free-be-account 0.0.16 → 0.0.17
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 +79 -12
- package/package-lock.json +1539 -0
- package/package.json +11 -6
- package/routers/mgmt/route.js +3 -0
- package/routers/uc/info/route.js +5 -5
- package/routers/uc/noty/index.js +4 -0
- package/routers/uc/noty/route.js +61 -0
- package/sms/index.js +10 -4
package/index.js
CHANGED
|
@@ -7,12 +7,23 @@ var svgCaptcha = require('svg-captcha');
|
|
|
7
7
|
const passport = require('passport');
|
|
8
8
|
const LocalStrategy = require('passport-local').Strategy;
|
|
9
9
|
const {v1: uuidv1} = require('uuid');
|
|
10
|
+
const RedisStore = require("connect-redis").default;
|
|
11
|
+
const session = require("express-session");
|
|
12
|
+
|
|
10
13
|
const crypto = require("./crypto");
|
|
11
14
|
const { clearPermission, getPermissionPathList, verifyPassword, encryptPwd } = require('./utils');
|
|
12
15
|
const { AccountAuditStatus } = require('./enum');
|
|
13
16
|
const sms = require('./sms');
|
|
14
17
|
const wx = require('./platforms/wx/index');
|
|
15
18
|
|
|
19
|
+
const eis = {};
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
Object.assign(eis, require('../../global.js').eis);
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.log('No global eis found!');
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
let __app_service_list_saved = false;
|
|
17
28
|
let __saved_service_list;
|
|
18
29
|
|
|
@@ -320,12 +331,19 @@ module.exports = (app) => ({
|
|
|
320
331
|
Label: '邮箱',
|
|
321
332
|
Name: 'Profile.Email',
|
|
322
333
|
Index: 3,
|
|
334
|
+
Rules: ['validatorEmail'],
|
|
323
335
|
},
|
|
324
336
|
{
|
|
325
337
|
Type: 'String',
|
|
326
338
|
Label: '职务',
|
|
327
339
|
Name: 'Profile.Title',
|
|
328
340
|
Index: 4,
|
|
341
|
+
Rules: ['validatorOnlyCC'],
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
Name: 'Profile.Avatar',
|
|
345
|
+
Type: 'Image',
|
|
346
|
+
Label: '头像',
|
|
329
347
|
},
|
|
330
348
|
],
|
|
331
349
|
},
|
|
@@ -404,6 +422,14 @@ module.exports = (app) => ({
|
|
|
404
422
|
// label could be nagtive, means a user with it will DO NOT has it's permissions
|
|
405
423
|
Negative: { type: 'Boolean', default: false },
|
|
406
424
|
},
|
|
425
|
+
|
|
426
|
+
system_notification: {
|
|
427
|
+
User: { type: 'String', refer: 'account' },
|
|
428
|
+
Title: { type: 'String', required: true },
|
|
429
|
+
Content: { type: 'String' },
|
|
430
|
+
Read: { type: 'Boolean', default: false },
|
|
431
|
+
Category: { type: 'String' },
|
|
432
|
+
},
|
|
407
433
|
},
|
|
408
434
|
utils: {
|
|
409
435
|
verify_api_permission,
|
|
@@ -855,12 +881,16 @@ module.exports = (app) => ({
|
|
|
855
881
|
{
|
|
856
882
|
// 'Profile.WxOpenId': wxResult.openid,
|
|
857
883
|
...openidFilter,
|
|
858
|
-
Enabled: true,
|
|
859
|
-
Deleted: false,
|
|
884
|
+
// Enabled: true,
|
|
885
|
+
// Deleted: false,
|
|
860
886
|
}).then((user) => {
|
|
861
887
|
if (user) {
|
|
862
|
-
user.
|
|
863
|
-
|
|
888
|
+
if (!user.Enabled || user.Deleted) {
|
|
889
|
+
done(null, false);
|
|
890
|
+
} else {
|
|
891
|
+
user.isWx = true;
|
|
892
|
+
done(null, user);
|
|
893
|
+
}
|
|
864
894
|
} else {
|
|
865
895
|
// create new
|
|
866
896
|
const profile = {};
|
|
@@ -900,12 +930,12 @@ module.exports = (app) => ({
|
|
|
900
930
|
{
|
|
901
931
|
$or: [{ PhoneNumber: username }, { UserName: username }],
|
|
902
932
|
// Password: password,
|
|
903
|
-
Enabled: true,
|
|
904
|
-
Deleted: false,
|
|
933
|
+
// Enabled: true,
|
|
934
|
+
// Deleted: false,
|
|
905
935
|
}).then(async (user) => {
|
|
906
936
|
if (!user) {
|
|
907
937
|
// auto create new user
|
|
908
|
-
if (m.config.autoCreateNewUser) {
|
|
938
|
+
if (m.config.autoCreateNewUser && await app.modules['account'].verify(username, password)) {
|
|
909
939
|
const valid_phone = (d) => {
|
|
910
940
|
return /^(0|86|17951)?(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])[0-9]{8}$/.test(d);
|
|
911
941
|
};
|
|
@@ -941,10 +971,14 @@ module.exports = (app) => ({
|
|
|
941
971
|
}
|
|
942
972
|
}
|
|
943
973
|
|
|
974
|
+
if (!user.Enabled || user.Deleted) {
|
|
975
|
+
return done(null, false);
|
|
976
|
+
}
|
|
977
|
+
|
|
944
978
|
const pwdVerified = verifyPassword(password, user.Password, m.config.pwdEncryptMethod || 'md5');
|
|
945
979
|
|
|
946
|
-
return Promise.resolve(app.
|
|
947
|
-
if (!pwdVerified && cachePwd
|
|
980
|
+
return Promise.resolve(app.modules['sms'].verify(username, cachePwd)).then((cachePwd) => {
|
|
981
|
+
if (!pwdVerified && !cachePwd) {
|
|
948
982
|
return done(null, false);
|
|
949
983
|
} else {
|
|
950
984
|
return done(null, user);
|
|
@@ -1118,7 +1152,11 @@ module.exports = (app) => ({
|
|
|
1118
1152
|
let access_token = req.cookies.token || req.header('Authorization');
|
|
1119
1153
|
|
|
1120
1154
|
// call logout of the passport
|
|
1121
|
-
req.logout(() => {
|
|
1155
|
+
req.logout((err) => {
|
|
1156
|
+
if (err) {
|
|
1157
|
+
app.logger.error(err.message || err);
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1122
1160
|
|
|
1123
1161
|
// clear the cached token
|
|
1124
1162
|
res.clearCookie('token');
|
|
@@ -1207,7 +1245,7 @@ module.exports = (app) => ({
|
|
|
1207
1245
|
return next('route');
|
|
1208
1246
|
}
|
|
1209
1247
|
const phone = crypto.encoder.desDecode(req.body.PhoneNumber, m.config.desKey);
|
|
1210
|
-
const result = await m.sms.verify(phone, req.body.code);
|
|
1248
|
+
const result = await m.sms.verify(phone, req.body.code, req.body.delete === false ? false : true);
|
|
1211
1249
|
// app.logger.debug(cache.exportJson());
|
|
1212
1250
|
|
|
1213
1251
|
if (!result) {
|
|
@@ -1496,6 +1534,35 @@ module.exports = (app) => ({
|
|
|
1496
1534
|
m.clearCachedPermission(app);
|
|
1497
1535
|
|
|
1498
1536
|
// TODO: remove service list which are in the white list
|
|
1537
|
+
},
|
|
1538
|
+
onAppReady: (app) => {
|
|
1539
|
+
let redisStore = new RedisStore({
|
|
1540
|
+
client: app.redis,
|
|
1541
|
+
prefix: app.config.prefix || 'xx-eis:',
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
app.use(
|
|
1545
|
+
session({
|
|
1546
|
+
store: redisStore,
|
|
1547
|
+
resave: false, // required: force lightweight session keep alive (touch)
|
|
1548
|
+
saveUninitialized: false, // recommended: only save session when data exists
|
|
1549
|
+
secret: eis.session.secret || 'default eis session secret',
|
|
1550
|
+
}),
|
|
1551
|
+
);
|
|
1552
|
+
|
|
1553
|
+
app.use(passport.session());
|
|
1554
|
+
},
|
|
1555
|
+
},
|
|
1556
|
+
notify: (user, title, content, category) => {
|
|
1557
|
+
if (!user || !title) {
|
|
1558
|
+
return;
|
|
1499
1559
|
}
|
|
1500
|
-
|
|
1560
|
+
|
|
1561
|
+
app.models.system_notification.create({
|
|
1562
|
+
User: user,
|
|
1563
|
+
Title: title,
|
|
1564
|
+
Content: content,
|
|
1565
|
+
Category: category,
|
|
1566
|
+
});
|
|
1567
|
+
},
|
|
1501
1568
|
})
|