nodefony 7.0.0-beta.2 → 7.0.0-beta.21
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/CHANGELOG.md +534 -8028
- package/README.md +33 -30
- package/autoloader.es6 +46 -48
- package/builder.es6 +66 -76
- package/cli/builder/bundles/bundle.js +57 -63
- package/cli/builder/bundles/controller.js +34 -38
- package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
- package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
- package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +25 -30
- package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
- package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
- package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
- package/cli/builder/bundles/users-bundle/Resources/config/config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
- package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -75
- package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
- package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +13 -15
- package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
- package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
- package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -36
- package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
- package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
- package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
- package/cli/builder/bundles/users-bundle/package.json +27 -25
- package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
- package/cli/builder/bundles/users-bundle/readme.md +7 -7
- package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
- package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
- package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
- package/cli/builder/bundles/users-bundle/tests/loginTest.js +119 -70
- package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
- package/cli/builder/microService/microService.js +139 -141
- package/cli/builder/microService/skeletons/package.json +23 -22
- package/cli/builder/project/project.js +228 -181
- package/cli/builder/project/skeletons/README.md +33 -30
- package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
- package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
- package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
- package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
- package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
- package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
- package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
- package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
- package/cli/builder/project/skeletons/package.json.twig +70 -0
- package/cli/builder/react/reactBuilder.js +59 -65
- package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
- package/cli/builder/skeletons/app/appKernel.js +120 -2
- package/cli/builder/skeletons/config/config.js +1 -1
- package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
- package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
- package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -12
- package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
- package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
- package/cli/builder/skeletons/package.json.twig +57 -0
- package/cli/builder/skeletons/unittest/testFile.js +44 -45
- package/cli/builder/vue/skeletons/vue.config.js +84 -10
- package/cli/builder/vue/vueBuilder.js +116 -114
- package/cli/generate/generate.es6 +38 -39
- package/cli/install/install.js +45 -58
- package/cli/sequelize/sequelize.js +50 -39
- package/cli/start.js +353 -347
- package/cli/tools/pm2.es6 +55 -57
- package/cli/tools/tools.es6 +36 -37
- package/cli.es6 +280 -228
- package/container.es6 +51 -59
- package/error.es6 +25 -27
- package/fileClass.es6 +53 -55
- package/finder/file.es6 +5 -4
- package/finder/fileResult.es6 +23 -22
- package/finder/finder2.es6 +46 -54
- package/finder.es6 +88 -97
- package/kernel/annotations/annotations.es6 +44 -46
- package/kernel/api/api.es6 +6 -8
- package/kernel/api/graphqlApi.es6 +21 -21
- package/kernel/api/jsonApi.es6 +40 -45
- package/kernel/api/openApi.es6 +9 -11
- package/kernel/api/schemas/openApiSchema.js +61 -32
- package/kernel/babylon.es6 +31 -38
- package/kernel/bundle.es6 +252 -220
- package/kernel/cliKernel.es6 +157 -170
- package/kernel/command.es6 +17 -20
- package/kernel/commands/nodefonyCommand.es6 +111 -58
- package/kernel/commands/tasks/bundlesTask.es6 +14 -19
- package/kernel/controllers/controller.es6 +167 -180
- package/kernel/fixture.es6 +4 -7
- package/kernel/injections/injections.es6 +97 -103
- package/kernel/kernel.es6 +476 -384
- package/kernel/kernelWatcher.es6 +64 -54
- package/kernel/orm/entity.es6 +10 -12
- package/kernel/orm/orm.es6 +68 -48
- package/kernel/reader.es6 +45 -47
- package/kernel/security/encoder.es6 +8 -6
- package/kernel/security/factories/factory.es6 +34 -37
- package/kernel/security/factories/passeportFactory.es6 +13 -14
- package/kernel/security/provider.es6 +11 -13
- package/kernel/security/providers/chainProvider.es6 +13 -28
- package/kernel/security/providers/memoryProvider.es6 +7 -11
- package/kernel/security/providers/providerManager.es6 +11 -14
- package/kernel/security/providers/userEntityProvider.es6 +7 -8
- package/kernel/security/role.es6 +3 -3
- package/kernel/security/secureArea.es6 +143 -149
- package/kernel/security/tokens/token.es6 +30 -32
- package/kernel/security/user.es6 +19 -19
- package/kernel/serviceRealTime.es6 +5 -7
- package/kernel/services/connectionsService.es6 +20 -22
- package/kernel/services/cron/cronService.es6 +14 -16
- package/kernel/task.es6 +20 -26
- package/kernel/templates.es6 +4 -5
- package/kernel/templating/twig.es6 +56 -47
- package/kernel/tests/cliTest.js +7 -11
- package/kernel/tests/containerTest.js +25 -37
- package/kernel/tests/kernelTest.js +9 -16
- package/nodefony.es6 +279 -256
- package/notificationsCenter.es6 +28 -20
- package/package.json +40 -40
- package/protocol.es6 +19 -21
- package/protocols/bayeux.es6 +35 -38
- package/protocols/jsonRpc/jsonrpc.es6 +12 -14
- package/result.es6 +11 -12
- package/service.es6 +62 -62
- package/syslog/pdu.es6 +99 -91
- package/syslog/syslog.es6 +101 -102
- package/watcher.es6 +21 -20
- package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
- package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
- package/cli/builder/project/skeletons/package.json.skeleton +0 -52
- package/cli/builder/skeletons/package.json +0 -61
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
const regController = /^(.*)Controller$/;
|
|
2
2
|
|
|
3
3
|
class generateController extends nodefony.Builder {
|
|
4
|
-
|
|
5
|
-
constructor(cli, options = {}) {
|
|
4
|
+
constructor (cli, options = {}) {
|
|
6
5
|
super(cli, cli.cmd, cli.args);
|
|
7
6
|
this.directory = "controller";
|
|
8
7
|
this.bundle = this.kernel.getBundle("app");
|
|
@@ -13,65 +12,62 @@ class generateController extends nodefony.Builder {
|
|
|
13
12
|
directory: this.directory,
|
|
14
13
|
bundle: this.bundle.name,
|
|
15
14
|
controllerName: "defaultController",
|
|
16
|
-
shortName:"default"
|
|
15
|
+
shortName: "default"
|
|
17
16
|
}, options);
|
|
18
|
-
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
interaction(
|
|
19
|
+
interaction () {
|
|
22
20
|
return this.cli.prompt([{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
21
|
+
type: "input",
|
|
22
|
+
name: "controllerName",
|
|
23
|
+
default: (response) => {
|
|
24
|
+
if (response.bundle === "Quit") {
|
|
25
|
+
return Promise.reject("Quit");
|
|
26
|
+
}
|
|
27
|
+
return `${this.bundle.name}Controller`;
|
|
28
|
+
},
|
|
29
|
+
message: "Enter Controller Name : ",
|
|
30
|
+
validate: (value, response) => {
|
|
31
|
+
if (value) {
|
|
32
|
+
try {
|
|
33
|
+
this.checkName(value, response);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return e.message;
|
|
40
36
|
}
|
|
41
|
-
return
|
|
37
|
+
return true;
|
|
42
38
|
}
|
|
39
|
+
return `${value} Unauthorised Please enter a valid Controller name`;
|
|
40
|
+
}
|
|
43
41
|
}]);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
setBundle(bundle){
|
|
47
|
-
this.bundle = bundle
|
|
48
|
-
this.response.bundle = bundle.name
|
|
49
|
-
//console.log(this.response)
|
|
50
|
-
//console.log(this.bundle.bundleName)
|
|
51
|
-
this.response.bundleName = this.bundle.bundleName
|
|
44
|
+
setBundle (bundle) {
|
|
45
|
+
this.bundle = bundle;
|
|
46
|
+
this.response.bundle = bundle.name;
|
|
47
|
+
// console.log(this.response)
|
|
48
|
+
// console.log(this.bundle.bundleName)
|
|
49
|
+
this.response.bundleName = this.bundle.bundleName;
|
|
52
50
|
this.setLocation(path.resolve(bundle.path, "controller"));
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
createBuilder() {
|
|
53
|
+
createBuilder () {
|
|
56
54
|
this.buildFront(this.response, this.bundle.path);
|
|
57
55
|
return this.Front.generateController(this.response.directory);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
checkName(name, response) {
|
|
61
|
-
|
|
58
|
+
checkName (name, response) {
|
|
59
|
+
const res = regController.exec(name);
|
|
62
60
|
this.shortName = null;
|
|
63
61
|
if (res) {
|
|
64
62
|
this.name = name;
|
|
65
63
|
this.shortName = res[1];
|
|
66
|
-
response.name = this.shortName
|
|
67
|
-
response.shortName = this.shortName
|
|
68
|
-
response.directory = this.shortName
|
|
64
|
+
response.name = this.shortName;
|
|
65
|
+
response.shortName = this.shortName;
|
|
66
|
+
response.directory = this.shortName;
|
|
69
67
|
} else {
|
|
70
|
-
throw new Error(
|
|
68
|
+
throw new Error(`Bad controller name : ${name}`);
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
module.exports = generateController;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
class fixtureTask extends nodefony.Task {
|
|
2
|
-
|
|
3
|
-
constructor(name, command) {
|
|
2
|
+
constructor (name, command) {
|
|
4
3
|
super(name, command);
|
|
5
4
|
this.bundle = command.bundle;
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
showHelp() {
|
|
9
|
-
this.setHelp(
|
|
7
|
+
showHelp () {
|
|
8
|
+
this.setHelp(
|
|
9
|
+
"users:fixtures:default",
|
|
10
10
|
"Generate admin, anonymous and 3 common users `nodefony users:fixtures:default` "
|
|
11
11
|
);
|
|
12
|
-
this.setHelp(
|
|
12
|
+
this.setHelp(
|
|
13
|
+
"users:fixtures:random nb",
|
|
13
14
|
"Generate ramdom users with faker `nodefony users:fixtures:random 10` "
|
|
14
15
|
);
|
|
15
16
|
}
|
|
@@ -19,30 +20,28 @@ class fixtureTask extends nodefony.Task {
|
|
|
19
20
|
const fixtures = this.bundle.getFixture("users");
|
|
20
21
|
if (fixtures) {
|
|
21
22
|
this.log(`LOAD FIXTURES users : ${args}`, "INFO");
|
|
22
|
-
|
|
23
|
+
const inst = new fixtures(this.container);
|
|
23
24
|
return await inst.run(args);
|
|
24
25
|
}
|
|
25
|
-
throw new Error(
|
|
26
|
-
|
|
26
|
+
throw new Error("users fixtures not found ");
|
|
27
27
|
} catch (e) {
|
|
28
28
|
throw e;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
async random(args = null) {
|
|
32
|
+
async random (args = null) {
|
|
33
33
|
try {
|
|
34
34
|
const fixtures = this.bundle.getFixture("users");
|
|
35
35
|
if (fixtures) {
|
|
36
36
|
this.log(`RANDOM FIXTURES users : ${args}`, "INFO");
|
|
37
|
-
|
|
37
|
+
const inst = new fixtures(this.container);
|
|
38
38
|
return await inst.run(args);
|
|
39
39
|
}
|
|
40
|
-
throw new Error(
|
|
40
|
+
throw new Error("users fixtures not found ");
|
|
41
41
|
} catch (e) {
|
|
42
42
|
throw e;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
module.exports = fixtureTask;
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
const fixtureTask = require(path.resolve(__dirname, "fixtureTask.js"));
|
|
2
2
|
|
|
3
3
|
class usersCommand extends nodefony.Command {
|
|
4
|
-
constructor(cli, bundle) {
|
|
4
|
+
constructor (cli, bundle) {
|
|
5
5
|
super("users", cli, bundle);
|
|
6
6
|
this.usersService = this.get("users");
|
|
7
7
|
this.setTask("fixtures", fixtureTask);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
showHelp() {
|
|
11
|
-
this.setHelp(
|
|
10
|
+
showHelp () {
|
|
11
|
+
this.setHelp(
|
|
12
|
+
"users:show [user]",
|
|
12
13
|
"nodefony users:show admin"
|
|
13
14
|
);
|
|
14
|
-
this.setHelp(
|
|
15
|
+
this.setHelp(
|
|
16
|
+
"users:find [--json] username",
|
|
15
17
|
"nodefony --json users:find admin"
|
|
16
18
|
);
|
|
17
|
-
this.setHelp(
|
|
19
|
+
this.setHelp(
|
|
20
|
+
"users:findAll [--json]",
|
|
18
21
|
"nodefony --json users:findAll"
|
|
19
22
|
);
|
|
20
23
|
super.showHelp();
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
async show(username) {
|
|
26
|
+
async show (username) {
|
|
24
27
|
let obj = null;
|
|
25
28
|
if (username) {
|
|
26
29
|
obj = await this.find(username);
|
|
@@ -29,43 +32,40 @@ class usersCommand extends nodefony.Command {
|
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
find(username) {
|
|
35
|
+
find (username) {
|
|
33
36
|
return this.usersService.findOne(username)
|
|
34
37
|
.then((res) => {
|
|
35
38
|
if (this.cli.commander.opts().json) {
|
|
36
39
|
return process.stdout.write(`${JSON.stringify(res)}\n`);
|
|
37
|
-
} else {
|
|
38
|
-
return this.display(res);
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
return this.display(res);
|
|
42
|
+
})
|
|
43
|
+
.catch((e) => {
|
|
41
44
|
if (this.cli.commander.opts().json) {
|
|
42
45
|
return process.stdout.write(`${JSON.stringify({})}\n`);
|
|
43
|
-
} else {
|
|
44
|
-
throw e;
|
|
45
46
|
}
|
|
47
|
+
throw e;
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
findAll() {
|
|
51
|
+
findAll () {
|
|
50
52
|
return this.usersService.find()
|
|
51
53
|
.then((res) => {
|
|
52
54
|
if (this.cli.commander.opts().json) {
|
|
53
55
|
return process.stdout.write(`${JSON.stringify(res.rows)}\n`);
|
|
54
|
-
} else {
|
|
55
|
-
return this.display(res.rows);
|
|
56
56
|
}
|
|
57
|
+
return this.display(res.rows);
|
|
57
58
|
})
|
|
58
|
-
.catch(e => {
|
|
59
|
+
.catch((e) => {
|
|
59
60
|
if (this.cli.commander.opts().json) {
|
|
60
61
|
return process.stdout.write(`${JSON.stringify({})}\n`);
|
|
61
|
-
} else {
|
|
62
|
-
throw e;
|
|
63
62
|
}
|
|
63
|
+
throw e;
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
display(obj) {
|
|
68
|
-
this.cli.logger(
|
|
67
|
+
display (obj) {
|
|
68
|
+
this.cli.logger(`START TABLE : ${this.cli.getEmoji("clapper")}`);
|
|
69
69
|
const type = nodefony.typeOf(obj);
|
|
70
70
|
if (type === "object" || type === null) {
|
|
71
71
|
if (!obj) {
|
|
@@ -74,7 +74,7 @@ class usersCommand extends nodefony.Command {
|
|
|
74
74
|
obj = [obj];
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
const options = {
|
|
78
78
|
head: [
|
|
79
79
|
"username",
|
|
80
80
|
"First Name",
|
|
@@ -85,7 +85,7 @@ class usersCommand extends nodefony.Command {
|
|
|
85
85
|
"Enabled"
|
|
86
86
|
]
|
|
87
87
|
};
|
|
88
|
-
|
|
88
|
+
const table = this.cli.displayTable([], options);
|
|
89
89
|
for (let i = 0; i < obj.length; i++) {
|
|
90
90
|
const user = obj[i];
|
|
91
91
|
table.push([
|
|
@@ -99,8 +99,7 @@ class usersCommand extends nodefony.Command {
|
|
|
99
99
|
]);
|
|
100
100
|
}
|
|
101
101
|
console.log(table.toString());
|
|
102
|
-
this.cli.logger(
|
|
102
|
+
this.cli.logger(`END TABLE : ${this.cli.getEmoji("checkered_flag")}`);
|
|
103
103
|
}
|
|
104
|
-
|
|
105
104
|
}
|
|
106
105
|
module.exports = usersCommand;
|
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
*
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
//const Mongoose = require('mongoose');
|
|
9
|
-
const Schema = require(
|
|
10
|
-
const mongoosePaginate = require(
|
|
11
|
-
const validator = require(
|
|
8
|
+
// const Mongoose = require('mongoose');
|
|
9
|
+
const {Schema} = require("mongoose");
|
|
10
|
+
const mongoosePaginate = require("mongoose-paginate-v2");
|
|
11
|
+
const validator = require("validator");
|
|
12
12
|
|
|
13
13
|
class userEntity extends nodefony.Entity {
|
|
14
|
-
|
|
15
|
-
constructor(bundle) {
|
|
14
|
+
constructor (bundle) {
|
|
16
15
|
/*
|
|
17
16
|
* @param bundle instance
|
|
18
17
|
* @param Entity name
|
|
@@ -20,14 +19,10 @@ class userEntity extends nodefony.Entity {
|
|
|
20
19
|
* @param connection name
|
|
21
20
|
*/
|
|
22
21
|
super(bundle, "user", "mongoose", "nodefony");
|
|
23
|
-
this.once("onConnect", (name, db) => {
|
|
24
|
-
this.model = this.registerModel(db);
|
|
25
|
-
this.orm.setEntity(this);
|
|
26
|
-
});
|
|
27
22
|
}
|
|
28
23
|
|
|
29
|
-
getSchema() {
|
|
30
|
-
//const encodePassword = this.encode.bind(this);
|
|
24
|
+
getSchema () {
|
|
25
|
+
// const encodePassword = this.encode.bind(this);
|
|
31
26
|
return {
|
|
32
27
|
username: {
|
|
33
28
|
type: String,
|
|
@@ -65,7 +60,7 @@ class userEntity extends nodefony.Entity {
|
|
|
65
60
|
type: String,
|
|
66
61
|
unique: true,
|
|
67
62
|
required: true,
|
|
68
|
-
validate: [validator.isEmail,
|
|
63
|
+
validate: [validator.isEmail, "invalid email {VALUE}"],
|
|
69
64
|
createIndexes: {
|
|
70
65
|
unique: true
|
|
71
66
|
}
|
|
@@ -117,8 +112,8 @@ class userEntity extends nodefony.Entity {
|
|
|
117
112
|
};
|
|
118
113
|
}
|
|
119
114
|
|
|
120
|
-
validPassword(value) {
|
|
121
|
-
|
|
115
|
+
validPassword (value) {
|
|
116
|
+
const valid = validator.isLength(value, {
|
|
122
117
|
min: 4,
|
|
123
118
|
max: undefined
|
|
124
119
|
});
|
|
@@ -128,46 +123,46 @@ class userEntity extends nodefony.Entity {
|
|
|
128
123
|
return value;
|
|
129
124
|
}
|
|
130
125
|
|
|
131
|
-
registerModel(db) {
|
|
132
|
-
|
|
126
|
+
registerModel (db) {
|
|
127
|
+
const mySchema = new Schema(this.getSchema(), {
|
|
133
128
|
timestamps: {
|
|
134
|
-
createdAt:
|
|
135
|
-
updatedAt:
|
|
129
|
+
createdAt: "createdAt",
|
|
130
|
+
updatedAt: "updatedAt"
|
|
136
131
|
}
|
|
137
132
|
});
|
|
138
133
|
mySchema.plugin(mongoosePaginate);
|
|
139
|
-
|
|
140
|
-
mySchema.pre(
|
|
141
|
-
if (!this.isModified(
|
|
134
|
+
const entity = this;
|
|
135
|
+
mySchema.pre("save", function (next) {
|
|
136
|
+
if (!this.isModified("password")) {
|
|
142
137
|
return next();
|
|
143
138
|
}
|
|
144
139
|
entity.logger("hash password ", "DEBUG");
|
|
145
140
|
entity.validPassword(this.password);
|
|
146
141
|
return entity.encode(this.password)
|
|
147
|
-
.then(hash => {
|
|
142
|
+
.then((hash) => {
|
|
148
143
|
entity.logger(hash, "DEBUG");
|
|
149
144
|
this.password = hash;
|
|
150
145
|
return hash;
|
|
151
146
|
})
|
|
152
|
-
.catch(err => {
|
|
147
|
+
.catch((err) => {
|
|
153
148
|
entity.logger(err, "ERROR");
|
|
154
149
|
throw err;
|
|
155
150
|
});
|
|
156
151
|
});
|
|
157
|
-
mySchema.pre(
|
|
158
|
-
//const data = this.getUpdate();
|
|
159
|
-
|
|
152
|
+
mySchema.pre("updateOne", function (next) {
|
|
153
|
+
// const data = this.getUpdate();
|
|
154
|
+
const password = this.get("password");
|
|
160
155
|
if (!password) {
|
|
161
156
|
return next();
|
|
162
157
|
}
|
|
163
158
|
entity.logger("update password hash", "DEBUG");
|
|
164
159
|
entity.validPassword(password);
|
|
165
160
|
return entity.encode(password)
|
|
166
|
-
.then(hash => {
|
|
161
|
+
.then((hash) => {
|
|
167
162
|
entity.logger(hash, "DEBUG");
|
|
168
163
|
this._update.password = hash;
|
|
169
164
|
})
|
|
170
|
-
.catch(err => {
|
|
165
|
+
.catch((err) => {
|
|
171
166
|
entity.logger(err, "ERROR");
|
|
172
167
|
throw err;
|
|
173
168
|
});
|
|
@@ -176,4 +171,4 @@ class userEntity extends nodefony.Entity {
|
|
|
176
171
|
}
|
|
177
172
|
}
|
|
178
173
|
|
|
179
|
-
module.exports = userEntity;
|
|
174
|
+
module.exports = userEntity;
|
|
@@ -2,8 +2,9 @@ const {
|
|
|
2
2
|
Sequelize,
|
|
3
3
|
DataTypes,
|
|
4
4
|
Model
|
|
5
|
-
} = nodefony.Sequelize; //require("sequelize");
|
|
6
|
-
const validator = require(
|
|
5
|
+
} = nodefony.Sequelize; // require("sequelize");
|
|
6
|
+
const validator = require("validator");
|
|
7
|
+
|
|
7
8
|
/*
|
|
8
9
|
*
|
|
9
10
|
*
|
|
@@ -12,8 +13,8 @@ const validator = require('validator');
|
|
|
12
13
|
*
|
|
13
14
|
*/
|
|
14
15
|
class userEntity extends nodefony.Entity {
|
|
16
|
+
constructor (bundle) {
|
|
15
17
|
|
|
16
|
-
constructor(bundle) {
|
|
17
18
|
/*
|
|
18
19
|
* @param bundle instance
|
|
19
20
|
* @param Entity name
|
|
@@ -21,7 +22,8 @@ class userEntity extends nodefony.Entity {
|
|
|
21
22
|
* @param connection name
|
|
22
23
|
*/
|
|
23
24
|
super(bundle, "user", "sequelize", "nodefony");
|
|
24
|
-
|
|
25
|
+
|
|
26
|
+
/* this.orm.on("onOrmReady", ( orm ) => {
|
|
25
27
|
let session = this.orm.getEntity("session");
|
|
26
28
|
if (session) {
|
|
27
29
|
this.model.hasMany(session, {
|
|
@@ -35,7 +37,8 @@ class userEntity extends nodefony.Entity {
|
|
|
35
37
|
});*/
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
40
|
+
// eslint-disable-next-line max-lines-per-function
|
|
41
|
+
getSchema () {
|
|
39
42
|
return {
|
|
40
43
|
username: {
|
|
41
44
|
type: DataTypes.STRING(126),
|
|
@@ -45,9 +48,10 @@ class userEntity extends nodefony.Entity {
|
|
|
45
48
|
validate: {
|
|
46
49
|
is: {
|
|
47
50
|
args: /^[\w-_.]+$/,
|
|
48
|
-
msg:
|
|
51
|
+
msg: "username allow alphanumeric and ( _ | - | . ) characters"
|
|
49
52
|
}
|
|
50
|
-
|
|
53
|
+
|
|
54
|
+
/* notIn: {
|
|
51
55
|
args: [['admin', 'root']],
|
|
52
56
|
msg: `username don't allow (admin , root) login name`
|
|
53
57
|
}*/
|
|
@@ -55,13 +59,14 @@ class userEntity extends nodefony.Entity {
|
|
|
55
59
|
},
|
|
56
60
|
password: {
|
|
57
61
|
type: DataTypes.STRING(256),
|
|
58
|
-
allowNull: false
|
|
59
|
-
|
|
62
|
+
allowNull: false
|
|
63
|
+
|
|
64
|
+
/* validate: {
|
|
60
65
|
min: {
|
|
61
66
|
args: [[4]],
|
|
62
|
-
msg:
|
|
67
|
+
msg: "password allow 4 characters min "
|
|
63
68
|
}
|
|
64
|
-
}
|
|
69
|
+
}*/
|
|
65
70
|
},
|
|
66
71
|
"2fa": {
|
|
67
72
|
type: DataTypes.BOOLEAN,
|
|
@@ -86,7 +91,7 @@ class userEntity extends nodefony.Entity {
|
|
|
86
91
|
},
|
|
87
92
|
email: {
|
|
88
93
|
type: DataTypes.STRING,
|
|
89
|
-
//primaryKey: true,
|
|
94
|
+
// primaryKey: true,
|
|
90
95
|
unique: true,
|
|
91
96
|
allowNull: false,
|
|
92
97
|
validate: {
|
|
@@ -101,7 +106,7 @@ class userEntity extends nodefony.Entity {
|
|
|
101
106
|
validate: {
|
|
102
107
|
is: {
|
|
103
108
|
args: /^[\w-_.]*$/,
|
|
104
|
-
msg:
|
|
109
|
+
msg: "name allow alphanumeric characters"
|
|
105
110
|
}
|
|
106
111
|
}
|
|
107
112
|
},
|
|
@@ -111,7 +116,7 @@ class userEntity extends nodefony.Entity {
|
|
|
111
116
|
validate: {
|
|
112
117
|
is: {
|
|
113
118
|
args: /^[\w-_.]*$/,
|
|
114
|
-
msg:
|
|
119
|
+
msg: "surname allow alphanumeric characters"
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
},
|
|
@@ -122,9 +127,9 @@ class userEntity extends nodefony.Entity {
|
|
|
122
127
|
roles: {
|
|
123
128
|
type: DataTypes.JSON,
|
|
124
129
|
defaultValue: ["ROLE_USER"],
|
|
125
|
-
get(key) {
|
|
130
|
+
get (key) {
|
|
126
131
|
let val = this.getDataValue(key);
|
|
127
|
-
if (typeof
|
|
132
|
+
if (typeof val === "string") {
|
|
128
133
|
val = JSON.parse(val);
|
|
129
134
|
}
|
|
130
135
|
return val;
|
|
@@ -145,8 +150,8 @@ class userEntity extends nodefony.Entity {
|
|
|
145
150
|
};
|
|
146
151
|
}
|
|
147
152
|
|
|
148
|
-
validPassword(value) {
|
|
149
|
-
|
|
153
|
+
validPassword (value) {
|
|
154
|
+
const valid = validator.isLength(value, {
|
|
150
155
|
min: 4,
|
|
151
156
|
max: undefined
|
|
152
157
|
});
|
|
@@ -156,17 +161,22 @@ class userEntity extends nodefony.Entity {
|
|
|
156
161
|
return value;
|
|
157
162
|
}
|
|
158
163
|
|
|
159
|
-
registerModel(db) {
|
|
164
|
+
registerModel (db) {
|
|
160
165
|
class MyModel extends Model {
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
static associate (models) {
|
|
167
|
+
// define association here
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
hasRole (name) {
|
|
171
|
+
for (const role in this.roles) {
|
|
163
172
|
if (this.roles[role] === name) {
|
|
164
173
|
return true;
|
|
165
174
|
}
|
|
166
175
|
}
|
|
167
176
|
return false;
|
|
168
177
|
}
|
|
169
|
-
|
|
178
|
+
|
|
179
|
+
isGranted (role) {
|
|
170
180
|
return this.hasRole(role);
|
|
171
181
|
}
|
|
172
182
|
}
|
|
@@ -175,12 +185,13 @@ class userEntity extends nodefony.Entity {
|
|
|
175
185
|
modelName: this.name,
|
|
176
186
|
hooks: {
|
|
177
187
|
beforeCreate: (user) => {
|
|
188
|
+
console.log("beforeCreate", user);
|
|
178
189
|
this.validPassword(user.password);
|
|
179
190
|
return this.encode(user.password)
|
|
180
|
-
.then(hash => {
|
|
191
|
+
.then((hash) => {
|
|
181
192
|
user.password = hash;
|
|
182
193
|
})
|
|
183
|
-
.catch(err => {
|
|
194
|
+
.catch((err) => {
|
|
184
195
|
this.logger(err, "ERROR");
|
|
185
196
|
throw err;
|
|
186
197
|
});
|
|
@@ -189,10 +200,10 @@ class userEntity extends nodefony.Entity {
|
|
|
189
200
|
if ("password" in userUpate.attributes) {
|
|
190
201
|
this.validPassword(userUpate.attributes.password);
|
|
191
202
|
return this.encode(userUpate.attributes.password)
|
|
192
|
-
.then(hash => {
|
|
203
|
+
.then((hash) => {
|
|
193
204
|
userUpate.attributes.password = hash;
|
|
194
205
|
})
|
|
195
|
-
.catch(err => {
|
|
206
|
+
.catch((err) => {
|
|
196
207
|
this.logger(err, "ERROR");
|
|
197
208
|
throw err;
|
|
198
209
|
});
|
|
@@ -200,19 +211,19 @@ class userEntity extends nodefony.Entity {
|
|
|
200
211
|
}
|
|
201
212
|
},
|
|
202
213
|
freezeTableName: true,
|
|
203
|
-
//add indexes
|
|
214
|
+
// add indexes
|
|
204
215
|
indexes: [{
|
|
205
216
|
unique: true,
|
|
206
|
-
fields: [
|
|
217
|
+
fields: ["email"]
|
|
207
218
|
}]
|
|
208
219
|
// add custom validations
|
|
209
|
-
//validate: {}
|
|
220
|
+
// validate: {}
|
|
210
221
|
});
|
|
211
222
|
return MyModel;
|
|
212
223
|
}
|
|
213
224
|
|
|
214
|
-
logger(pci
|
|
215
|
-
const msgid =
|
|
225
|
+
logger (pci /* , sequelize*/) {
|
|
226
|
+
const msgid = `Entity ${this.name}`;
|
|
216
227
|
return super.logger(pci, "DEBUG", msgid);
|
|
217
228
|
}
|
|
218
229
|
}
|