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
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @Route ("/api/users")
|
|
3
3
|
*/
|
|
4
4
|
class restController extends nodefony.Controller {
|
|
5
|
-
|
|
6
|
-
constructor(container, context) {
|
|
5
|
+
constructor (container, context) {
|
|
7
6
|
super(container, context);
|
|
8
7
|
// service entity
|
|
9
8
|
this.usersService = this.get("users");
|
|
@@ -16,10 +15,10 @@ class restController extends nodefony.Controller {
|
|
|
16
15
|
}, this.context);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
checkAuthorisation(username, query) {
|
|
20
|
-
|
|
18
|
+
checkAuthorisation (username, query) {
|
|
19
|
+
const granted = this.is_granted("ROLE_ADMIN");
|
|
21
20
|
if (username) {
|
|
22
|
-
|
|
21
|
+
const user = this.getUser();
|
|
23
22
|
if (!user) {
|
|
24
23
|
throw new nodefony.authorizationError("Unauthorized", 401, this.context);
|
|
25
24
|
}
|
|
@@ -28,13 +27,11 @@ class restController extends nodefony.Controller {
|
|
|
28
27
|
throw new nodefony.authorizationError("Unauthorized Role", 401, this.context);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
} else {
|
|
32
|
-
|
|
33
|
-
throw new nodefony.authorizationError("Unauthorized", 401, this.context);
|
|
34
|
-
}
|
|
30
|
+
} else if (!granted) {
|
|
31
|
+
throw new nodefony.authorizationError("Unauthorized", 401, this.context);
|
|
35
32
|
}
|
|
36
33
|
if (query && query.roles && query.roles.length) {
|
|
37
|
-
if (query.roles.indexOf("ROLE_ADMIN") >= 0 &&
|
|
34
|
+
if (query.roles.indexOf("ROLE_ADMIN") >= 0 && !granted) {
|
|
38
35
|
throw new nodefony.authorizationError("Unauthorized Role", 401, this.context);
|
|
39
36
|
}
|
|
40
37
|
}
|
|
@@ -48,7 +45,7 @@ class restController extends nodefony.Controller {
|
|
|
48
45
|
* )
|
|
49
46
|
* @Firewall ({bypass:true})
|
|
50
47
|
*/
|
|
51
|
-
swaggerAction() {
|
|
48
|
+
swaggerAction () {
|
|
52
49
|
return this.optionsAction();
|
|
53
50
|
}
|
|
54
51
|
|
|
@@ -56,9 +53,9 @@ class restController extends nodefony.Controller {
|
|
|
56
53
|
* @Method ({"OPTIONS"})
|
|
57
54
|
* @Route ( "",name="api-users-options")
|
|
58
55
|
*/
|
|
59
|
-
optionsAction() {
|
|
56
|
+
optionsAction () {
|
|
60
57
|
try {
|
|
61
|
-
|
|
58
|
+
const openApiConfig = require(path.resolve(this.bundle.path, "Resources", "swagger", "openapi", "users.js"));
|
|
62
59
|
return this.api.renderSchema(openApiConfig, this.usersService.entity);
|
|
63
60
|
} catch (e) {
|
|
64
61
|
return this.api.renderError(e, 400);
|
|
@@ -69,7 +66,7 @@ class restController extends nodefony.Controller {
|
|
|
69
66
|
* @Method ({"GET"})
|
|
70
67
|
* @Route ( "/{username}",name="api-user",defaults={"username" = ""})
|
|
71
68
|
*/
|
|
72
|
-
async getAction(username) {
|
|
69
|
+
async getAction (username) {
|
|
73
70
|
let result = null;
|
|
74
71
|
const user = this.getUser();
|
|
75
72
|
try {
|
|
@@ -94,7 +91,7 @@ class restController extends nodefony.Controller {
|
|
|
94
91
|
* @Method ({"HEAD"})
|
|
95
92
|
* @Route ( "",name="api-users-head",)
|
|
96
93
|
*/
|
|
97
|
-
headAction() {
|
|
94
|
+
headAction () {
|
|
98
95
|
return this.renderResponse("");
|
|
99
96
|
}
|
|
100
97
|
|
|
@@ -102,14 +99,14 @@ class restController extends nodefony.Controller {
|
|
|
102
99
|
* @Method ({"POST"})
|
|
103
100
|
* @Route ( "",name="api-users-post")
|
|
104
101
|
*/
|
|
105
|
-
async postAction() {
|
|
102
|
+
async postAction () {
|
|
106
103
|
let myuser = null;
|
|
107
104
|
let error = null;
|
|
108
105
|
if (!this.query.password || !this.query.confirm) {
|
|
109
|
-
error = new Error(
|
|
106
|
+
error = new Error("Password can't be empty");
|
|
110
107
|
}
|
|
111
108
|
if (this.query.password !== this.query.confirm) {
|
|
112
|
-
error = new Error(
|
|
109
|
+
error = new Error("Bad confirm password");
|
|
113
110
|
}
|
|
114
111
|
if (error) {
|
|
115
112
|
this.logger(error, "ERROR");
|
|
@@ -117,12 +114,12 @@ class restController extends nodefony.Controller {
|
|
|
117
114
|
}
|
|
118
115
|
try {
|
|
119
116
|
this.checkAuthorisation(null, this.query);
|
|
120
|
-
const user = this.getUser()
|
|
117
|
+
const user = this.getUser();
|
|
121
118
|
myuser = await this.usersService.create(this.query, user);
|
|
122
119
|
if (myuser) {
|
|
123
120
|
delete myuser.password;
|
|
124
121
|
delete myuser["2fa-token"];
|
|
125
|
-
|
|
122
|
+
const res = {
|
|
126
123
|
query: this.query,
|
|
127
124
|
user: myuser
|
|
128
125
|
};
|
|
@@ -142,24 +139,24 @@ class restController extends nodefony.Controller {
|
|
|
142
139
|
* @Method ({"PUT"})
|
|
143
140
|
* @Route ( "/{username}",name="api-user-put")
|
|
144
141
|
*/
|
|
145
|
-
async putAction(username) {
|
|
142
|
+
async putAction (username) {
|
|
146
143
|
this.checkAuthorisation(this.query.username, this.query);
|
|
147
|
-
const user = this.getUser()
|
|
144
|
+
const user = this.getUser();
|
|
148
145
|
return this.usersService.findOne(username, user)
|
|
149
146
|
.then(async (myuser) => {
|
|
150
147
|
if (myuser) {
|
|
151
148
|
if (this.query.password) {
|
|
152
|
-
let confirm = false
|
|
149
|
+
let confirm = false;
|
|
153
150
|
if (this.query.confirm) {
|
|
154
151
|
if (this.query.password !== this.query.confirm) {
|
|
155
|
-
throw new Error(
|
|
152
|
+
throw new Error("Bad confirm password");
|
|
156
153
|
}
|
|
157
154
|
delete this.query.confirm;
|
|
158
155
|
confirm = true;
|
|
159
156
|
}
|
|
160
157
|
if (this.query["old-password"]) {
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
const encoder = this.getNodefonyEntity("user").getEncoder();
|
|
159
|
+
const check = await encoder.isPasswordValid(this.query["old-password"], myuser.password);
|
|
163
160
|
if (!check) {
|
|
164
161
|
throw new Error(`User ${username} bad passport`);
|
|
165
162
|
}
|
|
@@ -172,9 +169,9 @@ class restController extends nodefony.Controller {
|
|
|
172
169
|
}
|
|
173
170
|
return this.usersService.update(myuser, this.query, user)
|
|
174
171
|
.then(async (res) => {
|
|
175
|
-
|
|
172
|
+
const message = `Update User ${this.query.username} OK`;
|
|
176
173
|
this.log(message, "INFO");
|
|
177
|
-
|
|
174
|
+
const currentUser = this.getUser();
|
|
178
175
|
if (this.session && myuser.username === currentUser.username) {
|
|
179
176
|
if (this.query.username !== myuser.username) {
|
|
180
177
|
currentUser.username = this.query.username;
|
|
@@ -183,7 +180,7 @@ class restController extends nodefony.Controller {
|
|
|
183
180
|
this.session.set("lang", this.query.lang);
|
|
184
181
|
}
|
|
185
182
|
}
|
|
186
|
-
|
|
183
|
+
const newUser = await this.usersService.findOne(this.query.username, user);
|
|
187
184
|
delete newUser.password;
|
|
188
185
|
delete newUser["2fa-token"];
|
|
189
186
|
return this.api.render({
|
|
@@ -204,8 +201,8 @@ class restController extends nodefony.Controller {
|
|
|
204
201
|
* @Method ({"PATCH"})
|
|
205
202
|
* @Route ( "/{username}",name="api-user-patch")
|
|
206
203
|
*/
|
|
207
|
-
|
|
208
|
-
async patchAction(username) {
|
|
204
|
+
// TODO
|
|
205
|
+
async patchAction (username) {
|
|
209
206
|
this.log(username);
|
|
210
207
|
}
|
|
211
208
|
|
|
@@ -213,16 +210,16 @@ class restController extends nodefony.Controller {
|
|
|
213
210
|
* @Method ({"DELETE"})
|
|
214
211
|
* @Route ( "/{username}",name="api-user-delete")
|
|
215
212
|
*/
|
|
216
|
-
async deleteAction(username) {
|
|
213
|
+
async deleteAction (username) {
|
|
217
214
|
try {
|
|
218
215
|
this.checkAuthorisation(this.query.username, this.query);
|
|
219
|
-
const user = this.getUser()
|
|
216
|
+
const user = this.getUser();
|
|
220
217
|
return this.usersService.delete(username, user)
|
|
221
218
|
.then((user) => {
|
|
222
219
|
delete user.password;
|
|
223
220
|
delete user["2fa-token"];
|
|
224
221
|
return this.api.render({
|
|
225
|
-
user
|
|
222
|
+
user
|
|
226
223
|
});
|
|
227
224
|
})
|
|
228
225
|
.catch((error) => {
|
|
@@ -237,12 +234,11 @@ class restController extends nodefony.Controller {
|
|
|
237
234
|
* @Method ({"TRACE"})
|
|
238
235
|
*
|
|
239
236
|
*/
|
|
240
|
-
traceAction() {
|
|
237
|
+
traceAction () {
|
|
241
238
|
return this.renderResponse(JSON.stringify(this.request.request.headers, null, " "), 200, {
|
|
242
239
|
"Content-Type": "message/http"
|
|
243
240
|
});
|
|
244
241
|
}
|
|
245
|
-
|
|
246
242
|
}
|
|
247
243
|
|
|
248
244
|
module.exports = restController;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
class loginController extends nodefony.controller {
|
|
2
|
-
|
|
3
|
-
constructor(container, context) {
|
|
2
|
+
constructor (container, context) {
|
|
4
3
|
super(container, context);
|
|
5
4
|
this.startSession();
|
|
6
5
|
}
|
|
@@ -12,7 +11,7 @@ class loginController extends nodefony.controller {
|
|
|
12
11
|
* name="secure-login"
|
|
13
12
|
* )
|
|
14
13
|
*/
|
|
15
|
-
secureAction() {
|
|
14
|
+
secureAction () {
|
|
16
15
|
return this.loginCheckAction();
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -23,8 +22,8 @@ class loginController extends nodefony.controller {
|
|
|
23
22
|
* name="login"
|
|
24
23
|
* )
|
|
25
24
|
*/
|
|
26
|
-
loginAction() {
|
|
27
|
-
|
|
25
|
+
loginAction () {
|
|
26
|
+
const token = this.getToken();
|
|
28
27
|
if (this.session && token) {
|
|
29
28
|
return this.redirectToRoute("home");
|
|
30
29
|
}
|
|
@@ -38,39 +37,38 @@ class loginController extends nodefony.controller {
|
|
|
38
37
|
* name="login-check"
|
|
39
38
|
* )
|
|
40
39
|
*/
|
|
41
|
-
loginCheckAction(lastUrl) {
|
|
42
|
-
//console.log(lastUrl)
|
|
40
|
+
loginCheckAction (lastUrl) {
|
|
41
|
+
// console.log(lastUrl)
|
|
43
42
|
try {
|
|
44
|
-
|
|
43
|
+
const token = this.getToken();
|
|
45
44
|
if (token.user && token.user.enabled) {
|
|
46
45
|
if (lastUrl) {
|
|
47
46
|
return this.redirect(lastUrl);
|
|
48
47
|
}
|
|
49
48
|
return this.redirectToRoute("home");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.log(error, "ERROR");
|
|
61
|
-
this.setFlashBag("error", error.message);
|
|
62
|
-
} else {
|
|
63
|
-
error = new nodefony.securityError(
|
|
64
|
-
`No Auth Token`,
|
|
65
|
-
401,
|
|
66
|
-
this.context.security,
|
|
67
|
-
this.context
|
|
68
|
-
);
|
|
69
|
-
}
|
|
49
|
+
}
|
|
50
|
+
this.session.invalidate();
|
|
51
|
+
let error = null;
|
|
52
|
+
if (token && !token.user.enabled) {
|
|
53
|
+
error = new nodefony.securityError(
|
|
54
|
+
`User ${token.user.username} Disabled `,
|
|
55
|
+
401,
|
|
56
|
+
this.context.security,
|
|
57
|
+
this.context
|
|
58
|
+
);
|
|
70
59
|
this.log(error, "ERROR");
|
|
71
60
|
this.setFlashBag("error", error.message);
|
|
72
|
-
|
|
61
|
+
} else {
|
|
62
|
+
error = new nodefony.securityError(
|
|
63
|
+
"No Auth Token",
|
|
64
|
+
401,
|
|
65
|
+
this.context.security,
|
|
66
|
+
this.context
|
|
67
|
+
);
|
|
73
68
|
}
|
|
69
|
+
this.log(error, "ERROR");
|
|
70
|
+
this.setFlashBag("error", error.message);
|
|
71
|
+
return this.redirectToRoute("login");
|
|
74
72
|
} catch (e) {
|
|
75
73
|
throw e;
|
|
76
74
|
}
|
|
@@ -80,16 +78,14 @@ class loginController extends nodefony.controller {
|
|
|
80
78
|
* @Method ({ "GET"})
|
|
81
79
|
* @Route ("/logout", name="logout")
|
|
82
80
|
*/
|
|
83
|
-
logoutAction() {
|
|
81
|
+
logoutAction () {
|
|
84
82
|
return this.logout()
|
|
85
|
-
.then(() =>
|
|
86
|
-
|
|
87
|
-
}).catch((e) => {
|
|
83
|
+
.then(() => this.redirectToRoute("login"))
|
|
84
|
+
.catch((e) => {
|
|
88
85
|
this.log(e, "ERROR");
|
|
89
86
|
return this.redirectToRoute("login");
|
|
90
87
|
});
|
|
91
88
|
}
|
|
92
|
-
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
module.exports = loginController;
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @Route ("/users")
|
|
3
3
|
*/
|
|
4
4
|
class usersController extends nodefony.Controller {
|
|
5
|
-
|
|
6
|
-
constructor(container, context) {
|
|
5
|
+
constructor (container, context) {
|
|
7
6
|
super(container, context);
|
|
8
7
|
// start session
|
|
9
8
|
this.startSession();
|
|
@@ -15,12 +14,10 @@ class usersController extends nodefony.Controller {
|
|
|
15
14
|
this.translation = this.get("translation");
|
|
16
15
|
this.usersService = this.get("users");
|
|
17
16
|
|
|
18
|
-
this.on("onError", (error, route, variables) =>
|
|
19
|
-
return this.onError(error, route, variables);
|
|
20
|
-
});
|
|
17
|
+
this.on("onError", (error, route, variables) => this.onError(error, route, variables));
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
onError(e, route, variables) {
|
|
20
|
+
onError (e, route, variables) {
|
|
24
21
|
try {
|
|
25
22
|
if (e.errorType === "csrfError") {
|
|
26
23
|
this.setFlashBag("error", e.message);
|
|
@@ -35,7 +32,7 @@ class usersController extends nodefony.Controller {
|
|
|
35
32
|
/**
|
|
36
33
|
*
|
|
37
34
|
*/
|
|
38
|
-
headerAction() {
|
|
35
|
+
headerAction () {
|
|
39
36
|
return this.render("users::header.html.twig", {
|
|
40
37
|
langs: this.get("translation").getLangs(),
|
|
41
38
|
locale: this.getLocale(),
|
|
@@ -46,10 +43,10 @@ class usersController extends nodefony.Controller {
|
|
|
46
43
|
/**
|
|
47
44
|
*
|
|
48
45
|
*/
|
|
49
|
-
footerAction() {
|
|
50
|
-
|
|
46
|
+
footerAction () {
|
|
47
|
+
const {version} = this.kernel.settings;
|
|
51
48
|
return this.render("users::footer.html.twig", {
|
|
52
|
-
version
|
|
49
|
+
version,
|
|
53
50
|
year: new Date().getFullYear()
|
|
54
51
|
});
|
|
55
52
|
}
|
|
@@ -59,17 +56,17 @@ class usersController extends nodefony.Controller {
|
|
|
59
56
|
* @Method ({ "GET", "POST"})
|
|
60
57
|
* @Route ("/lang", name="lang")
|
|
61
58
|
*/
|
|
62
|
-
langAction() {
|
|
59
|
+
langAction () {
|
|
63
60
|
if (this.query.language) {
|
|
64
61
|
if (this.session) {
|
|
65
62
|
this.session.set("lang", this.query.language);
|
|
66
|
-
|
|
63
|
+
const route = this.session.getMetaBag("lastRoute");
|
|
67
64
|
if (route) {
|
|
68
65
|
return this.redirect(this.url(route));
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
68
|
}
|
|
72
|
-
|
|
69
|
+
const referer = this.request.getHeader("referer");
|
|
73
70
|
if (referer) {
|
|
74
71
|
return this.redirect(referer);
|
|
75
72
|
}
|
|
@@ -81,11 +78,11 @@ class usersController extends nodefony.Controller {
|
|
|
81
78
|
* @Route ( "/create", name="nodefony-user-create")
|
|
82
79
|
*
|
|
83
80
|
*/
|
|
84
|
-
createAction() {
|
|
81
|
+
createAction () {
|
|
85
82
|
const user = this.getUser();
|
|
86
83
|
switch (this.method) {
|
|
87
84
|
case "GET":
|
|
88
|
-
|
|
85
|
+
const size = Object.keys(this.queryGet).length;
|
|
89
86
|
if (size) {
|
|
90
87
|
if (this.queryGet.roles) {
|
|
91
88
|
this.queryGet.roles = this.queryGet.roles.split(",");
|
|
@@ -102,10 +99,10 @@ class usersController extends nodefony.Controller {
|
|
|
102
99
|
// FORM DATA
|
|
103
100
|
let error = null;
|
|
104
101
|
if (!this.query.password || !this.query.confirm) {
|
|
105
|
-
error = new Error(
|
|
102
|
+
error = new Error("Password can't be empty");
|
|
106
103
|
}
|
|
107
104
|
if (this.query.password !== this.query.confirm) {
|
|
108
|
-
error = new Error(
|
|
105
|
+
error = new Error("Bad confirm password");
|
|
109
106
|
}
|
|
110
107
|
if (error) {
|
|
111
108
|
this.setFlashBag("error", error.message);
|
|
@@ -122,13 +119,13 @@ class usersController extends nodefony.Controller {
|
|
|
122
119
|
this.checkAuthorisation(null, this.query);
|
|
123
120
|
return this.usersService.create(this.query, user)
|
|
124
121
|
.then((user) => {
|
|
125
|
-
|
|
122
|
+
const message = `${this.translate("added", "users")} ${user.username}`;
|
|
126
123
|
this.setFlashBag("info", message);
|
|
127
124
|
this.log(message, "INFO");
|
|
128
125
|
return this.redirectToRoute("home");
|
|
129
126
|
})
|
|
130
127
|
.catch((error) => {
|
|
131
|
-
//console.log(error)
|
|
128
|
+
// console.log(error)
|
|
132
129
|
this.log(error, "ERROR");
|
|
133
130
|
this.setFlashBag("error", error.message);
|
|
134
131
|
delete this.query.password;
|
|
@@ -146,8 +143,8 @@ class usersController extends nodefony.Controller {
|
|
|
146
143
|
* @Method ({"GET","POST"})
|
|
147
144
|
* @Route ( "/update/{username}", name="nodefony-user-update")
|
|
148
145
|
*/
|
|
149
|
-
updateAction(username) {
|
|
150
|
-
|
|
146
|
+
updateAction (username) {
|
|
147
|
+
const user = this.getUser();
|
|
151
148
|
this.checkAuthorisation(username, this.query);
|
|
152
149
|
switch (this.method) {
|
|
153
150
|
case "GET":
|
|
@@ -161,7 +158,8 @@ class usersController extends nodefony.Controller {
|
|
|
161
158
|
});
|
|
162
159
|
}
|
|
163
160
|
throw new Error(`User ${username} not found`);
|
|
164
|
-
})
|
|
161
|
+
})
|
|
162
|
+
.catch((e) => {
|
|
165
163
|
throw e;
|
|
166
164
|
});
|
|
167
165
|
case "POST":
|
|
@@ -171,7 +169,7 @@ class usersController extends nodefony.Controller {
|
|
|
171
169
|
if (nodefony.typeOf(this.query.roles) === "string") {
|
|
172
170
|
this.query.roles = [this.query.roles];
|
|
173
171
|
}
|
|
174
|
-
|
|
172
|
+
const value = {
|
|
175
173
|
username: this.query.username || null,
|
|
176
174
|
email: this.query.email,
|
|
177
175
|
name: this.query.name,
|
|
@@ -184,29 +182,27 @@ class usersController extends nodefony.Controller {
|
|
|
184
182
|
if (this.query.password && this.isGranted("ROLE_ADMIN")) {
|
|
185
183
|
let error = null;
|
|
186
184
|
if (this.query.password && this.query.password !== this.query.confirm) {
|
|
187
|
-
error = new Error(
|
|
185
|
+
error = new Error("Bad confirm password");
|
|
188
186
|
}
|
|
189
187
|
if (error) {
|
|
190
188
|
throw error;
|
|
191
189
|
}
|
|
192
190
|
value.password = this.query.password;
|
|
193
|
-
} else {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
throw new Error(`User ${username} bad passport`);
|
|
201
|
-
}
|
|
191
|
+
} else if (this.query.password && this.query["old-passwd"]) {
|
|
192
|
+
const encoder = this.getNodefonyEntity("user").getEncoder();
|
|
193
|
+
const check = await encoder.isPasswordValid(this.query["old-passwd"], myuser.password);
|
|
194
|
+
if (check) {
|
|
195
|
+
value.password = this.query.password;
|
|
196
|
+
} else {
|
|
197
|
+
throw new Error(`User ${username} bad passport`);
|
|
202
198
|
}
|
|
203
199
|
}
|
|
204
200
|
return this.usersService.update(myuser, value, user)
|
|
205
201
|
.then(() => {
|
|
206
|
-
|
|
202
|
+
const message = `Update User ${this.query.username} OK`;
|
|
207
203
|
this.setFlashBag("info", message);
|
|
208
204
|
this.log(message, "INFO");
|
|
209
|
-
|
|
205
|
+
const currentUser = this.getUser();
|
|
210
206
|
if (myuser.username === currentUser.username) {
|
|
211
207
|
if (this.query.username !== myuser.username) {
|
|
212
208
|
currentUser.username = this.query.username;
|
|
@@ -214,11 +210,9 @@ class usersController extends nodefony.Controller {
|
|
|
214
210
|
if (this.getLocale() !== this.query.lang) {
|
|
215
211
|
this.session.set("lang", this.query.lang);
|
|
216
212
|
}
|
|
217
|
-
|
|
213
|
+
const token = this.getToken();
|
|
218
214
|
return token.refreshToken(this.context)
|
|
219
|
-
.then(() =>
|
|
220
|
-
return this.redirectToRoute("home");
|
|
221
|
-
})
|
|
215
|
+
.then(() => this.redirectToRoute("home"))
|
|
222
216
|
.catch((error) => {
|
|
223
217
|
throw error;
|
|
224
218
|
});
|
|
@@ -232,7 +226,7 @@ class usersController extends nodefony.Controller {
|
|
|
232
226
|
this.setFlashBag("error", error.message);
|
|
233
227
|
this.log(error, "ERROR");
|
|
234
228
|
return this.redirectToRoute("nodefony-user-update", {
|
|
235
|
-
username
|
|
229
|
+
username
|
|
236
230
|
});
|
|
237
231
|
});
|
|
238
232
|
default:
|
|
@@ -245,25 +239,26 @@ class usersController extends nodefony.Controller {
|
|
|
245
239
|
* @Route ("/delete/{username}", name="nodefony-user-delete")
|
|
246
240
|
*
|
|
247
241
|
*/
|
|
248
|
-
deleteAction(username) {
|
|
249
|
-
|
|
242
|
+
deleteAction (username) {
|
|
243
|
+
const user = this.getUser();
|
|
250
244
|
this.checkAuthorisation(username);
|
|
251
245
|
if (username) {
|
|
252
246
|
return this.usersService.delete(username, user)
|
|
253
247
|
.then((result) => {
|
|
254
|
-
|
|
248
|
+
const message = `Delete User ${result.username} OK`;
|
|
255
249
|
this.setFlashBag("info", message);
|
|
256
250
|
if (this.getUser().username === username) {
|
|
257
251
|
this.session.invalidate();
|
|
258
252
|
}
|
|
259
253
|
return this.redirectToRoute("nodefony-user");
|
|
260
|
-
})
|
|
254
|
+
})
|
|
255
|
+
.catch((e) => {
|
|
261
256
|
this.log(e, "ERROR");
|
|
262
257
|
this.setFlashBag("error", e.message);
|
|
263
258
|
return this.redirectToRoute("nodefony-user");
|
|
264
259
|
});
|
|
265
260
|
}
|
|
266
|
-
|
|
261
|
+
const error = new nodefony.Error(`User ${username} not found`, this.context);
|
|
267
262
|
this.setFlashBag("error", error.message);
|
|
268
263
|
this.log(error, "ERROR");
|
|
269
264
|
return this.redirectToRoute("nodefony-user");
|
|
@@ -274,8 +269,8 @@ class usersController extends nodefony.Controller {
|
|
|
274
269
|
* @Route ( "/{username}",name="nodefony-user",defaults={"username" = ""})
|
|
275
270
|
*
|
|
276
271
|
*/
|
|
277
|
-
userAction(username) {
|
|
278
|
-
|
|
272
|
+
userAction (username) {
|
|
273
|
+
const user = this.getUser();
|
|
279
274
|
if (username) {
|
|
280
275
|
switch (this.method) {
|
|
281
276
|
case "PUT":
|
|
@@ -283,7 +278,7 @@ class usersController extends nodefony.Controller {
|
|
|
283
278
|
case "DELETE":
|
|
284
279
|
return this.deleteAction(username);
|
|
285
280
|
case "GET":
|
|
286
|
-
//const user = new User(this);
|
|
281
|
+
// const user = new User(this);
|
|
287
282
|
return this.usersService.findOne(username, user)
|
|
288
283
|
.then((result) => {
|
|
289
284
|
if (result) {
|
|
@@ -292,7 +287,8 @@ class usersController extends nodefony.Controller {
|
|
|
292
287
|
});
|
|
293
288
|
}
|
|
294
289
|
return this.render("users:users:readUsers.html.twig");
|
|
295
|
-
})
|
|
290
|
+
})
|
|
291
|
+
.catch((e) => {
|
|
296
292
|
throw e;
|
|
297
293
|
});
|
|
298
294
|
}
|
|
@@ -301,21 +297,20 @@ class usersController extends nodefony.Controller {
|
|
|
301
297
|
case "POST":
|
|
302
298
|
return this.createAction();
|
|
303
299
|
default:
|
|
304
|
-
return this.usersService.find(this.query,{}, user)
|
|
305
|
-
.then((result) => {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}).catch(e => {
|
|
300
|
+
return this.usersService.find(this.query, {}, user)
|
|
301
|
+
.then((result) => this.render("users:users:readUsers.html.twig", {
|
|
302
|
+
users: result.rows
|
|
303
|
+
}))
|
|
304
|
+
.catch((e) => {
|
|
310
305
|
throw e;
|
|
311
306
|
});
|
|
312
307
|
}
|
|
313
308
|
}
|
|
314
309
|
|
|
315
|
-
checkAuthorisation(username, query) {
|
|
316
|
-
|
|
310
|
+
checkAuthorisation (username, query) {
|
|
311
|
+
const granted = this.is_granted("ROLE_ADMIN");
|
|
317
312
|
if (username) {
|
|
318
|
-
|
|
313
|
+
const user = this.getUser();
|
|
319
314
|
if (!user) {
|
|
320
315
|
throw new nodefony.authorizationError("Unauthorized", 401, this.context);
|
|
321
316
|
}
|
|
@@ -326,13 +321,12 @@ class usersController extends nodefony.Controller {
|
|
|
326
321
|
}
|
|
327
322
|
}
|
|
328
323
|
if (query && query.role && query.role.length) {
|
|
329
|
-
if (query.role.indexOf("ROLE_ADMIN") >= 0 &&
|
|
324
|
+
if (query.role.indexOf("ROLE_ADMIN") >= 0 && !granted) {
|
|
330
325
|
throw new nodefony.authorizationError("Unauthorized Role", 401, this.context);
|
|
331
326
|
}
|
|
332
327
|
}
|
|
333
328
|
return true;
|
|
334
329
|
}
|
|
335
|
-
|
|
336
330
|
}
|
|
337
331
|
|
|
338
332
|
module.exports = usersController;
|