emilsoftware-utilities 1.4.0-dev.1 → 1.4.0-dev.11

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/README.MD ADDED
@@ -0,0 +1,34 @@
1
+ Convenzioni per i Commit Message
2
+
3
+ 1. feat:
4
+ Descrizione: Nuova feature
5
+ Esempio: feat: aggiunta endpoint per notifiche
6
+ Trigger: MINOR release (es. 1.3.0 -> 1.4.0)
7
+ Su dev: 1.4.0-dev.0
8
+
9
+ 2. fix:
10
+ Descrizione: Correzione di bug
11
+ Esempio: fix: gestione errore null in login
12
+ Trigger: PATCH release (es. 1.3.1)
13
+ Su dev: 1.3.1-dev.0
14
+
15
+ 3. BREAKING CHANGE:
16
+ Descrizione: Cambiamento che rompe la compatibilità all'indietro
17
+ Esempio:
18
+ feat!: rimozione supporto legacy
19
+ BREAKING CHANGE: cambia lo schema JWT
20
+ Trigger: MAJOR release (es. 1.0.0 -> 2.0.0)
21
+
22
+ 4. Altri tipi di commit
23
+ Esempi: chore:, docs:, test:, refactor:
24
+ Descrizione: Non triggerano una release di default, a meno che non siano configurati esplicitamente nel commit-analyzer.
25
+ Esempio: chore: aggiorna dipendenze
26
+
27
+ 5. Forzare una Release
28
+ Descrizione: Utile in caso di merge o altre operazioni.
29
+ Comandi:
30
+ git commit --allow-empty -m "feat: trigger test release"
31
+ Poi:
32
+ git push origin dev
33
+ Oppure:
34
+ git push origin main
@@ -64,6 +64,7 @@ export declare class RestUtilities {
64
64
  static sendErrorMessage(res: Response, error: any, tag?: string, status?: number): Response;
65
65
  static sendUnauthorized(res: Response): Response;
66
66
  static sendInvalidCredentials(res: Response): Response;
67
+ static sendPasswordExpired(res: Response): Response;
67
68
  /**
68
69
  * Sends a base response with a payload.
69
70
  * @param res - Express Response object.
package/dist/Utilities.js CHANGED
@@ -138,6 +138,14 @@ class RestUtilities {
138
138
  message: "Credenziali non valide"
139
139
  });
140
140
  }
141
+ static sendPasswordExpired(res) {
142
+ return res.status(403).send({
143
+ severity: "warning",
144
+ statusCode: StatusCode.Warning,
145
+ code: "PASSWORD_EXPIRED",
146
+ message: "Password scaduta. E' necessario aggiornarla"
147
+ });
148
+ }
141
149
  /**
142
150
  * Sends a base response with a payload.
143
151
  * @param res - Express Response object.
@@ -4,8 +4,8 @@
4
4
  * @module AccessiModule
5
5
  * @author mttdev382
6
6
  */
7
- import { Options } from "es-node-firebird";
8
- import { DynamicModule } from "@nestjs/common";
7
+ import { Options } from 'es-node-firebird';
8
+ import { DynamicModule } from '@nestjs/common';
9
9
  export interface JwtOptions {
10
10
  secret: string;
11
11
  expiresIn: string;
@@ -29,11 +29,20 @@ export interface ExtensionFieldsOptions {
29
29
  }
30
30
  export interface AccessiOptions {
31
31
  databaseOptions: Options;
32
+ /**
33
+ * Basepath del sito es: 'http://www.il-mio-sito.it/nome-progetto(se c'è)'
34
+ */
32
35
  confirmationEmailUrl: string;
36
+ /**
37
+ * Percorso della pagina di reset personalizzata es. http://localhost:4200/#/admin/reset-password
38
+ * N.B si sostituisce al confirmationMailURl
39
+ */
40
+ customResetPage?: string;
33
41
  confirmationEmailReturnUrl: string;
34
42
  confirmationEmailPrefix?: string;
35
43
  encryptionKey: string;
36
44
  mockDemoUser: boolean;
45
+ passwordExpiration?: boolean;
37
46
  jwtOptions: JwtOptions;
38
47
  emailOptions: EmailOptions;
39
48
  extensionFieldsOptions?: ExtensionFieldsOptions[];
@@ -112,6 +112,10 @@ let AuthController = AuthController_1 = class AuthController {
112
112
  return Utilities_1.RestUtilities.sendBaseResponse(res, userData);
113
113
  }
114
114
  catch (error) {
115
+ if (error.message === 'PASSWORD_EXPIRED') {
116
+ this.logger.warning('Password scaduta, cambiare password ', error);
117
+ return Utilities_1.RestUtilities.sendPasswordExpired(res);
118
+ }
115
119
  this.logger.error('Errore durante il login', error);
116
120
  return Utilities_1.RestUtilities.sendInvalidCredentials(res);
117
121
  }
@@ -161,6 +165,20 @@ __decorate([
161
165
  status: 401,
162
166
  description: 'Credenziali non valide',
163
167
  }),
168
+ (0, swagger_1.ApiResponse)({
169
+ status: 403,
170
+ description: "Password scaduta, è necessatio aggiornarla. ",
171
+ schema: {
172
+ example: {
173
+ message: {
174
+ severity: 'warning',
175
+ statusCode: 2, // o il valore di StatusCode.Warning
176
+ code: 'PASSWORD_EXPIRED',
177
+ message: 'Password scaduta. È necessario aggiornarla.',
178
+ }
179
+ }
180
+ }
181
+ }),
164
182
  (0, common_1.Post)('login'),
165
183
  __param(0, (0, common_1.Body)()),
166
184
  __param(1, (0, common_1.Res)()),
@@ -8,5 +8,6 @@ export declare class EmailController {
8
8
  serveResetPasswordPage(res: Response, token: string, returnUrl?: string): Promise<void>;
9
9
  sendPasswordResetEmail(request: Request, sendResetPasswordData: {
10
10
  email: string;
11
+ htmlMail?: string;
11
12
  }, res: Response): Promise<Response<any, Record<string, any>>>;
12
13
  }
@@ -41,7 +41,7 @@ let EmailController = EmailController_1 = class EmailController {
41
41
  sendPasswordResetEmail(request, sendResetPasswordData, res) {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
43
  try {
44
- yield this.emailService.sendPasswordResetEmail(sendResetPasswordData.email);
44
+ yield this.emailService.sendPasswordResetEmail(sendResetPasswordData.email, sendResetPasswordData.htmlMail);
45
45
  return Utilities_1.RestUtilities.sendOKMessage(res, "L'email di reset è stata inoltrata al destinatario.");
46
46
  }
47
47
  catch (error) {
@@ -52,9 +52,16 @@ let EmailController = EmailController_1 = class EmailController {
52
52
  };
53
53
  exports.EmailController = EmailController;
54
54
  __decorate([
55
- (0, swagger_1.ApiOperation)({ summary: 'Serve una pagina per il reset della password', operationId: "serveResetPasswordPage" }),
55
+ (0, swagger_1.ApiOperation)({
56
+ summary: 'Serve una pagina per il reset della password',
57
+ operationId: 'serveResetPasswordPage',
58
+ }),
56
59
  (0, swagger_1.ApiParam)({ name: 'token', description: 'Token per il reset della password', required: true }),
57
- (0, swagger_1.ApiQuery)({ name: 'returnUrl', description: 'Url di ritorno della pagina. Default: https://google.com', required: false }),
60
+ (0, swagger_1.ApiQuery)({
61
+ name: 'returnUrl',
62
+ description: 'Url di ritorno della pagina. Default: https://google.com',
63
+ required: false,
64
+ }),
58
65
  (0, swagger_1.ApiResponse)({ status: 200, description: 'Pagina di reset password servita con successo' }),
59
66
  (0, common_1.Get)('reset-password-page/:token'),
60
67
  __param(0, (0, common_1.Res)()),
@@ -65,10 +72,30 @@ __decorate([
65
72
  __metadata("design:returntype", Promise)
66
73
  ], EmailController.prototype, "serveResetPasswordPage", null);
67
74
  __decorate([
68
- (0, swagger_1.ApiOperation)({ summary: 'Invia una e-mail per il reset della password', operationId: "sendPasswordResetEmail" }),
69
- (0, swagger_1.ApiBody)({ schema: { properties: { email: { type: 'string', description: "L'email dell'utente che richiede il reset" } } } }),
75
+ (0, swagger_1.ApiOperation)({
76
+ summary: 'Invia una e-mail per il reset della password',
77
+ operationId: 'sendPasswordResetEmail',
78
+ }),
79
+ (0, swagger_1.ApiBody)({
80
+ schema: {
81
+ properties: {
82
+ email: {
83
+ type: 'string',
84
+ description: "L'email dell'utente che richiede il reset",
85
+ },
86
+ htmlMail: {
87
+ type: 'string',
88
+ description: 'Corpo della mail in HTML',
89
+ },
90
+ },
91
+ required: ['email'],
92
+ },
93
+ }),
70
94
  (0, swagger_1.ApiResponse)({ status: 200, description: "L'email di reset è stata inviata con successo" }),
71
- (0, swagger_1.ApiResponse)({ status: 400, description: "Errore nella richiesta: protocollo o host non impostati" }),
95
+ (0, swagger_1.ApiResponse)({
96
+ status: 400,
97
+ description: 'Errore nella richiesta: protocollo o host non impostati',
98
+ }),
72
99
  (0, swagger_1.ApiResponse)({ status: 500, description: "Errore interno durante l'invio dell'email" }),
73
100
  (0, common_1.Post)('send-reset-password-email'),
74
101
  __param(0, (0, common_1.Req)()),
@@ -2,7 +2,7 @@ import { Response, Request } from 'express';
2
2
  import { AccessiOptions } from '../AccessiModule';
3
3
  import { UserService } from '../Services/UserService/UserService';
4
4
  import { EmailService } from '../Services/EmailService/EmailService';
5
- import { UserDto } from '../Dtos';
5
+ import { StatoRegistrazione, UserDto } from '../Dtos';
6
6
  import { RegisterRequest } from '../Dtos/RegisterRequest';
7
7
  export declare class UserController {
8
8
  private readonly userService;
@@ -13,6 +13,7 @@ export declare class UserController {
13
13
  serveResetPasswordPage(res: Response, token: string): Promise<void>;
14
14
  getUsers(res: Response, email?: string, codiceUtente?: number, includeExtensionFields?: boolean, includeGrants?: boolean): Promise<Response<any, Record<string, any>>>;
15
15
  deleteUser(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
16
+ setStatoRegistrazione(codiceUtente: number, statoRegistrazione: StatoRegistrazione, res: Response): Promise<Response<any, Record<string, any>>>;
16
17
  register(request: Request, registrationData: RegisterRequest, res: Response): Promise<Response<any, Record<string, any>>>;
17
18
  updateUtente(codiceUtente: number, user: UserDto, res: Response): Promise<Response<any, Record<string, any>>>;
18
19
  setGdpr(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
@@ -50,7 +50,10 @@ let UserController = UserController_1 = class UserController {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
51
  try {
52
52
  let filters = { email, codiceUtente };
53
- let options = { includeExtensionFields: includeExtensionFields !== null && includeExtensionFields !== void 0 ? includeExtensionFields : true, includeGrants: includeGrants !== null && includeGrants !== void 0 ? includeGrants : true };
53
+ let options = {
54
+ includeExtensionFields: includeExtensionFields !== null && includeExtensionFields !== void 0 ? includeExtensionFields : true,
55
+ includeGrants: includeGrants !== null && includeGrants !== void 0 ? includeGrants : true,
56
+ };
54
57
  const users = yield this.userService.getUsers(filters, options);
55
58
  return Utilities_1.RestUtilities.sendBaseResponse(res, users);
56
59
  }
@@ -73,11 +76,26 @@ let UserController = UserController_1 = class UserController {
73
76
  }
74
77
  });
75
78
  }
79
+ setStatoRegistrazione(codiceUtente, statoRegistrazione, res) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ try {
82
+ if (!codiceUtente)
83
+ throw new Error('Il codice utente è obbligatorio.');
84
+ if (statoRegistrazione === undefined)
85
+ throw new Error('Lo stato registrazione è obbligatorio.');
86
+ yield this.userService.setStato(codiceUtente, statoRegistrazione);
87
+ return Utilities_1.RestUtilities.sendOKMessage(res, `Lo stato dell'utente ${codiceUtente} è stato aggiornato a ${statoRegistrazione}.`);
88
+ }
89
+ catch (error) {
90
+ return Utilities_1.RestUtilities.sendErrorMessage(res, error, UserController_1.name);
91
+ }
92
+ });
93
+ }
76
94
  register(request, registrationData, res) {
77
95
  return __awaiter(this, void 0, void 0, function* () {
78
96
  try {
79
97
  const codiceUtente = yield this.userService.register(registrationData);
80
- yield this.emailService.sendPasswordResetEmail(registrationData.email);
98
+ yield this.emailService.sendPasswordResetEmail(registrationData.email, registrationData.htmlMail);
81
99
  return Utilities_1.RestUtilities.sendBaseResponse(res, codiceUtente);
82
100
  }
83
101
  catch (error) {
@@ -89,7 +107,7 @@ let UserController = UserController_1 = class UserController {
89
107
  return __awaiter(this, void 0, void 0, function* () {
90
108
  try {
91
109
  if (!codiceUtente)
92
- throw new Error("Il codice utente è obbligatorio.");
110
+ throw new Error('Il codice utente è obbligatorio.');
93
111
  yield this.userService.updateUser(codiceUtente, user);
94
112
  return Utilities_1.RestUtilities.sendOKMessage(res, `L'utente ${codiceUtente} è stato aggiornato con successo.`);
95
113
  }
@@ -102,7 +120,7 @@ let UserController = UserController_1 = class UserController {
102
120
  return __awaiter(this, void 0, void 0, function* () {
103
121
  try {
104
122
  if (!codiceUtente)
105
- throw new Error("Il codice utente è obbligatorio.");
123
+ throw new Error('Il codice utente è obbligatorio.');
106
124
  yield this.userService.setGdpr(codiceUtente);
107
125
  return Utilities_1.RestUtilities.sendOKMessage(res, `L'utente ${codiceUtente} ha accettato il GDPR.`);
108
126
  }
@@ -114,8 +132,15 @@ let UserController = UserController_1 = class UserController {
114
132
  };
115
133
  exports.UserController = UserController;
116
134
  __decorate([
117
- (0, swagger_1.ApiOperation)({ summary: 'Servire la pagina di reset password', operationId: "serveResetPasswordPageUser" }),
118
- (0, swagger_1.ApiParam)({ name: 'token', description: 'Token per il reset della password', required: true }),
135
+ (0, swagger_1.ApiOperation)({
136
+ summary: 'Servire la pagina di reset password',
137
+ operationId: 'serveResetPasswordPageUser',
138
+ }),
139
+ (0, swagger_1.ApiParam)({
140
+ name: 'token',
141
+ description: 'Token per il reset della password',
142
+ required: true,
143
+ }),
119
144
  (0, common_1.Get)('reset-password/:token'),
120
145
  __param(0, (0, common_1.Res)()),
121
146
  __param(1, (0, common_1.Param)('token')),
@@ -124,13 +149,36 @@ __decorate([
124
149
  __metadata("design:returntype", Promise)
125
150
  ], UserController.prototype, "serveResetPasswordPage", null);
126
151
  __decorate([
127
- (0, swagger_1.ApiOperation)({ summary: 'Recupera la lista degli utenti', operationId: "getUsers" }),
128
- (0, swagger_1.ApiResponse)({ status: 200, description: 'Lista utenti recuperata con successo', type: GetUsersResponse_1.GetUsersResponse }),
152
+ (0, swagger_1.ApiOperation)({
153
+ summary: 'Recupera la lista degli utenti',
154
+ operationId: 'getUsers',
155
+ }),
156
+ (0, swagger_1.ApiResponse)({
157
+ status: 200,
158
+ description: 'Lista utenti recuperata con successo',
159
+ type: GetUsersResponse_1.GetUsersResponse,
160
+ }),
129
161
  (0, swagger_1.ApiResponse)({ status: 401, description: 'Credenziali non valide' }),
130
- (0, swagger_1.ApiQuery)({ name: 'email', required: false, description: 'Email dell\'utente da cercare' }),
131
- (0, swagger_1.ApiQuery)({ name: 'codiceUtente', required: false, description: "Codice dell'utente da cercare" }),
132
- (0, swagger_1.ApiQuery)({ name: 'includeExtensionFields', required: false, description: "Includi extension fields (chiamata più pesante)" }),
133
- (0, swagger_1.ApiQuery)({ name: 'includeGrants', required: false, description: "Includi Permessi (chiamata più pesante)" }),
162
+ (0, swagger_1.ApiQuery)({
163
+ name: 'email',
164
+ required: false,
165
+ description: "Email dell'utente da cercare",
166
+ }),
167
+ (0, swagger_1.ApiQuery)({
168
+ name: 'codiceUtente',
169
+ required: false,
170
+ description: "Codice dell'utente da cercare",
171
+ }),
172
+ (0, swagger_1.ApiQuery)({
173
+ name: 'includeExtensionFields',
174
+ required: false,
175
+ description: 'Includi extension fields (chiamata più pesante)',
176
+ }),
177
+ (0, swagger_1.ApiQuery)({
178
+ name: 'includeGrants',
179
+ required: false,
180
+ description: 'Includi Permessi (chiamata più pesante)',
181
+ }),
134
182
  (0, common_1.Get)('get-users'),
135
183
  __param(0, (0, common_1.Res)()),
136
184
  __param(1, (0, common_1.Query)('email')),
@@ -142,16 +190,24 @@ __decorate([
142
190
  __metadata("design:returntype", Promise)
143
191
  ], UserController.prototype, "getUsers", null);
144
192
  __decorate([
145
- (0, swagger_1.ApiOperation)({ summary: 'Elimina un utente', operationId: "deleteUser" }),
193
+ (0, swagger_1.ApiOperation)({
194
+ summary: 'Elimina un utente',
195
+ operationId: 'deleteUser',
196
+ description: `Imposta lo stato di un utente a 50(eliminato)
197
+ Non esegue una eliminazione dei record`,
198
+ }),
146
199
  (0, swagger_1.ApiParam)({
147
200
  name: 'codiceUtente',
148
201
  description: "Codice identificativo dell'utente da eliminare",
149
202
  required: true,
150
- example: "USR123"
203
+ example: 'USR123',
151
204
  }),
152
- (0, swagger_1.ApiResponse)({ status: 200, description: "Utente eliminato con successo" }),
153
- (0, swagger_1.ApiResponse)({ status: 400, description: "Errore nei parametri della richiesta" }),
154
- (0, swagger_1.ApiResponse)({ status: 500, description: "Errore interno del server" }),
205
+ (0, swagger_1.ApiResponse)({ status: 200, description: 'Utente eliminato con successo' }),
206
+ (0, swagger_1.ApiResponse)({
207
+ status: 400,
208
+ description: 'Errore nei parametri della richiesta',
209
+ }),
210
+ (0, swagger_1.ApiResponse)({ status: 500, description: 'Errore interno del server' }),
155
211
  (0, common_1.Delete)('delete-user/:codiceUtente'),
156
212
  __param(0, (0, common_1.Param)('codiceUtente')),
157
213
  __param(1, (0, common_1.Res)()),
@@ -159,6 +215,57 @@ __decorate([
159
215
  __metadata("design:paramtypes", [Number, Object]),
160
216
  __metadata("design:returntype", Promise)
161
217
  ], UserController.prototype, "deleteUser", null);
218
+ __decorate([
219
+ (0, swagger_1.ApiOperation)({
220
+ summary: 'Imposta lo stato di registrazione di un utente',
221
+ operationId: 'setStatoRegistrazione',
222
+ description: `Imposta lo stato di registrazione di un utente. Stati possibili:
223
+ - 0: NULL (non definito)
224
+ - 5: INSERT (inserito)
225
+ - 10: INVIO (inviato)
226
+ - 20: CONF (confermato)
227
+ - 50: DELETE (eliminato)
228
+ - 99: BLOCC (bloccato)`,
229
+ }),
230
+ (0, swagger_1.ApiBody)({
231
+ schema: {
232
+ type: 'object',
233
+ required: ['codiceUtente', 'statoRegistrazione'],
234
+ properties: {
235
+ codiceUtente: {
236
+ type: 'number',
237
+ description: "Codice identificativo dell'utente",
238
+ example: 123,
239
+ },
240
+ statoRegistrazione: {
241
+ type: 'number',
242
+ enum: [0, 5, 10, 20, 50, 99],
243
+ description: 'Nuovo stato di registrazione',
244
+ example: 20,
245
+ },
246
+ },
247
+ },
248
+ }),
249
+ (0, swagger_1.ApiResponse)({
250
+ status: 200,
251
+ description: 'Stato registrazione aggiornato con successo',
252
+ }),
253
+ (0, swagger_1.ApiResponse)({
254
+ status: 400,
255
+ description: 'Errore nei parametri della richiesta',
256
+ }),
257
+ (0, swagger_1.ApiResponse)({
258
+ status: 500,
259
+ description: 'Errore interno del server',
260
+ }),
261
+ (0, common_1.Post)('set-stato'),
262
+ __param(0, (0, common_1.Body)('codiceUtente')),
263
+ __param(1, (0, common_1.Body)('statoRegistrazione')),
264
+ __param(2, (0, common_1.Res)()),
265
+ __metadata("design:type", Function),
266
+ __metadata("design:paramtypes", [Number, Number, Object]),
267
+ __metadata("design:returntype", Promise)
268
+ ], UserController.prototype, "setStatoRegistrazione", null);
162
269
  __decorate([
163
270
  (0, swagger_1.ApiOperation)({
164
271
  summary: 'Registra un nuovo utente',
@@ -166,19 +273,19 @@ __decorate([
166
273
  }),
167
274
  (0, swagger_1.ApiBody)({
168
275
  type: RegisterRequest_1.RegisterRequest,
169
- description: "Dati necessari per la registrazione dell'utente"
276
+ description: "Dati necessari per la registrazione dell'utente",
170
277
  }),
171
278
  (0, swagger_1.ApiCreatedResponse)({
172
279
  description: 'Utente registrato con successo. Restituisce il codice utente e invia una mail di conferma/reset password.',
173
- type: RegisterResponse_1.RegisterResponse
280
+ type: RegisterResponse_1.RegisterResponse,
174
281
  }),
175
282
  (0, swagger_1.ApiResponse)({
176
283
  status: common_1.HttpStatus.BAD_REQUEST,
177
- description: 'Errore nella registrazione. Potrebbe essere dovuto a dati mancanti, email già esistente o configurazione non valida.'
284
+ description: 'Errore nella registrazione. Potrebbe essere dovuto a dati mancanti, email già esistente o configurazione non valida.',
178
285
  }),
179
286
  (0, swagger_1.ApiResponse)({
180
287
  status: common_1.HttpStatus.INTERNAL_SERVER_ERROR,
181
- description: 'Errore interno del server durante la registrazione o l’invio dell’email.'
288
+ description: 'Errore interno del server durante la registrazione o l’invio dell’email.',
182
289
  }),
183
290
  (0, common_1.Post)('register'),
184
291
  __param(0, (0, common_1.Req)()),
@@ -189,18 +296,24 @@ __decorate([
189
296
  __metadata("design:returntype", Promise)
190
297
  ], UserController.prototype, "register", null);
191
298
  __decorate([
192
- (0, swagger_1.ApiOperation)({ summary: 'Aggiorna un utente esistente', operationId: "updateUtente" }),
299
+ (0, swagger_1.ApiOperation)({
300
+ summary: 'Aggiorna un utente esistente',
301
+ operationId: 'updateUtente',
302
+ }),
193
303
  (0, swagger_1.ApiParam)({
194
304
  name: 'codiceUtente',
195
305
  description: "Codice identificativo dell'utente da aggiornare",
196
306
  required: true,
197
- example: "USR123"
307
+ example: 'USR123',
198
308
  }),
199
309
  (0, swagger_1.ApiBody)({
200
310
  type: Dtos_1.UserDto,
201
- description: "Dati aggiornati dell'utente (escluso il codice utente, che è nel path)"
311
+ description: "Dati aggiornati dell'utente (escluso il codice utente, che è nel path)",
312
+ }),
313
+ (0, swagger_1.ApiResponse)({
314
+ status: common_1.HttpStatus.OK,
315
+ description: 'Utente aggiornato con successo',
202
316
  }),
203
- (0, swagger_1.ApiResponse)({ status: common_1.HttpStatus.OK, description: "Utente aggiornato con successo" }),
204
317
  (0, swagger_1.ApiResponse)({ status: 400, description: "Errore nell'aggiornamento" }),
205
318
  (0, common_1.Put)('update-user/:codiceUtente'),
206
319
  __param(0, (0, common_1.Param)('codiceUtente')),
@@ -211,15 +324,21 @@ __decorate([
211
324
  __metadata("design:returntype", Promise)
212
325
  ], UserController.prototype, "updateUtente", null);
213
326
  __decorate([
214
- (0, swagger_1.ApiOperation)({ summary: "Imposta il consenso GDPR per un utente", operationId: "setGdpr" }),
327
+ (0, swagger_1.ApiOperation)({
328
+ summary: 'Imposta il consenso GDPR per un utente',
329
+ operationId: 'setGdpr',
330
+ }),
215
331
  (0, swagger_1.ApiParam)({
216
- name: "codiceUtente",
332
+ name: 'codiceUtente',
217
333
  description: "Codice identificativo dell'utente che accetta il GDPR",
218
334
  required: true,
219
- example: "USR123"
335
+ example: 'USR123',
336
+ }),
337
+ (0, swagger_1.ApiResponse)({
338
+ status: 200,
339
+ description: 'Consenso GDPR impostato con successo',
220
340
  }),
221
- (0, swagger_1.ApiResponse)({ status: 200, description: "Consenso GDPR impostato con successo" }),
222
- (0, swagger_1.ApiResponse)({ status: 400, description: "Errore nella richiesta" }),
341
+ (0, swagger_1.ApiResponse)({ status: 400, description: 'Errore nella richiesta' }),
223
342
  (0, common_1.Patch)('set-gdpr/:codiceUtente'),
224
343
  __param(0, (0, common_1.Param)('codiceUtente')),
225
344
  __param(1, (0, common_1.Res)()),
@@ -1,4 +1,4 @@
1
- import { Permission } from './Permission';
1
+ import { Permission } from "./Permission";
2
2
  export declare class RegisterRequest {
3
3
  email: string;
4
4
  cognome?: string;
@@ -18,4 +18,5 @@ export declare class RegisterRequest {
18
18
  flagDueFattori?: boolean;
19
19
  paginaDefault?: string;
20
20
  ragSocCli?: string;
21
+ htmlMail?: string;
21
22
  }
@@ -17,11 +17,17 @@ class RegisterRequest {
17
17
  }
18
18
  exports.RegisterRequest = RegisterRequest;
19
19
  __decorate([
20
- (0, swagger_1.ApiProperty)({ description: "Email dell'utente.", example: "mario.rossi@dev.it" }),
20
+ (0, swagger_1.ApiProperty)({
21
+ description: "Email dell'utente.",
22
+ example: "mario.rossi@dev.it",
23
+ }),
21
24
  __metadata("design:type", String)
22
25
  ], RegisterRequest.prototype, "email", void 0);
23
26
  __decorate([
24
- (0, swagger_1.ApiPropertyOptional)({ description: "Cognome dell'utente.", example: "Rossi" }),
27
+ (0, swagger_1.ApiPropertyOptional)({
28
+ description: "Cognome dell'utente.",
29
+ example: "Rossi",
30
+ }),
25
31
  __metadata("design:type", String)
26
32
  ], RegisterRequest.prototype, "cognome", void 0);
27
33
  __decorate([
@@ -29,7 +35,11 @@ __decorate([
29
35
  __metadata("design:type", String)
30
36
  ], RegisterRequest.prototype, "nome", void 0);
31
37
  __decorate([
32
- (0, swagger_1.ApiPropertyOptional)({ description: "Numero di cellulare.", example: "+393401234567", nullable: true }),
38
+ (0, swagger_1.ApiPropertyOptional)({
39
+ description: "Numero di cellulare.",
40
+ example: "+393401234567",
41
+ nullable: true,
42
+ }),
33
43
  __metadata("design:type", String)
34
44
  ], RegisterRequest.prototype, "cellulare", void 0);
35
45
  __decorate([
@@ -37,54 +47,106 @@ __decorate([
37
47
  __metadata("design:type", Boolean)
38
48
  ], RegisterRequest.prototype, "flagSuper", void 0);
39
49
  __decorate([
40
- (0, swagger_1.ApiPropertyOptional)({ description: "Ruoli assegnati all'utente.", example: ["admin", "editor"] }),
50
+ (0, swagger_1.ApiPropertyOptional)({
51
+ description: "Ruoli assegnati all'utente.",
52
+ example: ["admin", "editor"],
53
+ }),
41
54
  __metadata("design:type", Array)
42
55
  ], RegisterRequest.prototype, "roles", void 0);
43
56
  __decorate([
44
- (0, swagger_1.ApiPropertyOptional)({ description: "Permessi assegnati all'utente.", type: [Permission_1.Permission], example: [{ codiceMenu: "MNUOFFICINA", tipoAbilitazione: TipoAbilitazione_1.TipoAbilitazione.SCRITTURA }] }),
57
+ (0, swagger_1.ApiPropertyOptional)({
58
+ description: "Permessi assegnati all'utente.",
59
+ type: [Permission_1.Permission],
60
+ example: [
61
+ {
62
+ codiceMenu: "MNUOFFICINA",
63
+ tipoAbilitazione: TipoAbilitazione_1.TipoAbilitazione.SCRITTURA,
64
+ },
65
+ ],
66
+ }),
45
67
  __metadata("design:type", Array)
46
68
  ], RegisterRequest.prototype, "permissions", void 0);
47
69
  __decorate([
48
- (0, swagger_1.ApiPropertyOptional)({ description: "Numero del report associato.", example: 1002 }),
70
+ (0, swagger_1.ApiPropertyOptional)({
71
+ description: "Numero del report associato.",
72
+ example: 1002,
73
+ }),
49
74
  __metadata("design:type", Number)
50
75
  ], RegisterRequest.prototype, "numeroReport", void 0);
51
76
  __decorate([
52
- (0, swagger_1.ApiPropertyOptional)({ description: "Indice personale dell'utente.", example: 15 }),
77
+ (0, swagger_1.ApiPropertyOptional)({
78
+ description: "Indice personale dell'utente.",
79
+ example: 15,
80
+ }),
53
81
  __metadata("design:type", Number)
54
82
  ], RegisterRequest.prototype, "indicePersonale", void 0);
55
83
  __decorate([
56
- (0, swagger_1.ApiPropertyOptional)({ description: "Codice del cliente principale (super).", example: "CLT_SUP_1234" }),
84
+ (0, swagger_1.ApiPropertyOptional)({
85
+ description: "Codice del cliente principale (super).",
86
+ example: "CLT_SUP_1234",
87
+ }),
57
88
  __metadata("design:type", String)
58
89
  ], RegisterRequest.prototype, "codiceClienteSuper", void 0);
59
90
  __decorate([
60
- (0, swagger_1.ApiPropertyOptional)({ description: "Codice dell'agenzia associata.", example: "AGZ_5678" }),
91
+ (0, swagger_1.ApiPropertyOptional)({
92
+ description: "Codice dell'agenzia associata.",
93
+ example: "AGZ_5678",
94
+ }),
61
95
  __metadata("design:type", String)
62
96
  ], RegisterRequest.prototype, "codiceAgenzia", void 0);
63
97
  __decorate([
64
- (0, swagger_1.ApiPropertyOptional)({ description: "Codice del cliente collegato.", example: "CLT_COL_8765" }),
98
+ (0, swagger_1.ApiPropertyOptional)({
99
+ description: "Codice del cliente collegato.",
100
+ example: "CLT_COL_8765",
101
+ }),
65
102
  __metadata("design:type", String)
66
103
  ], RegisterRequest.prototype, "codiceClienteCollegato", void 0);
67
104
  __decorate([
68
- (0, swagger_1.ApiPropertyOptional)({ description: "Lista di codici clienti separati da virgola.", example: "CLT_123,CLT_456,CLT_789" }),
105
+ (0, swagger_1.ApiPropertyOptional)({
106
+ description: "Lista di codici clienti separati da virgola.",
107
+ example: "CLT_123,CLT_456,CLT_789",
108
+ }),
69
109
  __metadata("design:type", String)
70
110
  ], RegisterRequest.prototype, "codiceClienti", void 0);
71
111
  __decorate([
72
- (0, swagger_1.ApiPropertyOptional)({ description: "Tipo di filtro applicato.", example: "esclusivo" }),
112
+ (0, swagger_1.ApiPropertyOptional)({
113
+ description: "Tipo di filtro applicato.",
114
+ example: "esclusivo",
115
+ }),
73
116
  __metadata("design:type", String)
74
117
  ], RegisterRequest.prototype, "tipoFiltro", void 0);
75
118
  __decorate([
76
- (0, swagger_1.ApiPropertyOptional)({ description: "Avatar dell'utente.", example: "user.svg" }),
119
+ (0, swagger_1.ApiPropertyOptional)({
120
+ description: "Avatar dell'utente.",
121
+ example: "user.svg",
122
+ }),
77
123
  __metadata("design:type", String)
78
124
  ], RegisterRequest.prototype, "avatar", void 0);
79
125
  __decorate([
80
- (0, swagger_1.ApiPropertyOptional)({ description: "Flag autenticazione a due fattori.", example: false }),
126
+ (0, swagger_1.ApiPropertyOptional)({
127
+ description: "Flag autenticazione a due fattori.",
128
+ example: false,
129
+ }),
81
130
  __metadata("design:type", Boolean)
82
131
  ], RegisterRequest.prototype, "flagDueFattori", void 0);
83
132
  __decorate([
84
- (0, swagger_1.ApiPropertyOptional)({ description: "Pagina di default dell'utente.", example: "/dashboard" }),
133
+ (0, swagger_1.ApiPropertyOptional)({
134
+ description: "Pagina di default dell'utente.",
135
+ example: "/dashboard",
136
+ }),
85
137
  __metadata("design:type", String)
86
138
  ], RegisterRequest.prototype, "paginaDefault", void 0);
87
139
  __decorate([
88
- (0, swagger_1.ApiPropertyOptional)({ description: "Ragione sociale cliente.", example: "ALIVAL STOCK" }),
140
+ (0, swagger_1.ApiPropertyOptional)({
141
+ description: "Ragione sociale cliente.",
142
+ example: "ALIVAL STOCK",
143
+ }),
89
144
  __metadata("design:type", String)
90
145
  ], RegisterRequest.prototype, "ragSocCli", void 0);
146
+ __decorate([
147
+ (0, swagger_1.ApiPropertyOptional)({
148
+ description: "HTML mail personalizzato",
149
+ example: "<html></html>",
150
+ }),
151
+ __metadata("design:type", String)
152
+ ], RegisterRequest.prototype, "htmlMail", void 0);
@@ -36,9 +36,11 @@ let AuthService = class AuthService {
36
36
  }
37
37
  login(request) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- if (this.accessiOptions.mockDemoUser && request.email.toLowerCase() === "demo")
39
+ if (this.accessiOptions.mockDemoUser &&
40
+ request.email.toLowerCase() === "demo")
40
41
  return this.getDemoUser();
41
- if (this.accessiOptions.mockDemoUser && request.email.toLowerCase() === "admin")
42
+ if (this.accessiOptions.mockDemoUser &&
43
+ request.email.toLowerCase() === "admin")
42
44
  return this.getAdminUser();
43
45
  const passwordCifrata = Utilities_1.CryptUtilities.encrypt(request.password, this.accessiOptions.encryptionKey);
44
46
  const utente = yield this.userService.getUserByEmail(request.email.toLowerCase());
@@ -61,10 +63,13 @@ let AuthService = class AuthService {
61
63
  const isPasswordValid = yield this.verifyPassword(utente.codiceUtente, passwordCifrata);
62
64
  if (!isPasswordValid)
63
65
  throw new Error("Nome utente o password errata!");
64
- const today = new Date();
65
- const targetDate = new Date(utente.dataScadenzaPassword);
66
- if (today >= targetDate) {
67
- throw new Error("Password scaduta!");
66
+ if (this.accessiOptions.passwordExpiration &&
67
+ this.accessiOptions.passwordExpiration == true) {
68
+ const today = new Date();
69
+ const targetDate = new Date(utente.dataScadenzaPassword);
70
+ if (today >= targetDate) {
71
+ throw new Error("PASSWORD_EXPIRED");
72
+ }
68
73
  }
69
74
  // Recupera i grants
70
75
  const userGrants = yield this.permissionService.getUserRolesAndGrants(utente.codiceUtente);
@@ -73,9 +78,12 @@ let AuthService = class AuthService {
73
78
  const updateLastAccessDateQuery = "UPDATE UTENTI SET DATLASTLOGIN = CURRENT_TIMESTAMP WHERE CODUTE = ?";
74
79
  yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, updateLastAccessDateQuery, [utente.codiceUtente]);
75
80
  let extensionFields = {};
76
- for (const ext of this.accessiOptions.extensionFieldsOptions) {
77
- const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(",")} FROM ${ext.tableName} WHERE ${ext.tableJoinFieldName} = ?`, [utente.codiceUtente])).map(Utilities_1.RestUtilities.convertKeysToCamelCase);
78
- extensionFields[ext.objectKey] = values;
81
+ if (this.accessiOptions.extensionFieldsOptions &&
82
+ this.accessiOptions.extensionFieldsOptions.length > 0) {
83
+ for (const ext of this.accessiOptions.extensionFieldsOptions) {
84
+ const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(",")} FROM ${ext.tableName} WHERE ${ext.tableJoinFieldName} = ?`, [utente.codiceUtente])).map(Utilities_1.RestUtilities.convertKeysToCamelCase);
85
+ extensionFields[ext.objectKey] = values;
86
+ }
79
87
  }
80
88
  return { utente, filtri, userGrants, extensionFields };
81
89
  });
@@ -4,6 +4,6 @@ export declare class EmailService {
4
4
  constructor(accessiOptions: AccessiOptions);
5
5
  sendAccountUpdateEmail(email: string, message: string): Promise<void>;
6
6
  private transporter;
7
- sendPasswordResetEmail(email: string): Promise<void>;
7
+ sendPasswordResetEmail(email: string, htmlMail?: string): Promise<void>;
8
8
  private GetHtmlMail;
9
9
  }
@@ -38,21 +38,33 @@ let EmailService = class EmailService {
38
38
  sendAccountUpdateEmail(email, message) {
39
39
  throw new Error('Method not implemented.');
40
40
  }
41
- sendPasswordResetEmail(email) {
41
+ sendPasswordResetEmail(email, htmlMail) {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
43
  var _a;
44
44
  try {
45
45
  const resetToken = (0, uuid_1.v4)(); // Generiamo un nuovo token unico
46
+ console.log('Generated reset token:', resetToken);
46
47
  // Aggiorna il campo keyReg nel database
47
- const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, "UPDATE UTENTI SET KEYREG = ?, STAREG = ? WHERE USRNAME = ? RETURNING CODUTE", [resetToken, StatoRegistrazione_1.StatoRegistrazione.INVIO, email]);
48
- if (result.length === 0) {
49
- throw new Error("Email non trovata.");
48
+ const result = yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, 'UPDATE UTENTI SET KEYREG = ?, STAREG = ? WHERE USRNAME = ? ', [resetToken, StatoRegistrazione_1.StatoRegistrazione.INVIO, email]);
49
+ //costruizione dei queryparams
50
+ const returnUrlQueryParams = '?returnUrl=' +
51
+ this.accessiOptions.confirmationEmailReturnUrl +
52
+ '&prefix=' +
53
+ ((_a = this.accessiOptions.confirmationEmailPrefix) !== null && _a !== void 0 ? _a : '');
54
+ const { confirmationEmailUrl, customResetPage } = this.accessiOptions;
55
+ // costruisco l'url di base
56
+ let resetUrl = `${confirmationEmailUrl}/api/accessi/email/reset-password-page/${resetToken}${returnUrlQueryParams}`;
57
+ //solo se gli do la customResetPage
58
+ if (customResetPage) {
59
+ resetUrl = customResetPage + '?token=' + resetToken;
50
60
  }
51
- const returnUrlQueryParams = "?returnUrl=" + this.accessiOptions.confirmationEmailReturnUrl + "&prefix=" + ((_a = this.accessiOptions.confirmationEmailPrefix) !== null && _a !== void 0 ? _a : '');
52
- const { confirmationEmailUrl } = this.accessiOptions;
53
- const resetUrl = `${confirmationEmailUrl}/api/accessi/email/reset-password-page/${resetToken}${returnUrlQueryParams}`;
54
61
  let sPhrase;
55
- sPhrase = ` Gentile utente,<br>
62
+ if (htmlMail) {
63
+ sPhrase = htmlMail;
64
+ sPhrase.replace('#link_conferma_password_url', resetUrl);
65
+ }
66
+ else {
67
+ sPhrase = ` Gentile utente,<br>
56
68
  abbiamo ricevuto la tua richiesta.<br><br>
57
69
 
58
70
  Per completare l'operazione, clicca sul link qui sotto:<br>
@@ -64,11 +76,12 @@ let EmailService = class EmailService {
64
76
  Questa è una comunicazione automatica, ti preghiamo di non rispondere a questa email.<br><br>
65
77
 
66
78
  Grazie.<br>`;
79
+ }
67
80
  const html = this.GetHtmlMail(sPhrase);
68
81
  const mailOptions = {
69
82
  from: this.accessiOptions.emailOptions.from,
70
83
  to: email,
71
- subject: "Scelta nuova password",
84
+ subject: 'Scelta nuova password',
72
85
  text: sPhrase,
73
86
  html: html,
74
87
  };
@@ -192,7 +205,8 @@ let EmailService = class EmailService {
192
205
  sTxt += ' table.kmSplitContentRightContentContainer,';
193
206
  sTxt += ' table.kmColumnContainer,';
194
207
  sTxt += ' td.kmVerticalButtonBarContentOuter table.kmButtonBarContent,';
195
- sTxt += ' td.kmVerticalButtonCollectionContentOuter table.kmButtonCollectionContent,';
208
+ sTxt +=
209
+ ' td.kmVerticalButtonCollectionContentOuter table.kmButtonCollectionContent,';
196
210
  sTxt += ' table.kmVerticalButton,';
197
211
  sTxt += ' table.kmVerticalButtonContent {';
198
212
  sTxt += ' width: 100% !important';
@@ -272,44 +286,68 @@ let EmailService = class EmailService {
272
286
  sTxt += ' }';
273
287
  sTxt += ' </style>';
274
288
  sTxt += '</head>';
275
- sTxt += '<body style="margin:0;padding:0;font-family:"Raleway", Helvetica, sans-serif;font-weight:400;letter-spacing:0.75px;line-height:180%;background-color:#F2F2F2">';
289
+ sTxt +=
290
+ '<body style="margin:0;padding:0;font-family:"Raleway", Helvetica, sans-serif;font-weight:400;letter-spacing:0.75px;line-height:180%;background-color:#F2F2F2">';
276
291
  sTxt += ' <center>';
277
- sTxt += ' <table align="center" border="0" cellpadding="0" cellspacing="0" id="bodyTable" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;padding:0;background-color:#F2F2F2;height:100%;margin:0;width:100%">';
292
+ sTxt +=
293
+ ' <table align="center" border="0" cellpadding="0" cellspacing="0" id="bodyTable" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;padding:0;background-color:#F2F2F2;height:100%;margin:0;width:100%">';
278
294
  sTxt += ' <tbody>';
279
295
  sTxt += ' <tr>';
280
- sTxt += ' <td align="center" id="bodyCell" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;padding-top:10px;padding-left:10px;padding-bottom:20px;padding-right:10px;border-top:0;height:100%;margin:0;width:100%">';
296
+ sTxt +=
297
+ ' <td align="center" id="bodyCell" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;padding-top:10px;padding-left:10px;padding-bottom:20px;padding-right:10px;border-top:0;height:100%;margin:0;width:100%">';
281
298
  sTxt += ' <!--[if !mso]>';
282
299
  sTxt += ' <!-->';
283
- sTxt += ' <div class="templateContainer" style="border:0 none #aaa;background-color:#F2F2F2;border-radius:0;display: table; width:90%">';
300
+ sTxt +=
301
+ ' <div class="templateContainer" style="border:0 none #aaa;background-color:#F2F2F2;border-radius:0;display: table; width:90%">';
284
302
  sTxt += ' <div class="templateContainerInner" style="padding:0">';
285
303
  sTxt += ' <!--';
286
304
  sTxt += ' <![endif]-->';
287
305
  sTxt += ' <!--[if mso]>';
288
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" class="templateContainer" width="90%" ';
289
- sTxt += ' style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
306
+ sTxt +=
307
+ ' <table border="0" cellpadding="0" cellspacing="0" class="templateContainer" width="90%" ';
308
+ sTxt +=
309
+ ' style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
290
310
  sTxt += ' <tbody>';
291
311
  sTxt += ' <tr>';
292
- sTxt += ' <td class="templateContainerInner" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
312
+ sTxt +=
313
+ ' <td class="templateContainerInner" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;">';
293
314
  sTxt += ' <![endif]-->';
294
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
315
+ sTxt +=
316
+ ' <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
295
317
  sTxt += ' <tr>';
296
- sTxt += ' <td align="center" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
297
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" class="templateRow" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
318
+ sTxt +=
319
+ ' <td align="center" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
320
+ sTxt +=
321
+ ' <table border="0" cellpadding="0" cellspacing="0" class="templateRow" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
298
322
  sTxt += ' <tbody>';
299
323
  sTxt += ' <tr>';
300
- sTxt += ' <td class="rowContainer kmFloatLeft" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
301
- sTxt += ' <table border="0" cellpadding="0" cellspacing="0" class="kmTextBlock" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
302
- sTxt += ' <tbody class="kmTextBlockOuter">';
324
+ sTxt +=
325
+ ' <td class="rowContainer kmFloatLeft" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
326
+ sTxt +=
327
+ ' <table border="0" cellpadding="0" cellspacing="0" class="kmTextBlock" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
328
+ sTxt +=
329
+ ' <tbody class="kmTextBlockOuter">';
303
330
  sTxt += ' <tr>';
304
- sTxt += ' <td class="kmTextBlockInner" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;background-color:#FFFFFF;">';
305
- sTxt += ' <table align="left" border="0" cellpadding="0" cellspacing="0" class="kmTextContentContainer" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
306
- sTxt += ' <tbody>';
307
- sTxt += ' <tr>';
308
- sTxt += ' <td class="kmTextContent" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;color:#272727;font-family:Helvetica, Arial;font-size:13px;line-height:200%;letter-spacing:normal;text-align:left;padding-top:40px;padding-bottom:40px;padding-left:40px;padding-right:40px;">';
309
- sTxt += ' <p>' + sPhrase + '<p>';
310
- sTxt += ' </td>';
311
- sTxt += ' </tr>';
312
- sTxt += ' </tbody>';
331
+ sTxt +=
332
+ ' <td class="kmTextBlockInner" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;background-color:#FFFFFF;">';
333
+ sTxt +=
334
+ ' <table align="left" border="0" cellpadding="0" cellspacing="0" class="kmTextContentContainer" width="100%" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0">';
335
+ sTxt +=
336
+ ' <tbody>';
337
+ sTxt +=
338
+ ' <tr>';
339
+ sTxt +=
340
+ ' <td class="kmTextContent" valign="top" style="border-collapse:collapse;mso-table-lspace:0;mso-table-rspace:0;color:#272727;font-family:Helvetica, Arial;font-size:13px;line-height:200%;letter-spacing:normal;text-align:left;padding-top:40px;padding-bottom:40px;padding-left:40px;padding-right:40px;">';
341
+ sTxt +=
342
+ ' <p>' +
343
+ sPhrase +
344
+ '<p>';
345
+ sTxt +=
346
+ ' </td>';
347
+ sTxt +=
348
+ ' </tr>';
349
+ sTxt +=
350
+ ' </tbody>';
313
351
  sTxt += ' </table>';
314
352
  sTxt += ' </td>';
315
353
  sTxt += ' </tr>';
@@ -1,10 +1,11 @@
1
- import { AccessiOptions } from "../../AccessiModule";
2
- import { EmailService } from "../EmailService/EmailService";
3
- import { FiltriUtente } from "../../Dtos/FiltriUtente";
4
- import { GetUsersResult } from "../../Dtos/GetUsersResponse";
5
- import { PermissionService } from "../PermissionService/PermissionService";
6
- import { UserDto } from "../../Dtos";
7
- import { RegisterRequest } from "../../Dtos/RegisterRequest";
1
+ import { AccessiOptions } from '../../AccessiModule';
2
+ import { StatoRegistrazione } from '../../Dtos/StatoRegistrazione';
3
+ import { EmailService } from '../EmailService/EmailService';
4
+ import { FiltriUtente } from '../../Dtos/FiltriUtente';
5
+ import { GetUsersResult } from '../../Dtos/GetUsersResponse';
6
+ import { PermissionService } from '../PermissionService/PermissionService';
7
+ import { UserDto } from '../../Dtos';
8
+ import { RegisterRequest } from '../../Dtos/RegisterRequest';
8
9
  export declare class UserService {
9
10
  private readonly accessiOptions;
10
11
  private readonly emailService;
@@ -27,5 +28,6 @@ export declare class UserService {
27
28
  register(registrationData: RegisterRequest): Promise<string>;
28
29
  updateUser(codiceUtente: number, user: UserDto): Promise<void>;
29
30
  deleteUser(codiceCliente: number): Promise<void>;
31
+ setStato(codiceCliente: number, statoRegistrazione: StatoRegistrazione): Promise<void>;
30
32
  setGdpr(codiceUtente: number): Promise<any>;
31
33
  }
@@ -80,29 +80,30 @@ let UserService = class UserService {
80
80
  queryParams.push(filters.codiceUtente);
81
81
  }
82
82
  query += ` ORDER BY U.CODUTE DESC `;
83
- let users = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams);
83
+ let users = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams));
84
84
  users = users.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
85
85
  let usersResponse = [];
86
- console.log("OPTIONS: ", options);
86
+ console.log('OPTIONS: ', options);
87
87
  for (const user of users) {
88
88
  let userGrants = null;
89
89
  if (options.includeGrants)
90
90
  userGrants = yield this.permissionService.getUserRolesAndGrants(user.codiceUtente);
91
91
  let extensionFields = options.includeExtensionFields ? {} : null;
92
+ //todo: se non è prendente extensionFieldOptions va in errore. Risolvere il problema
92
93
  if (options.includeExtensionFields) {
93
94
  for (const ext of this.accessiOptions.extensionFieldsOptions) {
94
- const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(",")} FROM ${ext.tableName} WHERE ${ext.tableJoinFieldName} = ?`, [user.codiceUtente])).map(Utilities_1.RestUtilities.convertKeysToCamelCase);
95
+ const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(',')} FROM ${ext.tableName} WHERE ${ext.tableJoinFieldName} = ?`, [user.codiceUtente])).map(Utilities_1.RestUtilities.convertKeysToCamelCase);
95
96
  extensionFields[ext.objectKey] = values;
96
97
  }
97
98
  }
98
99
  let userResult = {
99
100
  utente: user,
100
101
  userGrants: userGrants,
101
- extensionFields: extensionFields
102
+ extensionFields: extensionFields,
102
103
  };
103
104
  usersResponse.push(userResult);
104
105
  }
105
- console.log("OPTIONS: ", options);
106
+ console.log('OPTIONS: ', options);
106
107
  return usersResponse;
107
108
  }
108
109
  catch (error) {
@@ -114,7 +115,9 @@ let UserService = class UserService {
114
115
  return __awaiter(this, void 0, void 0, function* () {
115
116
  try {
116
117
  const query = `SELECT CODUTE as codice_utente FROM UTENTI WHERE LOWER(USRNAME) = ?`;
117
- const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email.trim().toLowerCase()]);
118
+ const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [
119
+ email.trim().toLowerCase(),
120
+ ]);
118
121
  return result.map(Utilities_1.RestUtilities.convertKeysToCamelCase)[0];
119
122
  }
120
123
  catch (error) {
@@ -144,8 +147,7 @@ let UserService = class UserService {
144
147
  INNER JOIN UTENTI_CONFIG C ON C.CODUTE = U.CODUTE
145
148
  WHERE LOWER(U.USRNAME) = ?
146
149
  `;
147
- const utenti = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email])
148
- .then(results => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase));
150
+ const utenti = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [email]).then((results) => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase)));
149
151
  return utenti.length > 0 ? utenti[0] : null;
150
152
  });
151
153
  }
@@ -164,8 +166,7 @@ let UserService = class UserService {
164
166
  FROM FILTRI F
165
167
  WHERE F.CODUTE = ?
166
168
  `;
167
- return yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente])
168
- .then(results => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase));
169
+ return (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente]).then((results) => results.map(Utilities_1.RestUtilities.convertKeysToCamelCase)));
169
170
  });
170
171
  }
171
172
  insertUserFilters(codiceUtente, filterData) {
@@ -181,7 +182,7 @@ let UserService = class UserService {
181
182
  codiceAgenzia: { dbField: 'CODAGE', type: 'string' },
182
183
  codiceClienteCollegato: { dbField: 'CODCLICOL', type: 'string' },
183
184
  codiceClienti: { dbField: 'CODCLIENTI', type: 'string' },
184
- tipoFiltro: { dbField: 'TIPFIL', type: 'string' }
185
+ tipoFiltro: { dbField: 'TIPFIL', type: 'string' },
185
186
  };
186
187
  const fieldsToInsert = Object.entries(fieldMapping)
187
188
  .filter(([tsField]) => {
@@ -203,9 +204,9 @@ let UserService = class UserService {
203
204
  }
204
205
  yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
205
206
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, 'DELETE FROM FILTRI WHERE CODUTE = ?', [codiceUtente]);
206
- const dbFields = ['CODUTE', ...fieldsToInsert.map(f => f.dbField)];
207
+ const dbFields = ['CODUTE', ...fieldsToInsert.map((f) => f.dbField)];
207
208
  const placeholders = dbFields.map(() => '?');
208
- const values = [codiceUtente, ...fieldsToInsert.map(f => f.value)];
209
+ const values = [codiceUtente, ...fieldsToInsert.map((f) => f.value)];
209
210
  const insertQuery = `INSERT INTO FILTRI (${dbFields.join(', ')}) VALUES (${placeholders.join(', ')})`;
210
211
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, insertQuery, values);
211
212
  }));
@@ -223,9 +224,9 @@ let UserService = class UserService {
223
224
  register(registrationData) {
224
225
  return __awaiter(this, void 0, void 0, function* () {
225
226
  try {
226
- const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, "SELECT CODUTE FROM UTENTI WHERE USRNAME = ?", [registrationData.email]);
227
+ const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT CODUTE FROM UTENTI WHERE USRNAME = ?', [registrationData.email]);
227
228
  if (existingUser.length > 0) {
228
- throw new Error("Questa e-mail è già stata utilizzata!");
229
+ throw new Error('Questa e-mail è già stata utilizzata!');
229
230
  }
230
231
  const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?) RETURNING CODUTE`;
231
232
  const paramsUtenti = [registrationData.email, StatoRegistrazione_1.StatoRegistrazione.INVIO];
@@ -270,24 +271,24 @@ let UserService = class UserService {
270
271
  return __awaiter(this, void 0, void 0, function* () {
271
272
  try {
272
273
  if (!codiceUtente)
273
- throw new Error("Impossibile aggiornare senza codice utente.");
274
+ throw new Error('Impossibile aggiornare senza codice utente.');
274
275
  // Costruzione dinamica della query per UTENTI
275
276
  const utentiUpdates = [];
276
277
  const utentiParams = [];
277
278
  if (user.email !== undefined) {
278
- utentiUpdates.push("usrname = ?");
279
+ utentiUpdates.push('usrname = ?');
279
280
  utentiParams.push(user.email);
280
281
  }
281
282
  if (user.flagGdpr !== undefined) {
282
- utentiUpdates.push("flggdpr = ?");
283
+ utentiUpdates.push('flggdpr = ?');
283
284
  utentiParams.push(user.flagGdpr);
284
285
  }
285
286
  if (user.statoRegistrazione !== undefined) {
286
- utentiUpdates.push("stareg = ?");
287
+ utentiUpdates.push('stareg = ?');
287
288
  utentiParams.push(user.statoRegistrazione);
288
289
  }
289
290
  if (utentiUpdates.length > 0) {
290
- const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(", ")} WHERE CODUTE = ?`;
291
+ const queryUtenti = `UPDATE UTENTI SET ${utentiUpdates.join(', ')} WHERE CODUTE = ?`;
291
292
  utentiParams.push(codiceUtente);
292
293
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, utentiParams);
293
294
  }
@@ -295,47 +296,47 @@ let UserService = class UserService {
295
296
  const utentiConfigUpdates = [];
296
297
  const utentiConfigParams = [];
297
298
  if (user.cognome !== undefined) {
298
- utentiConfigUpdates.push("cognome = ?");
299
+ utentiConfigUpdates.push('cognome = ?');
299
300
  utentiConfigParams.push(user.cognome);
300
301
  }
301
302
  if (user.nome !== undefined) {
302
- utentiConfigUpdates.push("nome = ?");
303
+ utentiConfigUpdates.push('nome = ?');
303
304
  utentiConfigParams.push(user.nome);
304
305
  }
305
306
  if (user.avatar !== undefined) {
306
- utentiConfigUpdates.push("avatar = ?");
307
+ utentiConfigUpdates.push('avatar = ?');
307
308
  utentiConfigParams.push(user.avatar);
308
309
  }
309
310
  if (user.flagDueFattori !== undefined) {
310
- utentiConfigUpdates.push("flg2fatt = ?");
311
+ utentiConfigUpdates.push('flg2fatt = ?');
311
312
  utentiConfigParams.push(user.flagDueFattori);
312
313
  }
313
314
  if (user.codiceLingua !== undefined) {
314
- utentiConfigUpdates.push("codlingua = ?");
315
+ utentiConfigUpdates.push('codlingua = ?');
315
316
  utentiConfigParams.push(user.codiceLingua);
316
317
  }
317
318
  if (user.cellulare !== undefined) {
318
- utentiConfigUpdates.push("cellulare = ?");
319
+ utentiConfigUpdates.push('cellulare = ?');
319
320
  utentiConfigParams.push(user.cellulare);
320
321
  }
321
322
  if (user.flagSuper !== undefined) {
322
- utentiConfigUpdates.push("flgsuper = ?");
323
+ utentiConfigUpdates.push('flgsuper = ?');
323
324
  utentiConfigParams.push(user.flagSuper);
324
325
  }
325
326
  if (user.paginaDefault !== undefined) {
326
- utentiConfigUpdates.push("pagdef = ?");
327
+ utentiConfigUpdates.push('pagdef = ?');
327
328
  utentiConfigParams.push(user.paginaDefault);
328
329
  }
329
330
  if (user.jsonMetadata !== undefined) {
330
- utentiConfigUpdates.push("json_metadata = ?");
331
+ utentiConfigUpdates.push('json_metadata = ?');
331
332
  utentiConfigParams.push(user.jsonMetadata);
332
333
  }
333
334
  if (user.ragSocCli !== undefined) {
334
- utentiConfigUpdates.push("ragsoccli = ?");
335
+ utentiConfigUpdates.push('ragsoccli = ?');
335
336
  utentiConfigParams.push(user.ragSocCli);
336
337
  }
337
338
  if (utentiConfigUpdates.length > 0) {
338
- const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(", ")} WHERE CODUTE = ?`;
339
+ const queryUtentiConfig = `UPDATE UTENTI_CONFIG SET ${utentiConfigUpdates.join(', ')} WHERE CODUTE = ?`;
339
340
  utentiConfigParams.push(codiceUtente);
340
341
  yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
341
342
  }
@@ -355,7 +356,24 @@ let UserService = class UserService {
355
356
  return __awaiter(this, void 0, void 0, function* () {
356
357
  try {
357
358
  const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
358
- yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [StatoRegistrazione_1.StatoRegistrazione.DELETE, codiceCliente]);
359
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
360
+ StatoRegistrazione_1.StatoRegistrazione.DELETE,
361
+ codiceCliente,
362
+ ]);
363
+ }
364
+ catch (error) {
365
+ throw error;
366
+ }
367
+ });
368
+ }
369
+ setStato(codiceCliente, statoRegistrazione) {
370
+ return __awaiter(this, void 0, void 0, function* () {
371
+ try {
372
+ const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
373
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [
374
+ statoRegistrazione,
375
+ codiceCliente,
376
+ ]);
359
377
  }
360
378
  catch (error) {
361
379
  throw error;
@@ -381,5 +399,6 @@ exports.UserService = UserService = __decorate([
381
399
  autobind_1.autobind,
382
400
  (0, common_1.Injectable)(),
383
401
  __param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
384
- __metadata("design:paramtypes", [Object, EmailService_1.EmailService, PermissionService_1.PermissionService])
402
+ __metadata("design:paramtypes", [Object, EmailService_1.EmailService,
403
+ PermissionService_1.PermissionService])
385
404
  ], UserService);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.4.0-dev.1",
3
+ "version": "1.4.0-dev.11",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",