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
|
@@ -84,21 +84,21 @@ const openApi = {
|
|
|
84
84
|
required: true
|
|
85
85
|
}],
|
|
86
86
|
responses: {
|
|
87
|
-
|
|
87
|
+
"200": {
|
|
88
88
|
description: "User Description",
|
|
89
89
|
content: {
|
|
90
90
|
"application/json": {
|
|
91
91
|
schema: {
|
|
92
92
|
allOf: [{
|
|
93
93
|
$ref: "#/components/schemas/users-api"
|
|
94
|
-
|
|
94
|
+
}, {
|
|
95
95
|
type: "object",
|
|
96
96
|
properties: {
|
|
97
97
|
result: {
|
|
98
98
|
$ref: "#/components/schemas/user"
|
|
99
|
-
}
|
|
99
|
+
}
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
}]
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
@@ -114,7 +114,7 @@ const openApi = {
|
|
|
114
114
|
summary: "Get OpenAPI (OAS 3.0) configuration",
|
|
115
115
|
tags: ["users"],
|
|
116
116
|
responses: {
|
|
117
|
-
|
|
117
|
+
"200": {
|
|
118
118
|
description: "OpenAPI (OAS 3.0) configuration",
|
|
119
119
|
content: {
|
|
120
120
|
"application/json": {}
|
|
@@ -140,7 +140,7 @@ const openApi = {
|
|
|
140
140
|
required: false
|
|
141
141
|
}],
|
|
142
142
|
responses: {
|
|
143
|
-
|
|
143
|
+
"200": {
|
|
144
144
|
description: "List or filter Users",
|
|
145
145
|
content: {
|
|
146
146
|
"application/json": {
|
|
@@ -164,7 +164,7 @@ const openApi = {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
}
|
|
167
|
+
}
|
|
168
168
|
}
|
|
169
169
|
}]
|
|
170
170
|
}
|
|
@@ -179,24 +179,24 @@ const openApi = {
|
|
|
179
179
|
post: {
|
|
180
180
|
summary: "Create user",
|
|
181
181
|
requestBody: {
|
|
182
|
-
description:
|
|
182
|
+
description: "Parameters **users** schema",
|
|
183
183
|
required: true,
|
|
184
184
|
content: {
|
|
185
185
|
"application/json": {
|
|
186
186
|
schema: {
|
|
187
|
-
$ref:
|
|
187
|
+
$ref: "#/components/schemas/user"
|
|
188
188
|
}
|
|
189
189
|
},
|
|
190
190
|
"application/x-www-form-urlencoded": {
|
|
191
191
|
schema: {
|
|
192
|
-
$ref:
|
|
192
|
+
$ref: "#/components/schemas/user"
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
}
|
|
195
|
+
}
|
|
196
196
|
},
|
|
197
197
|
tags: ["users"],
|
|
198
198
|
responses: {
|
|
199
|
-
|
|
199
|
+
"200": {
|
|
200
200
|
description: "get headers request"
|
|
201
201
|
},
|
|
202
202
|
default: {
|
|
@@ -211,7 +211,7 @@ const openApi = {
|
|
|
211
211
|
jwtAuth: ""
|
|
212
212
|
}],
|
|
213
213
|
responses: {
|
|
214
|
-
|
|
214
|
+
"200": {
|
|
215
215
|
description: "get headers request"
|
|
216
216
|
},
|
|
217
217
|
default: {
|
|
@@ -219,7 +219,7 @@ const openApi = {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
}
|
|
222
|
+
}
|
|
223
223
|
},
|
|
224
224
|
|
|
225
225
|
tags: [{
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* @Route ("/api/graphql/users")
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
|
-
const userType = require(path.resolve(__dirname, "
|
|
5
|
+
const userType = require(path.resolve(__dirname, "usertype.js"));
|
|
6
6
|
const userResolver = require(path.resolve(__dirname, "userResolver.js"));
|
|
7
7
|
|
|
8
8
|
module.exports = class graphqlController extends nodefony.Controller {
|
|
9
|
-
|
|
10
|
-
constructor(container, context) {
|
|
9
|
+
constructor (container, context) {
|
|
11
10
|
super(container, context);
|
|
12
11
|
// service entity
|
|
13
12
|
this.usersService = this.get("users");
|
|
@@ -26,13 +25,12 @@ module.exports = class graphqlController extends nodefony.Controller {
|
|
|
26
25
|
* @Method ({"GET", "POST","OPTIONS"})
|
|
27
26
|
* @Route ( "*",name="api-user-graphql")
|
|
28
27
|
*/
|
|
29
|
-
graphqlAction() {
|
|
28
|
+
graphqlAction () {
|
|
30
29
|
try {
|
|
31
30
|
return this.api.query(this.query.query, this.query.variables, this.query.operationName)
|
|
32
|
-
.then((data) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.api.logger(this.query.query, "WARNING")
|
|
31
|
+
.then((data) => this.api.render(data))
|
|
32
|
+
.catch((e) => {
|
|
33
|
+
this.api.logger(this.query.query, "WARNING");
|
|
36
34
|
this.api.logger(e, "ERROR");
|
|
37
35
|
return this.api.renderError(e, 400);
|
|
38
36
|
});
|
|
@@ -41,18 +39,18 @@ module.exports = class graphqlController extends nodefony.Controller {
|
|
|
41
39
|
}
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
static schema(context) {
|
|
45
|
-
return
|
|
42
|
+
static schema (context) {
|
|
43
|
+
return nodefony.api.Graphql.makeExecutableSchema({
|
|
46
44
|
typeDefs: graphqlController.types(context),
|
|
47
45
|
resolvers: graphqlController.resolvers(context)
|
|
48
46
|
});
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
static types(context) {
|
|
49
|
+
static types (context) {
|
|
52
50
|
return [userType];
|
|
53
51
|
}
|
|
54
|
-
static resolvers(context) {
|
|
55
|
-
return [userResolver]
|
|
56
|
-
}
|
|
57
52
|
|
|
58
|
-
|
|
53
|
+
static resolvers (context) {
|
|
54
|
+
return [userResolver];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
Query: {
|
|
3
3
|
// provides all functions for each API endpoint
|
|
4
|
-
async user(obj, field, context, info) {
|
|
5
|
-
const user = context.getUser()
|
|
4
|
+
async user (obj, field, context, info) {
|
|
5
|
+
const user = context.getUser();
|
|
6
6
|
const usersService = context.get("users");
|
|
7
7
|
return await usersService.findOne(field.username, user);
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
async users(obj, field, context, info) {
|
|
11
|
-
const user = context.getUser()
|
|
10
|
+
async users (obj, field, context, info) {
|
|
11
|
+
const user = context.getUser();
|
|
12
12
|
const usersService = context.get("users");
|
|
13
|
-
|
|
13
|
+
const res = await usersService.find({}, {}, user);
|
|
14
14
|
return res.rows;
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
Mutation: {
|
|
18
|
-
async addUser(obj, field, context, info) {
|
|
18
|
+
async addUser (obj, field, context, info) {
|
|
19
19
|
const {
|
|
20
20
|
input
|
|
21
21
|
} = field;
|
|
22
|
-
const user = context.getUser()
|
|
22
|
+
const user = context.getUser();
|
|
23
23
|
const usersService = context.get("users");
|
|
24
24
|
let myuser = null;
|
|
25
25
|
let error = null;
|
|
26
26
|
if (!input.password || !input.confirm) {
|
|
27
|
-
error = new Error(
|
|
27
|
+
error = new Error("Password can't be empty");
|
|
28
28
|
}
|
|
29
29
|
if (input.password !== input.confirm) {
|
|
30
|
-
error = new Error(
|
|
30
|
+
error = new Error("Bad confirm password");
|
|
31
31
|
}
|
|
32
32
|
if (error) {
|
|
33
33
|
context.logger(error, "ERROR");
|
|
@@ -38,38 +38,38 @@ module.exports = {
|
|
|
38
38
|
if (myuser) {
|
|
39
39
|
delete myuser.password;
|
|
40
40
|
delete myuser["2fa-token"];
|
|
41
|
-
return myuser
|
|
41
|
+
return myuser;
|
|
42
42
|
}
|
|
43
|
-
throw new nodefony.Error("user not create",400)
|
|
43
|
+
throw new nodefony.Error("user not create", 400);
|
|
44
44
|
} catch (e) {
|
|
45
45
|
context.logger(e, "ERROR");
|
|
46
|
-
throw new nodefony.Error(e,400)
|
|
46
|
+
throw new nodefony.Error(e, 400);
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
|
|
50
|
-
async updateUser(obj, field, context, info) {
|
|
51
|
-
const user = context.getUser()
|
|
50
|
+
async updateUser (obj, field, context, info) {
|
|
51
|
+
const user = context.getUser();
|
|
52
52
|
const usersService = context.get("users");
|
|
53
53
|
const orm = context.kernel.getORM();
|
|
54
54
|
const {
|
|
55
55
|
input
|
|
56
56
|
} = field;
|
|
57
|
-
const username = input
|
|
57
|
+
const {username} = input;
|
|
58
58
|
return usersService.findOne(username, user)
|
|
59
59
|
.then(async (myuser) => {
|
|
60
60
|
if (myuser) {
|
|
61
61
|
if (input.password) {
|
|
62
|
-
let confirm = false
|
|
62
|
+
let confirm = false;
|
|
63
63
|
if (input.confirm) {
|
|
64
64
|
if (input.password !== input.confirm) {
|
|
65
|
-
throw new Error(
|
|
65
|
+
throw new Error("Bad confirm password");
|
|
66
66
|
}
|
|
67
67
|
delete input.confirm;
|
|
68
68
|
confirm = true;
|
|
69
69
|
}
|
|
70
70
|
if (input["old-password"]) {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
const encoder = orm.getNodefonyEntity("user").getEncoder();
|
|
72
|
+
const check = await encoder.isPasswordValid(input["old-password"], myuser.password);
|
|
73
73
|
if (!check) {
|
|
74
74
|
throw new Error(`User ${username} bad passport`);
|
|
75
75
|
}
|
|
@@ -82,7 +82,7 @@ module.exports = {
|
|
|
82
82
|
}
|
|
83
83
|
return usersService.update(myuser, input, user)
|
|
84
84
|
.then(async (res) => {
|
|
85
|
-
|
|
85
|
+
const message = `Update User ${input.username} OK`;
|
|
86
86
|
context.log(message, "INFO");
|
|
87
87
|
if (context.session && myuser.username === user.username) {
|
|
88
88
|
if (input.username !== myuser.username) {
|
|
@@ -92,30 +92,30 @@ module.exports = {
|
|
|
92
92
|
context.session.set("lang", input.lang);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
const newUser = await usersService.findOne(input.username, user);
|
|
96
96
|
delete newUser.password;
|
|
97
97
|
delete newUser["2fa-token"];
|
|
98
|
-
return newUser
|
|
98
|
+
return newUser;
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
throw new Error(`User ${username} not found`);
|
|
102
|
-
})
|
|
102
|
+
});
|
|
103
103
|
},
|
|
104
104
|
|
|
105
|
-
async deleteUser(obj, field, context, info){
|
|
105
|
+
async deleteUser (obj, field, context, info) {
|
|
106
106
|
const {
|
|
107
107
|
username
|
|
108
108
|
} = field;
|
|
109
|
-
const user = context.getUser()
|
|
109
|
+
const user = context.getUser();
|
|
110
110
|
const usersService = context.get("users");
|
|
111
|
-
return usersService.delete(username, user)
|
|
111
|
+
return usersService.delete(username, user);
|
|
112
112
|
},
|
|
113
113
|
|
|
114
|
-
async deleteUsers(obj, field, context, info){
|
|
114
|
+
async deleteUsers (obj, field, context, info) {
|
|
115
115
|
const {
|
|
116
116
|
users
|
|
117
117
|
} = field;
|
|
118
|
-
return []
|
|
118
|
+
return [];
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
}
|
|
121
|
+
};
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @Route ("/api/jwt")
|
|
3
3
|
*/
|
|
4
4
|
class loginApiController extends nodefony.Controller {
|
|
5
|
-
|
|
6
|
-
constructor(container, context) {
|
|
5
|
+
constructor (container, context) {
|
|
7
6
|
super(container, context);
|
|
8
7
|
this.security = this.get("security");
|
|
9
8
|
this.jwtFactory = this.security.getFactory("jwt");
|
|
@@ -26,7 +25,7 @@ class loginApiController extends nodefony.Controller {
|
|
|
26
25
|
* )
|
|
27
26
|
* @Firewall ({bypass:true})
|
|
28
27
|
*/
|
|
29
|
-
swaggerAction() {
|
|
28
|
+
swaggerAction () {
|
|
30
29
|
return this.optionsAction();
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -34,9 +33,9 @@ class loginApiController extends nodefony.Controller {
|
|
|
34
33
|
* @Method ({"OPTIONS"})
|
|
35
34
|
* @Route ( "",name="api-login-options",)
|
|
36
35
|
*/
|
|
37
|
-
optionsAction() {
|
|
36
|
+
optionsAction () {
|
|
38
37
|
try {
|
|
39
|
-
|
|
38
|
+
const openApiConfig = require(path.resolve(this.bundle.path, "Resources", "swagger", "openapi", "login.js"));
|
|
40
39
|
return this.api.renderSchema(openApiConfig, this.usersService.entity);
|
|
41
40
|
} catch (e) {
|
|
42
41
|
return this.api.renderError(e, 400);
|
|
@@ -50,7 +49,7 @@ class loginApiController extends nodefony.Controller {
|
|
|
50
49
|
* name="api-login-jwt"
|
|
51
50
|
* )
|
|
52
51
|
*/
|
|
53
|
-
async loginAction() {
|
|
52
|
+
async loginAction () {
|
|
54
53
|
if (!this.context.token) {
|
|
55
54
|
return this.createException("No Auth Token", 401);
|
|
56
55
|
}
|
|
@@ -61,15 +60,17 @@ class loginApiController extends nodefony.Controller {
|
|
|
61
60
|
}
|
|
62
61
|
const token = this.jwtFactory.generateJwtToken(
|
|
63
62
|
this.context.token.serialize(),
|
|
64
|
-
this.jwtSettings.token
|
|
63
|
+
this.jwtSettings.token
|
|
64
|
+
);
|
|
65
65
|
const refreshToken = await this.jwtFactory.generateJwtRefreshToken(
|
|
66
66
|
this.context.token.user.username,
|
|
67
67
|
token,
|
|
68
|
-
this.jwtSettings.refreshToken
|
|
68
|
+
this.jwtSettings.refreshToken
|
|
69
|
+
);
|
|
69
70
|
return this.api.render({
|
|
70
71
|
decodedToken: this.jwtFactory.decodeJwtToken(token),
|
|
71
|
-
token
|
|
72
|
-
refreshToken
|
|
72
|
+
token,
|
|
73
|
+
refreshToken
|
|
73
74
|
});
|
|
74
75
|
} catch (e) {
|
|
75
76
|
throw this.createException(e, 401);
|
|
@@ -84,7 +85,7 @@ class loginApiController extends nodefony.Controller {
|
|
|
84
85
|
* )
|
|
85
86
|
* @Firewall ({bypass:true})
|
|
86
87
|
*/
|
|
87
|
-
async tokenAction() {
|
|
88
|
+
async tokenAction () {
|
|
88
89
|
try {
|
|
89
90
|
// get refreshToken from request
|
|
90
91
|
let sessionToken = null;
|
|
@@ -98,13 +99,13 @@ class loginApiController extends nodefony.Controller {
|
|
|
98
99
|
throw this.createSecurityException("refreshToken parameter Not found");
|
|
99
100
|
}
|
|
100
101
|
// verify refreshToken expired
|
|
101
|
-
|
|
102
|
+
const refresh = await this.jwtFactory.verifyRefreshToken(refreshToken)
|
|
102
103
|
.catch((e) => {
|
|
103
104
|
throw this.createSecurityException(e);
|
|
104
105
|
});
|
|
105
|
-
const username = refresh.data
|
|
106
|
+
const {username} = refresh.data;
|
|
106
107
|
if (!username) {
|
|
107
|
-
throw this.createSecurityException(
|
|
108
|
+
throw this.createSecurityException("username not valid");
|
|
108
109
|
}
|
|
109
110
|
const dtuser = await this.usersService.findOne(username);
|
|
110
111
|
// controll user enabled
|
|
@@ -116,10 +117,10 @@ class loginApiController extends nodefony.Controller {
|
|
|
116
117
|
await this.jwtFactory.updateJwtRefreshToken(dtuser.username, token, refreshToken);
|
|
117
118
|
return this.api.render({
|
|
118
119
|
decodedToken: this.jwtFactory.decodeJwtToken(token),
|
|
119
|
-
token
|
|
120
|
+
token
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
|
-
throw this.createSecurityException(
|
|
123
|
+
throw this.createSecurityException("User not valid");
|
|
123
124
|
} catch (e) {
|
|
124
125
|
throw this.createException(e);
|
|
125
126
|
}
|
|
@@ -131,9 +132,8 @@ class loginApiController extends nodefony.Controller {
|
|
|
131
132
|
* "/refresh",
|
|
132
133
|
* name="api-login-jwt-refresh"
|
|
133
134
|
* )
|
|
134
|
-
* @Firewall ({bypass:true})
|
|
135
135
|
*/
|
|
136
|
-
async refreshAction() {
|
|
136
|
+
async refreshAction () {
|
|
137
137
|
// get refreshToken from request
|
|
138
138
|
let sessionToken = null;
|
|
139
139
|
let sessionRefreshToken = null;
|
|
@@ -150,29 +150,30 @@ class loginApiController extends nodefony.Controller {
|
|
|
150
150
|
throw this.createSecurityException("refreshToken or token parameter Not found");
|
|
151
151
|
}
|
|
152
152
|
// verify refreshToken expired
|
|
153
|
-
|
|
153
|
+
const refresh = await this.jwtFactory.verifyRefreshToken(refreshToken)
|
|
154
154
|
.catch((e) => {
|
|
155
155
|
throw this.createSecurityException(e);
|
|
156
156
|
});
|
|
157
|
-
const username = refresh.data
|
|
157
|
+
const {username} = refresh.data;
|
|
158
158
|
if (!username) {
|
|
159
|
-
throw this.createSecurityException(
|
|
159
|
+
throw this.createSecurityException("username not valid");
|
|
160
160
|
}
|
|
161
161
|
const dtuser = await this.usersService.findOne(username);
|
|
162
162
|
// controll user enabled
|
|
163
163
|
if (dtuser && dtuser.enabled) {
|
|
164
|
-
await this.jwtFactory.truncateJwtToken(this.context.token.user.username)
|
|
164
|
+
await this.jwtFactory.truncateJwtToken(this.context.token.user.username);
|
|
165
165
|
const refreshToken = await this.jwtFactory.generateJwtRefreshToken(
|
|
166
166
|
this.context.token.user.username,
|
|
167
167
|
token,
|
|
168
|
-
this.jwtSettings.refreshToken
|
|
168
|
+
this.jwtSettings.refreshToken
|
|
169
|
+
);
|
|
169
170
|
return this.api.render({
|
|
170
171
|
decodedToken: this.jwtFactory.decodeJwtToken(token),
|
|
171
|
-
token
|
|
172
|
-
refreshToken
|
|
172
|
+
token,
|
|
173
|
+
refreshToken
|
|
173
174
|
});
|
|
174
175
|
}
|
|
175
|
-
throw this.createSecurityException(
|
|
176
|
+
throw this.createSecurityException("User not valid");
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
/**
|
|
@@ -182,9 +183,9 @@ class loginApiController extends nodefony.Controller {
|
|
|
182
183
|
* name="api-login-jwt-truncate"
|
|
183
184
|
* )
|
|
184
185
|
*/
|
|
185
|
-
async truncateAction() {
|
|
186
|
+
async truncateAction () {
|
|
186
187
|
try {
|
|
187
|
-
|
|
188
|
+
const res = await this.jwtFactory.truncateJwtToken(this.query.username);
|
|
188
189
|
return this.api.render({
|
|
189
190
|
nbDeleted: res
|
|
190
191
|
});
|
|
@@ -197,15 +198,12 @@ class loginApiController extends nodefony.Controller {
|
|
|
197
198
|
* @Method ({"POST"})
|
|
198
199
|
* @Route ("/logout", name="api-login-jwt-logout")
|
|
199
200
|
*/
|
|
200
|
-
logoutAction() {
|
|
201
|
+
logoutAction () {
|
|
201
202
|
return this.logout()
|
|
202
|
-
.then(() => {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}).catch((e) => {
|
|
207
|
-
return this.api.render(e, 500);
|
|
208
|
-
});
|
|
203
|
+
.then(() => this.api.render({
|
|
204
|
+
logout: "ok"
|
|
205
|
+
}))
|
|
206
|
+
.catch((e) => this.api.render(e, 500));
|
|
209
207
|
}
|
|
210
208
|
}
|
|
211
209
|
|