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.
Files changed (136) hide show
  1. package/CHANGELOG.md +534 -8028
  2. package/README.md +33 -30
  3. package/autoloader.es6 +46 -48
  4. package/builder.es6 +66 -76
  5. package/cli/builder/bundles/bundle.js +57 -63
  6. package/cli/builder/bundles/controller.js +34 -38
  7. package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
  8. package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
  9. package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +25 -30
  10. package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
  11. package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
  12. package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
  13. package/cli/builder/bundles/users-bundle/Resources/config/config.js +4 -3
  14. package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
  15. package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
  16. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
  17. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
  18. package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -75
  19. package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
  20. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
  21. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
  22. package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +13 -15
  23. package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
  24. package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
  25. package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -36
  26. package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
  27. package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
  28. package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
  29. package/cli/builder/bundles/users-bundle/package.json +27 -25
  30. package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
  31. package/cli/builder/bundles/users-bundle/readme.md +7 -7
  32. package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
  33. package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
  34. package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
  35. package/cli/builder/bundles/users-bundle/tests/loginTest.js +119 -70
  36. package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
  37. package/cli/builder/microService/microService.js +139 -141
  38. package/cli/builder/microService/skeletons/package.json +23 -22
  39. package/cli/builder/project/project.js +228 -181
  40. package/cli/builder/project/skeletons/README.md +33 -30
  41. package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
  42. package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
  43. package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
  44. package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
  45. package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
  46. package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
  47. package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
  48. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
  49. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
  50. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
  51. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
  52. package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
  53. package/cli/builder/project/skeletons/package.json.twig +70 -0
  54. package/cli/builder/react/reactBuilder.js +59 -65
  55. package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
  56. package/cli/builder/skeletons/app/appKernel.js +120 -2
  57. package/cli/builder/skeletons/config/config.js +1 -1
  58. package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
  59. package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
  60. package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -12
  61. package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
  62. package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
  63. package/cli/builder/skeletons/package.json.twig +57 -0
  64. package/cli/builder/skeletons/unittest/testFile.js +44 -45
  65. package/cli/builder/vue/skeletons/vue.config.js +84 -10
  66. package/cli/builder/vue/vueBuilder.js +116 -114
  67. package/cli/generate/generate.es6 +38 -39
  68. package/cli/install/install.js +45 -58
  69. package/cli/sequelize/sequelize.js +50 -39
  70. package/cli/start.js +353 -347
  71. package/cli/tools/pm2.es6 +55 -57
  72. package/cli/tools/tools.es6 +36 -37
  73. package/cli.es6 +280 -228
  74. package/container.es6 +51 -59
  75. package/error.es6 +25 -27
  76. package/fileClass.es6 +53 -55
  77. package/finder/file.es6 +5 -4
  78. package/finder/fileResult.es6 +23 -22
  79. package/finder/finder2.es6 +46 -54
  80. package/finder.es6 +88 -97
  81. package/kernel/annotations/annotations.es6 +44 -46
  82. package/kernel/api/api.es6 +6 -8
  83. package/kernel/api/graphqlApi.es6 +21 -21
  84. package/kernel/api/jsonApi.es6 +40 -45
  85. package/kernel/api/openApi.es6 +9 -11
  86. package/kernel/api/schemas/openApiSchema.js +61 -32
  87. package/kernel/babylon.es6 +31 -38
  88. package/kernel/bundle.es6 +252 -220
  89. package/kernel/cliKernel.es6 +157 -170
  90. package/kernel/command.es6 +17 -20
  91. package/kernel/commands/nodefonyCommand.es6 +111 -58
  92. package/kernel/commands/tasks/bundlesTask.es6 +14 -19
  93. package/kernel/controllers/controller.es6 +167 -180
  94. package/kernel/fixture.es6 +4 -7
  95. package/kernel/injections/injections.es6 +97 -103
  96. package/kernel/kernel.es6 +476 -384
  97. package/kernel/kernelWatcher.es6 +64 -54
  98. package/kernel/orm/entity.es6 +10 -12
  99. package/kernel/orm/orm.es6 +68 -48
  100. package/kernel/reader.es6 +45 -47
  101. package/kernel/security/encoder.es6 +8 -6
  102. package/kernel/security/factories/factory.es6 +34 -37
  103. package/kernel/security/factories/passeportFactory.es6 +13 -14
  104. package/kernel/security/provider.es6 +11 -13
  105. package/kernel/security/providers/chainProvider.es6 +13 -28
  106. package/kernel/security/providers/memoryProvider.es6 +7 -11
  107. package/kernel/security/providers/providerManager.es6 +11 -14
  108. package/kernel/security/providers/userEntityProvider.es6 +7 -8
  109. package/kernel/security/role.es6 +3 -3
  110. package/kernel/security/secureArea.es6 +143 -149
  111. package/kernel/security/tokens/token.es6 +30 -32
  112. package/kernel/security/user.es6 +19 -19
  113. package/kernel/serviceRealTime.es6 +5 -7
  114. package/kernel/services/connectionsService.es6 +20 -22
  115. package/kernel/services/cron/cronService.es6 +14 -16
  116. package/kernel/task.es6 +20 -26
  117. package/kernel/templates.es6 +4 -5
  118. package/kernel/templating/twig.es6 +56 -47
  119. package/kernel/tests/cliTest.js +7 -11
  120. package/kernel/tests/containerTest.js +25 -37
  121. package/kernel/tests/kernelTest.js +9 -16
  122. package/nodefony.es6 +279 -256
  123. package/notificationsCenter.es6 +28 -20
  124. package/package.json +40 -40
  125. package/protocol.es6 +19 -21
  126. package/protocols/bayeux.es6 +35 -38
  127. package/protocols/jsonRpc/jsonrpc.es6 +12 -14
  128. package/result.es6 +11 -12
  129. package/service.es6 +62 -62
  130. package/syslog/pdu.es6 +99 -91
  131. package/syslog/syslog.es6 +101 -102
  132. package/watcher.es6 +21 -20
  133. package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
  134. package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
  135. package/cli/builder/project/skeletons/package.json.skeleton +0 -52
  136. package/cli/builder/skeletons/package.json +0 -61
@@ -1,53 +1,50 @@
1
1
  class providerManager extends nodefony.Service {
2
-
3
- constructor(firewall, providers = []) {
2
+ constructor (firewall, providers = []) {
4
3
  super("providerManager", firewall.container);
5
4
  this.providers = providers || [];
6
5
  this.nbProviders = 0;
7
6
  }
8
7
 
9
- getProvider(name) {
8
+ getProvider (name) {
10
9
  if (this.providers[name]) {
11
10
  return this.providers[name];
12
11
  }
13
12
  throw new Error(`Provider : ${name} nor found`);
14
13
  }
15
14
 
16
- getProviders(name) {
15
+ getProviders (name) {
17
16
  if (name) {
18
17
  return this.getProvider(name);
19
18
  }
20
19
  return this.providers;
21
20
  }
22
21
 
23
- addConfiguration(name, config) {
22
+ addConfiguration (name, config) {
24
23
  if (name in this.providers) {
25
24
  this.log(`Provider ${name} already exist`, "WARNING");
26
25
  return null;
27
26
  }
28
27
  if (config) {
29
- this.kernel.prependOnceListener("onBoot", async() => {
28
+ this.kernel.prependOnceListener("onBoot", async () => {
30
29
  switch (true) {
31
- case !!config.entity:
30
+ case Boolean(config.entity):
32
31
  if (config.class) {
33
32
  if (config.class in nodefony.security.providers) {
34
33
  this.providers[name] = new nodefony.security.providers[config.class](name, this, config.entity);
35
34
  } else {
36
35
  this.log(new Error(`provider class not exist : ${config.class}`), "ERROR");
37
36
  }
38
- } else {
39
- if ( nodefony.security.providers.userProvider ){
40
- this.providers[name] = new nodefony.security.providers.userProvider(name, this, config.entity);
41
- }
37
+ } else if (nodefony.security.providers.userProvider) {
38
+ this.providers[name] = new nodefony.security.providers.userProvider(name, this, config.entity);
42
39
  }
43
40
  break;
44
- case !!config.chain:
41
+ case Boolean(config.chain):
45
42
  this.providers[name] = new nodefony.security.providers.chainProvider(this, config.chain);
46
43
  break;
47
- case !!config.memory:
44
+ case Boolean(config.memory):
48
45
  this.providers[name] = new nodefony.security.providers.memoryProvider(this, config.memory);
49
46
  break;
50
- case !!config.anonymous:
47
+ case Boolean(config.anonymous):
51
48
  if (config.anonymous.provider) {
52
49
  if (this.providers[config.anonymous.provider]) {
53
50
  this.providers[name] = this.providers[config.anonymous.provider];
@@ -1,6 +1,5 @@
1
1
  class userEntityProvider extends nodefony.Provider {
2
-
3
- constructor(name, manager, config) {
2
+ constructor (name, manager, config) {
4
3
  super(name, manager);
5
4
  this.entityName = config.name || "user";
6
5
  this.userProperty = config.property || "username";
@@ -14,16 +13,16 @@ class userEntityProvider extends nodefony.Provider {
14
13
  });
15
14
  }
16
15
 
17
- getEntity(name) {
16
+ getEntity (name) {
18
17
  if (name) {
19
18
  return this.orm.getEntity(name);
20
19
  }
21
20
  return this.orm.getEntity(this.entityName);
22
21
  }
23
22
 
24
- async encodePassword(raw, salt) {
23
+ async encodePassword (raw, salt) {
25
24
  try {
26
- let ret = this.entity.hasEncoder();
25
+ const ret = this.entity.hasEncoder();
27
26
  if (ret) {
28
27
  return await this.encoder.encodePassword(raw, salt);
29
28
  }
@@ -33,11 +32,11 @@ class userEntityProvider extends nodefony.Provider {
33
32
  }
34
33
  }
35
34
 
36
- async isPasswordValid(raw, encoded) {
35
+ async isPasswordValid (raw, encoded) {
37
36
  try {
38
- let ret = this.entity.hasEncoder();
37
+ const ret = this.entity.hasEncoder();
39
38
  if (ret) {
40
- this.log(`Check Password Valid `, "DEBUG", `ENCODER ${this.encoder.name}`);
39
+ this.log("Check Password Valid ", "DEBUG", `ENCODER ${this.encoder.name}`);
41
40
  return await this.encoder.isPasswordValid(raw, encoded);
42
41
  }
43
42
  return await super.isPasswordValid(raw, encoded);
@@ -1,12 +1,12 @@
1
1
  class Role {
2
- constructor(role) {
2
+ constructor (role) {
3
3
  this.role = role;
4
4
  }
5
5
 
6
- getRole() {
6
+ getRole () {
7
7
  return this.role;
8
8
  }
9
9
  }
10
10
 
11
11
  nodefony.Role = Role;
12
- module.exports = Role;
12
+ module.exports = Role;
@@ -1,15 +1,14 @@
1
- module.exports = nodefony.register("SecuredArea", function () {
2
-
1
+ /* eslint-disable max-lines-per-function */
2
+ module.exports = nodefony.register("SecuredArea", () => {
3
3
  // context security
4
4
  class securedArea extends nodefony.Service {
5
-
6
- constructor(name, firewall) {
5
+ constructor (name, firewall) {
7
6
  super(name, firewall.container, firewall.notificationsCenter);
8
7
  this.firewall = firewall;
9
8
  this.router = this.get("router");
10
9
  this.sessionContext = "default";
11
10
  this.cors = null;
12
- this.pattern = /.*/;
11
+ this.pattern = /.*/u;
13
12
  this.factories = [];
14
13
  this.nbFactories = 0;
15
14
  this.provider = null;
@@ -26,37 +25,33 @@ module.exports = nodefony.register("SecuredArea", function () {
26
25
  if (this.providerName) {
27
26
  if (this.providerName in this.firewall.providerManager.providers) {
28
27
  this.provider = this.firewall.providerManager.getProvider(this.providerName);
29
- } else {
30
- if (this.anonymous) {
31
- this.providerName = "anonymous";
32
- this.provider = this.firewall.providerManager.getProvider("anonymous");
33
- } else {
34
- throw new Error(`Provider : ${this.providerName} not found in firewall ${this.name}`);
35
- }
36
- }
37
- } else {
38
- if (this.anonymous) {
28
+ } else if (this.anonymous) {
39
29
  this.providerName = "anonymous";
40
30
  this.provider = this.firewall.providerManager.getProvider("anonymous");
41
31
  } else {
42
- //this.providerName = null; //"nodefony";
43
- //this.provider = this.firewall.providerManager.getProvider("nodefony");
32
+ throw new Error(`Provider : ${this.providerName} not found in firewall ${this.name}`);
44
33
  }
34
+ } else if (this.anonymous) {
35
+ this.providerName = "anonymous";
36
+ this.provider = this.firewall.providerManager.getProvider("anonymous");
37
+ } else {
38
+ // this.providerName = null; //"nodefony";
39
+ // this.provider = this.firewall.providerManager.getProvider("nodefony");
45
40
  }
46
41
  } catch (e) {
47
- this.log(this.name + " " + e, "ERROR");
42
+ this.log(`${this.name} ${e}`, "ERROR");
48
43
  }
49
44
  });
50
45
  }
51
46
 
52
- log(pci, severity, msgid, msg) {
47
+ log (pci, severity, msgid, msg) {
53
48
  if (!msgid) {
54
- msgid = "\x1b[36mSECURE AREA \x1b[31m" + this.name + " \x1b[0m";
49
+ msgid = `\x1b[36mSECURE AREA \x1b[31m${this.name} \x1b[0m`;
55
50
  }
56
51
  return super.log(pci, severity, msgid, msg);
57
52
  }
58
53
 
59
- handleCrossDomain(context) {
54
+ handleCrossDomain (context) {
60
55
  let redirect = false;
61
56
  if (context.security.redirect_Https &&
62
57
  context.protocol === "https" &&
@@ -66,19 +61,22 @@ module.exports = nodefony.register("SecuredArea", function () {
66
61
  if (context.crossDomain) {
67
62
  if (this.cors) {
68
63
  return this.cors.match(context, redirect);
69
- } else {
70
- if (redirect) {
71
- return null;
72
- }
73
- return 401;
74
64
  }
65
+ if (redirect) {
66
+ return null;
67
+ }
68
+ if (context.originUrl.href === "*") {
69
+ return 200;
70
+ }
71
+ return 401;
75
72
  }
76
73
  }
77
74
 
78
- handleError(context, e) {
75
+ // eslint-disable-next-line complexity
76
+ handleError (context, e) {
79
77
  let securityError = null;
80
78
  switch (true) {
81
- case (e instanceof nodefony.securityError):
79
+ case e instanceof nodefony.securityError:
82
80
  securityError = e;
83
81
  break;
84
82
  default:
@@ -88,7 +86,7 @@ module.exports = nodefony.register("SecuredArea", function () {
88
86
  securityError.code = 401;
89
87
  }
90
88
  if (this.kernel.debug) {
91
- //this.log(securityError, "ERROR");
89
+ // this.log(securityError, "ERROR");
92
90
  }
93
91
  switch (context.type) {
94
92
  case "HTTP":
@@ -101,12 +99,12 @@ module.exports = nodefony.register("SecuredArea", function () {
101
99
  }
102
100
  if (this.formLogin) {
103
101
  if (context.session) {
104
- let area = context.session.getMetaBag("area");
102
+ const area = context.session.getMetaBag("area");
105
103
  if (area && area !== this.name) {
106
104
  context.session.clearFlashBag("default_target_path");
107
105
  }
108
106
  context.session.setMetaBag("area", this.name);
109
- let target_path = context.session.getFlashBag("default_target_path");
107
+ const target_path = context.session.getFlashBag("default_target_path");
110
108
  if (!target_path && context.method === "GET") {
111
109
  context.session.setFlashBag("default_target_path", context.request.url.pathname);
112
110
  }
@@ -115,7 +113,7 @@ module.exports = nodefony.register("SecuredArea", function () {
115
113
  }
116
114
  }
117
115
 
118
- /*if (context.session &&
116
+ /* if (context.session &&
119
117
  (context.request.url.pathname !== this.formLogin) &&
120
118
  (context.request.url.pathname !== this.checkLogin)
121
119
  ) {
@@ -141,10 +139,11 @@ module.exports = nodefony.register("SecuredArea", function () {
141
139
  if (context.isJson) {
142
140
  return securityError;
143
141
  }
144
- //return this.redirect(context, this.formLogin);
142
+ // return this.redirect(context, this.formLogin);
145
143
  context.resolver = this.overrideURL(context, this.formLogin);
146
144
  return context;
147
145
  } catch (e) {
146
+ // eslint-disable-next-line new-cap
148
147
  return new nodefony.securityError(e, 500, this, context);
149
148
  }
150
149
  } else {
@@ -153,22 +152,20 @@ module.exports = nodefony.register("SecuredArea", function () {
153
152
  }
154
153
  return securityError;
155
154
  }
156
- break;
157
155
  case "WEBSOCKET":
158
156
  case "WEBSOCKET SECURE":
159
157
  return securityError;
158
+ default:
160
159
  }
161
160
  }
162
161
 
163
- handleFactories(context, index = 1) {
162
+ handleFactories (context, index = 1) {
164
163
  return new Promise((resolve, reject) => {
165
164
  if (this.nbFactories) {
166
165
  try {
167
166
  this.log(`Try Authentication Factory ${this.factories[index - 1].name}`, "DEBUG");
168
167
  return this.factories[index - 1].handle(context)
169
- .then((token) => {
170
- return resolve(token);
171
- })
168
+ .then((token) => resolve(token))
172
169
  .catch((e) => {
173
170
  this.factories[index - 1].log(e, "DEBUG");
174
171
  if (index === this.nbFactories) {
@@ -185,108 +182,105 @@ module.exports = nodefony.register("SecuredArea", function () {
185
182
  });
186
183
  }
187
184
 
188
- handle(context) {
189
- return new Promise((resolve, reject) => {
190
- return this.handleFactories(context)
191
- .then((token) => {
192
- let target = this.defaultTarget;
193
- try {
194
- if (token) {
195
- context.user = token.user;
196
- context.token = token;
197
- } else {
198
- if (context.session) {
199
- context.session.setMetaBag("security", {
200
- firewall: this.name,
201
- token: null
202
- });
203
- if (context.user && context.user.lang) {
204
- context.session.set("lang", context.user.lang);
205
- } else {
206
- if( ! context.session.get("lang") ){
207
- context.session.set("lang", context.translation.defaultLocale);
208
- }
209
- }
210
- }
211
- return resolve(context);
212
- }
185
+ handle (context) {
186
+ // eslint-disable-next-line no-promise-executor-return
187
+ return new Promise((resolve, reject) => this.handleFactories(context)
188
+ .then((token) => {
189
+ let target = this.defaultTarget;
190
+ try {
191
+ if (token) {
192
+ context.user = token.user;
193
+ context.token = token;
194
+ } else {
213
195
  if (context.session) {
214
- //context.session.migrate();
215
196
  context.session.setMetaBag("security", {
216
197
  firewall: this.name,
217
- token: token ? token.serialize() : null
198
+ token: null
218
199
  });
219
200
  if (context.user && context.user.lang) {
220
201
  context.session.set("lang", context.user.lang);
221
- } else {
202
+ } else if (!context.session.get("lang")) {
222
203
  context.session.set("lang", context.translation.defaultLocale);
223
204
  }
224
- if (!this.alwaysUseDefaultTarget) {
225
- target = context.session.getFlashBag("default_target_path") || this.defaultTarget;
226
- } else {
227
- target = this.defaultTarget;
228
- }
229
- context.session.clearFlashBag("default_target_path");
230
- }
231
- } catch (e) {
232
- let res = this.handleError(context, e);
233
- if (res instanceof Error) {
234
- return reject(res);
235
- }
236
- return resolve(res);
237
- }
238
- if (this.checkLogin) {
239
- try {
240
- delete context.resolver;
241
- context.checkLogin = true;
242
- context.resolver = this.overrideURL(context, this.checkLogin, target);
243
- //context.resolver = this.router.resolveName(context, this.checkLogin);
244
- return resolve(context);
245
- } catch (e) {
246
- throw e;
247
205
  }
248
- }
249
- if (!target) {
250
206
  return resolve(context);
251
207
  }
252
- if (context.isJson) {
253
- context.resolver = this.overrideURL(context, target);
254
- return resolve(context);
255
- } else {
256
- return resolve(this.redirect(context, target));
257
- }
258
- return resolve(context);
259
- })
260
- .catch((error) => {
261
- if (!error) {
262
- error = new Error("");
208
+ if (context.session) {
209
+ // context.session.migrate();
210
+ context.session.setMetaBag("security", {
211
+ firewall: this.name,
212
+ token: token ? token.serialize() : null
213
+ });
214
+ if (context.user && context.user.lang) {
215
+ context.session.set("lang", context.user.lang);
216
+ } else {
217
+ context.session.set("lang", context.translation.defaultLocale);
218
+ }
219
+ if (!this.alwaysUseDefaultTarget) {
220
+ target = context.session.getFlashBag("default_target_path") || this.defaultTarget;
221
+ } else {
222
+ target = this.defaultTarget;
223
+ }
224
+ context.session.clearFlashBag("default_target_path");
263
225
  }
264
- let res = this.handleError(context, error);
226
+ } catch (e) {
227
+ const res = this.handleError(context, e);
265
228
  if (res instanceof Error) {
266
229
  return reject(res);
267
230
  }
268
231
  return resolve(res);
269
- });
270
- });
232
+ }
233
+ if (this.checkLogin) {
234
+ try {
235
+ delete context.resolver;
236
+ context.checkLogin = true;
237
+ context.resolver = this.overrideURL(context, this.checkLogin, target);
238
+ // context.resolver = this.router.resolveName(context, this.checkLogin);
239
+ return resolve(context);
240
+ } catch (e) {
241
+ throw e;
242
+ }
243
+ }
244
+ if (!target) {
245
+ return resolve(context);
246
+ }
247
+ if (context.isJson) {
248
+ context.resolver = this.overrideURL(context, target);
249
+ return resolve(context);
250
+ }
251
+ return resolve(this.redirect(context, target));
252
+ // return resolve(context);
253
+ })
254
+ .catch((error) => {
255
+ if (!error) {
256
+ error = new Error("");
257
+ }
258
+ const res = this.handleError(context, error);
259
+ if (res instanceof Error) {
260
+ return reject(res);
261
+ }
262
+ return resolve(res);
263
+ }));
271
264
  }
272
265
 
273
- logout(context) {
266
+ logout (context) {
274
267
  return new Promise(async (resolve, reject) => {
275
- let res = [];
276
- this.log("Logout factories","DEBUG");
277
- for await (let factorie of this.factories) {
278
- this.log(`Logout factory : ${factorie}`,"DEBUG")
268
+ const res = [];
269
+ this.log("Logout factories", "DEBUG");
270
+ for await (const factorie of this.factories) {
271
+ this.log(`Logout factory : ${factorie}`, "DEBUG");
279
272
  res.push(await factorie.logout(context));
280
273
  }
281
274
  if (context.session) {
282
- this.log(`Invalidate session Security : ${context.session.id}`,"DEBUG")
275
+ this.log(`Invalidate session Security : ${context.session.id}`, "DEBUG");
283
276
  return context.session.invalidate()
284
277
  .then(() => {
285
278
  if (this.formLogin) {
286
279
  return resolve(this.redirect(context, this.formLogin));
287
280
  }
288
281
  return resolve(context);
289
- }).catch(e => {
282
+ })
283
+ .catch((e) => {
290
284
  this.log(e, "ERROR");
291
285
  return reject(e);
292
286
  });
@@ -296,7 +290,7 @@ module.exports = nodefony.register("SecuredArea", function () {
296
290
  }
297
291
 
298
292
  // Factory
299
- setFactory(auth, options) {
293
+ setFactory (auth, options) {
300
294
  if (auth) {
301
295
  if (auth in nodefony.security.factories) {
302
296
  let index = null;
@@ -308,20 +302,18 @@ module.exports = nodefony.register("SecuredArea", function () {
308
302
  index = 0;
309
303
  }
310
304
  this.nbFactories++;
311
- this.log("FACTORY " + auth + " registered ", "DEBUG");
305
+ this.log(`FACTORY ${auth} registered `, "DEBUG");
312
306
  return this.factories[index];
313
- } else {
314
- this.log("FACTORY :" + auth + "NOT registered ", "ERROR");
315
- throw new Error("FACTORY :" + auth + "NOT registered ");
316
307
  }
308
+ this.log(`FACTORY :${auth}NOT registered `, "ERROR");
309
+ throw new Error(`FACTORY :${auth} NOT registered `);
317
310
  }
311
+ throw new Error(`FACTORY :${auth} bad args`);
318
312
  }
319
313
 
320
- getFactory(name) {
314
+ getFactory (name) {
321
315
  if (name) {
322
- let index = this.factories.findIndex((factory) => {
323
- return factory.name === name;
324
- });
316
+ const index = this.factories.findIndex((factory) => factory.name === name);
325
317
  if (index >= 0) {
326
318
  return this.factories[index];
327
319
  }
@@ -330,70 +322,72 @@ module.exports = nodefony.register("SecuredArea", function () {
330
322
  return null;
331
323
  }
332
324
 
333
- setProvider(provider) {
325
+ setProvider (provider) {
334
326
  if (provider) {
335
327
  this.provider = provider;
336
328
  this.providerName = provider.name;
337
329
  }
338
330
  }
339
331
 
340
- setProviderName(name) {
332
+ setProviderName (name) {
341
333
  this.providerName = name;
342
334
  }
343
335
 
344
- getProvider() {
336
+ getProvider () {
345
337
  return this.provider;
346
338
  }
347
339
 
348
- setStateLess(state) {
340
+ setStateLess (state) {
349
341
  if (state === null) {
350
- return this.stateLess = true;
342
+ this.stateLess = true;
343
+ return true;
351
344
  }
352
- return this.stateLess = state || false;
345
+ this.stateLess = state || false;
346
+ return state || false;
353
347
  }
354
348
 
355
- overrideURL(context, myUrl, target = null) {
356
- try{
349
+ overrideURL (context, myUrl, target = null) {
350
+ try {
357
351
  if (myUrl) {
358
352
  context.request.url = url.parse(url.resolve(context.request.url, myUrl));
359
353
  }
360
- let resolver = this.router.resolve(context);
354
+ const resolver = this.router.resolve(context);
361
355
  if (target) {
362
356
  resolver.variables.push(target);
363
357
  }
364
358
  return resolver;
365
- }catch(e){
366
- if (e instanceof nodefony.Resolver ){
367
- if ( e.exception){
368
- throw e.exception ;
359
+ } catch (e) {
360
+ if (e instanceof nodefony.Resolver) {
361
+ if (e.exception) {
362
+ throw e.exception;
369
363
  }
370
364
  }
371
- throw e ;
365
+ throw e;
372
366
  }
373
367
  }
374
368
 
375
- redirectHttps(context) {
369
+ redirectHttps (context) {
376
370
  // no cache
377
371
  context.redirectHttps(301);
378
372
  return context;
379
373
  }
380
374
 
381
- redirect(context, url) {
375
+ redirect (context, url) {
382
376
  if (url) {
383
377
  // no cache
384
378
  return context.redirect(url, 302, true);
385
- //return context;
379
+ // return context;
386
380
  }
387
381
  return context.redirect(context.request.url, 302, true);
388
- //return context;
382
+ // return context;
389
383
  }
390
384
 
391
- match(context) {
392
- let url = context.request.url ? context.request.url.pathname : (context.request.resourceURL ? context.request.resourceURL.pathname : null);
385
+ match (context) {
386
+ const url = context.request.url ? context.request.url.pathname : context.request.resourceURL ? context.request.resourceURL.pathname : null;
393
387
  return this.pattern.exec(url);
394
388
  }
395
389
 
396
- setPattern(pattern) {
390
+ setPattern (pattern) {
397
391
  if (pattern instanceof RegExp) {
398
392
  this.pattern = pattern;
399
393
  this.stringPattern = pattern.toString();
@@ -404,32 +398,32 @@ module.exports = nodefony.register("SecuredArea", function () {
404
398
  return this.pattern;
405
399
  }
406
400
 
407
- setCors(crossSettings) {
401
+ setCors (crossSettings) {
408
402
  this.cors = this.firewall.corsManager.createCors(crossSettings);
409
403
  return this.cors;
410
404
  }
411
405
 
412
- setFormLogin(route) {
406
+ setFormLogin (route) {
413
407
  this.formLogin = route;
414
408
  }
415
409
 
416
- setCheckLogin(route) {
410
+ setCheckLogin (route) {
417
411
  this.checkLogin = route;
418
412
  }
419
413
 
420
- setDefaultTarget(route) {
414
+ setDefaultTarget (route) {
421
415
  this.defaultTarget = route;
422
416
  }
423
417
 
424
- setAlwaysUseDefaultTarget(data) {
418
+ setAlwaysUseDefaultTarget (data) {
425
419
  this.alwaysUseDefaultTarget = data;
426
420
  }
427
421
 
428
- setContextSession(context) {
422
+ setContextSession (context) {
429
423
  this.sessionContext = context;
430
424
  }
431
425
 
432
- setRedirectHttps(value) {
426
+ setRedirectHttps (value) {
433
427
  this.redirect_Https = value || false;
434
428
  }
435
429
  }