free-be-account 0.0.1

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/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "free-be-account",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "license": "UNLICENSED",
6
+ "dependencies": {
7
+ "@alicloud/pop-core": "^1.7.9",
8
+ "bcrypt": "^5.0.1",
9
+ "crypto-js": "^4.0.0",
10
+ "js-md5": "^0.7.3",
11
+ "passport": "^0.5.0",
12
+ "passport-local": "^1.0.0",
13
+ "uuid": "^8.3.2"
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: 'module-title',
3
+ description: 'module-description',
4
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: 'module-label-title',
3
+ description: 'module-label-description',
4
+ };
@@ -0,0 +1,33 @@
1
+ const path = require('path');
2
+ const express = require(path.resolve('./') + "/node_modules/express");
3
+ const router = express.Router();
4
+
5
+ router.get('/',
6
+ (req, res, next) => {
7
+ res.locals = res.locals || {};
8
+ res.locals.fields = [
9
+ 'id',
10
+ 'Name',
11
+ 'Index',
12
+ 'Enabled',
13
+ 'Permission'
14
+ ];
15
+ res.locals.filter = {
16
+ Parent: req.query.Parent || {
17
+ $exists: false,
18
+ $eq: null
19
+ }
20
+ }
21
+
22
+ return next();
23
+ },
24
+ router.FindAllDocuments('plabel')
25
+ );
26
+
27
+ router.post('/', router.CreateDocument('plabel'));
28
+
29
+ router.put('/', router.UpdateDocument('plabel'));
30
+
31
+ router.delete('/', router.DeleteDocument('plabel'));
32
+
33
+ module.exports = router;
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: 'module-mgmt-title',
3
+ description: 'module-mgmt-description',
4
+ };
@@ -0,0 +1,279 @@
1
+ const path = require('path');
2
+ const express = require(path.resolve('./') + "/node_modules/express");
3
+ const router = express.Router();
4
+ const { AccountAuditStatus } = require('../../enum');
5
+ const { clearPermission, encryptPwd, crypto } = require('../../utils');
6
+
7
+ // TODO: i18n translate
8
+ const accountFilters = [
9
+ {
10
+ Name: 'LastUpdateDate',
11
+ Type: 'DateRange',
12
+ Label: '更新日期',
13
+ Placeholder: '请选择',
14
+ },
15
+ {
16
+ Name: 'Enabled',
17
+ Type: 'Select',
18
+ Label: '激活状态',
19
+ Placeholder: '请选择',
20
+ Options: [
21
+ {
22
+ Label: '已激活',
23
+ Value: true,
24
+ },
25
+ {
26
+ Label: '未激活',
27
+ Value: false,
28
+ },
29
+ ],
30
+ },
31
+ {
32
+ Name: 'Profile.Name',
33
+ Type: 'String',
34
+ Label: '姓名',
35
+ },
36
+ {
37
+ Name: 'Profile.Title',
38
+ Type: 'String',
39
+ Label: '职务',
40
+ },
41
+ {
42
+ Name: 'PhoneNumber',
43
+ Type: 'String',
44
+ Label: '手机号',
45
+ },
46
+ {
47
+ Name: 'UserName',
48
+ Type: 'String',
49
+ Label: '用户名',
50
+ },
51
+ ];
52
+
53
+ router.get('/', async (req, res, next) => {
54
+ res.locals.fields = [
55
+ 'id',
56
+ 'LastUpdateDate',
57
+ 'Profile',
58
+ 'PhoneNumber',
59
+ 'Enabled',
60
+ 'Org',
61
+ 'Labels',
62
+ ];
63
+
64
+ res.locals.filter = Object.assign({ Saved: true }, res.app.modules['core-modules'].generateQueryFilter(accountFilters, req.query), res.locals.filter);
65
+
66
+ res.locals.data.summary = {};
67
+ res.locals.data.summary.auditing = await res.app.models['account'].countDocuments({...res.locals.filter, Status: AccountAuditStatus.Auditing });
68
+ res.locals.data.summary.passed = await res.app.models['account'].countDocuments({...res.locals.filter, Status: AccountAuditStatus.Passed });
69
+ res.locals.data.summary.failed = await res.app.models['account'].countDocuments({...res.locals.filter, Status: AccountAuditStatus.Failed });
70
+
71
+ return next();
72
+
73
+ }, router.FindDocuments('account', false, async (req, res) => {
74
+ res.locals.data.Filters = accountFilters;
75
+
76
+ if (res.locals.data && res.locals.data.total) {
77
+ for (let i = 0; i < res.locals.data.docs.length; i += 1) {
78
+ const doc = res.locals.data.docs[i];
79
+ if (doc && doc.Org) {
80
+ const org = await app.models.organization.findOne({ id: doc.Org });
81
+ if (org) {
82
+ doc.Org = {
83
+ id: org.id,
84
+ Name: org.Name
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }));
91
+
92
+ router.get('/:id',
93
+ (req, res, next) => {
94
+ if (req.params.id === 'sl') return next('route');
95
+
96
+ res.locals.filter = { id: req.params.id };
97
+
98
+ res.locals.fields = [
99
+ 'id',
100
+ 'LastUpdateDate',
101
+ 'Profile',
102
+ 'PhoneNumber',
103
+ 'UserName',
104
+ 'Enabled',
105
+ 'Org',
106
+ 'Status',
107
+ 'Permission',
108
+ 'Labels'
109
+ ];
110
+
111
+ return next();
112
+ },
113
+ router.FindDocuments('account', false, (req, res) => {
114
+ if (res.locals.data && res.locals.data.total) {
115
+ res.locals.data = res.locals.data.docs[0];
116
+ } else {
117
+ res.locals.data = {};
118
+ }
119
+ })
120
+ );
121
+
122
+ router.post('/',
123
+ (req, res, next) => {
124
+ req.body.Status = AccountAuditStatus.Passed;
125
+
126
+ if (req.body.Permission) {
127
+ if (!clearPermission(req.body.Permission)) {
128
+ req.body.Permission = {};
129
+ }
130
+ }
131
+
132
+ // pwd
133
+ if (req.body.Password) {
134
+ const password = crypto.encoder.desDecode(req.body.Password, router.mdl.config.desKey);
135
+ req.body.Password = encryptPwd(password, router.mdl.config.pwdEncryptMethod || 'md5');
136
+ }
137
+
138
+ return next();
139
+ },
140
+ router.CreateDocument('account')
141
+ );
142
+
143
+ router.post('/audit',
144
+ async (req, res, next) => {
145
+ if (typeof req.body.Status === 'undefined' ||
146
+ typeof req.body.id === 'undefined' ||
147
+ [
148
+ AccountAuditStatus.Passed,
149
+ AccountAuditStatus.Auditing,
150
+ AccountAuditStatus.Failed
151
+ ].indexOf(req.body.Status) < 0) {
152
+ await res.endWithErr(400);
153
+ return;
154
+ }
155
+
156
+ res.locals.body = res.locals.body || {};
157
+ res.locals.body.Status = req.body.Status;
158
+
159
+ // set to default permission if change audit status back to auditing
160
+ if (req.body.Status === AccountAuditStatus.Failed) {
161
+ res.locals.body.Permission = {};
162
+ } else if (req.body.Status === AccountAuditStatus.Auditing) {
163
+ res.locals.body.Permission = router.mdl.config.accountDefaultPermissions;
164
+ }
165
+
166
+ if (res.locals.body.Permission)
167
+ clearPermission(res.locals.body.Permission);
168
+
169
+ res.locals.filter = res.locals.filter || {};
170
+ res.locals.filter.id = req.body.id;
171
+
172
+ // set permission
173
+ // try to use default account permission in the config first
174
+ // if not found use the permission of the org of the account (if have org module loaded)
175
+ if (req.body.Status === app.modules.account.AccountAuditStatus.Passed && req.body.id) {
176
+ const account = await app.models.account.findOne({ id: req.body.id });
177
+ if (account && account.Org) {
178
+ const accountOrg = await app.models.organization.findOne({ id: account.Org });
179
+ if (accountOrg && accountOrg.Permission) {
180
+ const p = Object.assign({}, accountOrg.Permission);
181
+ if (app.modules.account.utils.clearPermission(p)) {
182
+ const op = res.locals.CURD.find(op => op.method === 'U' && op.model === 'account');
183
+ if (op) {
184
+ op.ctx.body.Permission = p;
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+
191
+ return next();
192
+ },
193
+ router.UpdateDocument('account'),
194
+ );
195
+
196
+ router.put('/',
197
+ router.UpdateDocument('account', false, (req, res) => {
198
+ // clear return data
199
+ if (res.locals.data && res.locals.data.id) {
200
+ res.locals.data = { id: res.locals.data.id };
201
+ }
202
+ })
203
+ );
204
+
205
+ router.post('/:id/resetpwd',
206
+ (req, res, next) => {
207
+ if (!req.params.id) {
208
+ res.makeError(401, 'Please specify which account you want to reset!');
209
+ return next('route');
210
+ }
211
+
212
+ res.locals.filter = { id: req.params.id };
213
+
214
+ res.locals.fields = [
215
+ 'Password'
216
+ ];
217
+
218
+ res.locals.body = {
219
+ Password: router.mdl.config.defaultPassword
220
+ };
221
+
222
+ res.locals.newPwd = router.mdl.config.defaultPassword;
223
+
224
+ // set default password
225
+ let clearPwd = router.mdl.config.accountDefaultPasswordRandom ?
226
+ crypto.randomPassword(router.mdl.config.accountDefaultPasswordRandomLength || 6) :
227
+ router.mdl.config.accountDefaultPassword;
228
+
229
+ clearPwd = clearPwd || res.app.modules.account.config.defaultPassword;
230
+ res.locals.newPwd = clearPwd;
231
+
232
+ res.locals.body.Password = res.app.modules.account.utils.encryptPwd(clearPwd, router.mdl.config.pwdEncryptMethod || 'md5');
233
+
234
+ return next();
235
+ },
236
+ router.UpdateDocument('account', false, (req, res) => {
237
+ // return the new pwd
238
+ if (res.locals.newPwd) {
239
+ res.locals.data = {
240
+ newPwd: res.locals.newPwd
241
+ };
242
+ }
243
+ })
244
+ );
245
+
246
+ router.delete('/', router.DeleteDocument('account'));
247
+
248
+ router.get(`/search`,
249
+ async (req, res, next) => {
250
+ res.locals = res.locals || {};
251
+
252
+ res.locals.filter = {};
253
+ if (req.query.id) {
254
+ res.locals.filter.id = req.query.id;
255
+ }
256
+ else if (req.query.search) {
257
+ let keyword = RegExp.quote(req.query.search);
258
+ res.locals.filter.$or = [
259
+ { Name: keyword },
260
+ ];
261
+ } else {
262
+ await res.endWithErr(400);
263
+ return;
264
+ }
265
+
266
+ res.locals.fields = [
267
+ 'id',
268
+ 'Name',
269
+ 'Index',
270
+ 'IsVirtual',
271
+ 'LastUpdateDate'
272
+ ];
273
+
274
+ return next();
275
+ },
276
+ router.FindDocuments('organization')
277
+ );
278
+
279
+ module.exports = router;
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: 'module-org-export-title',
3
+ description: 'module-org-export-description',
4
+ };
@@ -0,0 +1,11 @@
1
+ const express = require(require('path').resolve('./') + "/node_modules/express");
2
+ const router = express.Router();
3
+
4
+ /**
5
+ * get all the dicts
6
+ */
7
+ router.get('/',
8
+ router.FindAllDocuments('organization')
9
+ )
10
+
11
+ module.exports = router;
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: 'module-org-title',
3
+ description: 'module-org-description',
4
+ };
@@ -0,0 +1,67 @@
1
+ const express = require(require('path').resolve('./') + "/node_modules/express");
2
+ const router = express.Router();
3
+
4
+ router.get('/',
5
+ (req, res, next) => {
6
+ res.locals = res.locals || {};
7
+ res.locals.fields = [
8
+ 'id',
9
+ 'Name',
10
+ 'Index',
11
+ 'IsVirtual',
12
+ 'Permission'
13
+ ];
14
+ res.locals.filter = {
15
+ Parent: req.query.Parent || {
16
+ $exists: false,
17
+ $eq: null
18
+ }
19
+ }
20
+
21
+ return next();
22
+ },
23
+ router.FindAllDocuments('organization')
24
+ );
25
+
26
+ // router.get('/search',
27
+ // (req, res, next) => {
28
+ // res.locals = res.locals || {};
29
+
30
+ // res.locals.filter = {};
31
+ // if (req.query.id) {
32
+ // res.locals.filter.id = req.query.id;
33
+ // }
34
+ // else if (req.query.search) {
35
+ // // TODO: search with regexp not working!!!
36
+ // // let keyword = new RegExp(req.query.search);
37
+ // res.locals.filter.$or = [
38
+ // { Name: req.query.search },
39
+ // ];
40
+ // } else {
41
+ // await res.endWithErr(400);
42
+ // return;
43
+ // }
44
+
45
+ // res.locals.fields = [
46
+ // 'id',
47
+ // 'Name',
48
+ // 'Index',
49
+ // 'IsVirtual',
50
+ // 'LastUpdateDate'
51
+ // ];
52
+
53
+ // return next();
54
+ // },
55
+ // router.FindDocuments('organization')
56
+ // );
57
+
58
+ // TODO: org name should be unqiue in the same parent
59
+ router.post('/', router.CreateDocument('organization'));
60
+
61
+ // TODO: org name should be unqiue in the same parent
62
+ router.put('/', router.UpdateDocument('organization'));
63
+
64
+ // TODO: should delete recursively
65
+ router.delete('/', router.DeleteDocument('organization'));
66
+
67
+ module.exports = router;
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: 'module-perm-title',
3
+ description: 'module-perm-description',
4
+ };
@@ -0,0 +1,94 @@
1
+ const path = require('path');
2
+ const express = require(path.resolve('./') + "/node_modules/express");
3
+ const router = express.Router();
4
+ const utils = require('../../utils');
5
+
6
+ router.get('/',
7
+ async (req, res, next) => {
8
+ res.locals.filter = {
9
+ Parent: req.query.Parent || {
10
+ $exists: false,
11
+ $eq: null
12
+ },
13
+ };
14
+
15
+ // add app.serviceList into db if not yet
16
+ // TODO: we force clean up all built-in permissions here, any problems?
17
+ // it will remove all the data scope!!!!!!!!!
18
+ await utils.saveServiceList(res.app, false);
19
+
20
+ // add form fields
21
+ const Fields = Object.assign([], router.mdl.config.permFields);
22
+ Fields.push(
23
+ {
24
+ Name: 'Scope',
25
+ Label: router.mdl.t('scope-field-label'),
26
+ Type: 'DynamicList',
27
+ Options: {
28
+ Columns: [
29
+ {
30
+ Name: 'Name',
31
+ Label: router.mdl.t('scope-params-header-label'),
32
+ Type: 'Select',
33
+ Options: res.app.getContainerContent('DataScope').map(ds => {
34
+ const ret = {
35
+ Label: ds.Label,
36
+ Value: ds.Name,
37
+ };
38
+
39
+ if (ds && ds.Params && ds.Params.length > 0) {
40
+ ret.Extra = {
41
+ Label: router.mdl.t('scope-params-label'),
42
+ Name: 'Params',
43
+ Type: 'FixedList',
44
+ Options: {
45
+ Columns: ds.Params,
46
+ Default: [{}]
47
+ }
48
+ }
49
+ }
50
+
51
+ return ret;
52
+ }),
53
+ },
54
+ ],
55
+ },
56
+ }
57
+ );
58
+
59
+ res.addData({ Fields }, false)
60
+
61
+ return next();
62
+ },
63
+ router.FindAllDocuments('permission')
64
+ );
65
+
66
+ router.post('/',
67
+ async (req, res, next) => {
68
+ if (!req.body.Name || !req.body.Title) {
69
+ res.makeError(201, router.mdl);
70
+ return;
71
+ }
72
+
73
+ let parent;
74
+ if (req.body.Parent) {
75
+ parent = await res.app.models.permission.findOne({ id: req.body.Parent });
76
+ if (!parent || !parent.Path) {
77
+ res.makeError(211, router.mdl);
78
+ return;
79
+ }
80
+ }
81
+
82
+ req.body.Path = `${parent ? parent.Path + '/' : ''}${req.body.Name}`
83
+ req.body.BuiltIn = false;
84
+
85
+ return next();
86
+ },
87
+ router.CreateDocument('permission')
88
+ );
89
+
90
+ router.put('/', router.UpdateDocument('permission'));
91
+
92
+ router.delete('/', router.DeleteDocument('permission'));
93
+
94
+ module.exports = router;
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: 'module-uc-title',
3
+ description: 'module-uc-description',
4
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ title: '账号信息',
3
+ description: '',
4
+ };
@@ -0,0 +1,95 @@
1
+ const express = require(require('path').resolve('./') + "/node_modules/express");
2
+ const router = express.Router();
3
+
4
+ router.get('/', (req, res, next) => {
5
+ const user = req.user;
6
+
7
+ const StepsDefinition = Object.clone(router.mdl.config.infoStepsDefinition || []);
8
+
9
+ const extraFields = {};
10
+ if (StepsDefinition[0]) {
11
+ StepsDefinition[0].Fields = StepsDefinition[0].Fields || [];
12
+
13
+ for (let i = 0; i < StepsDefinition[0].Fields.length; i += 1) {
14
+ const field = StepsDefinition[0].Fields[i];
15
+
16
+ if (field && field.Name) {
17
+ Object.setValue(extraFields, field.Name, Object.nestValue(user, field.Name));
18
+ }
19
+ }
20
+
21
+ }
22
+
23
+ res.addData({
24
+ ...extraFields,
25
+
26
+ PhoneNumber: user.PhoneNumber,
27
+ Org: user.Org,
28
+ Profile: user.Profile,
29
+ Status: user.Status,
30
+
31
+ StepsDefinition,
32
+ });
33
+
34
+ return next();
35
+ });
36
+
37
+ router.put('/', async (req, res, next) => {
38
+ const user = req.user;
39
+
40
+ res.locals.filter = { id: user.id };
41
+ // get new data from request (now only profile can be updated in uc)
42
+ if (req.body.Profile) {
43
+ res.locals.body = { Profile: req.body.Profile };
44
+ } else {
45
+ res.locals.body = { Enabled: user.Enabled };
46
+ }
47
+
48
+ return next();
49
+ }, router.UpdateDocument('account', false, (req, res) => {
50
+ if (res.locals.data) {
51
+
52
+ // only return necessary info
53
+ res.addData({});
54
+ }
55
+ }));
56
+
57
+ // change to editing status
58
+ router.post('/edit', async (req, res, next) => {
59
+ // set to default permission
60
+ const p = res.app.modules.account.config.accountDefaultPermissions;
61
+ res.app.modules.account.utils.clearPermission(p);
62
+
63
+ // TODO: should not use mongoose directly
64
+ await res.app.models['account'].update({ id: req.user.id }, { $unset: { Status: 0 }, $set: { Permission: p } });
65
+
66
+ res.addData({});
67
+
68
+ return next();
69
+ });
70
+
71
+ // submit to audit
72
+ router.post('/submit', async (req, res, next) => {
73
+ const user = req.user;
74
+
75
+ // save changes first
76
+ if (req.body.Profile) {
77
+ user.Profile = Object.assign(user.Profile, req.body.Profile);
78
+ }
79
+
80
+ user.Status = res.app.modules.account.AccountAuditStatus.Auditing;
81
+
82
+ // set to default permission
83
+ const p = res.app.modules.account.config.accountDefaultPermissions;
84
+ res.app.modules.account.utils.clearPermission(p);
85
+ user.Permission = p;
86
+
87
+ // save
88
+ await user.save();
89
+
90
+ res.addData({});
91
+
92
+ return next();
93
+ });
94
+
95
+ module.exports = router;
@@ -0,0 +1,5 @@
1
+
2
+ module.exports = {
3
+ title: '修改手机号',
4
+ description: '',
5
+ };