emilsoftware-utilities 1.3.94 → 1.3.95

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.
@@ -108,7 +108,6 @@ export declare class CryptUtilities {
108
108
  */
109
109
  static decrypt(encryptedData: string, key: string): string | null;
110
110
  }
111
- export declare function Deprecated(message: string): (target: any, key?: string, descriptor?: PropertyDescriptor) => void;
112
111
  /**
113
112
  * Utility class for managing database-related configurations and operations.
114
113
  */
@@ -136,3 +135,4 @@ export declare class DatabaseUtilities {
136
135
  */
137
136
  static createOption(host: string, port: number, database: string, username?: string, password?: string): Options;
138
137
  }
138
+ export declare function Deprecated(message: string): (target: any, key?: string, descriptor?: PropertyDescriptor) => void;
package/dist/Utilities.js CHANGED
@@ -269,11 +269,6 @@ class CryptUtilities {
269
269
  }
270
270
  }
271
271
  exports.CryptUtilities = CryptUtilities;
272
- function Deprecated(message) {
273
- return function (target, key, descriptor) {
274
- console.warn(`⚠️ [DEPRECATED] ${message}`);
275
- };
276
- }
277
272
  /**
278
273
  * Utility class for managing database-related configurations and operations.
279
274
  */
@@ -315,3 +310,8 @@ class DatabaseUtilities {
315
310
  }
316
311
  }
317
312
  exports.DatabaseUtilities = DatabaseUtilities;
313
+ function Deprecated(message) {
314
+ return function (target, key, descriptor) {
315
+ console.warn(`⚠️ [DEPRECATED] ${message}`);
316
+ };
317
+ }
@@ -81,7 +81,7 @@ let AccessiController = AccessiController_1 = class AccessiController {
81
81
  resetPassword(res, token, newPassword) {
82
82
  return __awaiter(this, void 0, void 0, function* () {
83
83
  try {
84
- yield this.authService.resetPassword(token, newPassword);
84
+ yield this.authService.confirmResetPassword(token, newPassword);
85
85
  return Utilities_1.RestUtilities.sendOKMessage(res, 'Password aggiornata con successo!');
86
86
  }
87
87
  catch (error) {
@@ -69,7 +69,7 @@ let AuthController = AuthController_1 = class AuthController {
69
69
  resetPassword(res, token, newPassword) {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
71
  try {
72
- yield this.authService.resetPassword(token, newPassword);
72
+ yield this.authService.confirmResetPassword(token, newPassword);
73
73
  return Utilities_1.RestUtilities.sendOKMessage(res, 'Password aggiornata con successo!');
74
74
  }
75
75
  catch (error) {
@@ -113,7 +113,7 @@ let AuthController = AuthController_1 = class AuthController {
113
113
  };
114
114
  exports.AuthController = AuthController;
115
115
  __decorate([
116
- (0, common_1.Post)('reset-password/:token'),
116
+ (0, common_1.Post)('confirm-reset-password/:token'),
117
117
  __param(0, (0, common_1.Res)()),
118
118
  __param(1, (0, common_1.Param)('token')),
119
119
  __param(2, (0, common_1.Body)("newPassword")),
@@ -59,7 +59,7 @@ let EmailController = class EmailController {
59
59
  exports.EmailController = EmailController;
60
60
  __decorate([
61
61
  (0, swagger_1.ApiOperation)({ summary: 'Serve una pagina per il reset della password' }),
62
- (0, common_1.Get)('reset-password/:token'),
62
+ (0, common_1.Get)('reset-password-page/:token'),
63
63
  __param(0, (0, common_1.Res)()),
64
64
  __param(1, (0, common_1.Param)('token')),
65
65
  __metadata("design:type", Function),
@@ -67,8 +67,8 @@ __decorate([
67
67
  __metadata("design:returntype", Promise)
68
68
  ], EmailController.prototype, "serveResetPasswordPage", null);
69
69
  __decorate([
70
- (0, swagger_1.ApiOperation)({ summary: 'Registra un nuovo utente' }),
71
- (0, common_1.Post)('send-reset-password'),
70
+ (0, swagger_1.ApiOperation)({ summary: 'Invia una e-mail per il reset della password' }),
71
+ (0, common_1.Post)('send-reset-password-email'),
72
72
  __param(0, (0, common_1.Req)()),
73
73
  __param(1, (0, common_1.Body)()),
74
74
  __param(2, (0, common_1.Res)()),
@@ -77,7 +77,7 @@ __decorate([
77
77
  __metadata("design:returntype", Promise)
78
78
  ], EmailController.prototype, "sendPasswordResetEmail", null);
79
79
  exports.EmailController = EmailController = __decorate([
80
- (0, swagger_1.ApiTags)('Auth'),
80
+ (0, swagger_1.ApiTags)('Email'),
81
81
  (0, common_1.Controller)('accessi/email'),
82
82
  __param(1, (0, common_1.Inject)('ACCESSI_OPTIONS')),
83
83
  __metadata("design:paramtypes", [EmailService_1.EmailService, Object])
@@ -12,5 +12,5 @@ export declare class AuthService implements IAuthService {
12
12
  verifyPassword(codiceUtente: string, passwordCifrata: string): Promise<boolean>;
13
13
  getAdminUser(): ILoginResult;
14
14
  getDemoUser(): ILoginResult;
15
- resetPassword(token: string, newPassword: string): Promise<void>;
15
+ confirmResetPassword(token: string, newPassword: string): Promise<void>;
16
16
  }
@@ -129,7 +129,7 @@ let AuthService = class AuthService {
129
129
  abilitazioni: []
130
130
  };
131
131
  }
132
- resetPassword(token, newPassword) {
132
+ confirmResetPassword(token, newPassword) {
133
133
  return __awaiter(this, void 0, void 0, function* () {
134
134
  try {
135
135
  // Controlliamo se il token esiste
@@ -60,5 +60,5 @@ export interface IAuthService {
60
60
  * @returns {Promise<void>} - Nessun valore di ritorno se il reset ha successo.
61
61
  * @throws {Error} - Se il token è invalido o già usato, o se si verifica un errore nel database.
62
62
  */
63
- resetPassword(token: string, newPassword: string): Promise<void>;
63
+ confirmResetPassword(token: string, newPassword: string): Promise<void>;
64
64
  }
@@ -29,6 +29,7 @@ const nodemailer_1 = __importDefault(require("nodemailer"));
29
29
  const uuid_1 = require("uuid");
30
30
  const Orm_1 = require("../../../Orm");
31
31
  const common_1 = require("@nestjs/common");
32
+ const StatoRegistrazione_1 = require("../../models/StatoRegistrazione");
32
33
  let EmailService = class EmailService {
33
34
  constructor(accessiOptions) {
34
35
  this.accessiOptions = accessiOptions;
@@ -42,11 +43,11 @@ let EmailService = class EmailService {
42
43
  try {
43
44
  const resetToken = (0, uuid_1.v4)(); // Generiamo un nuovo token unico
44
45
  // Aggiorna il campo keyReg nel database
45
- const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, "UPDATE UTENTI SET KEYREG = ? WHERE USRNAME = ? RETURNING CODUTE", [resetToken, email]);
46
+ 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]);
46
47
  if (result.length === 0) {
47
48
  throw new Error("Email non trovata.");
48
49
  }
49
- const resetUrl = `${baseUrl}/api/accessi/reset-password/${resetToken}`;
50
+ const resetUrl = `${baseUrl}/api/accessi/email/reset-password/${resetToken}`;
50
51
  const mailOptions = {
51
52
  from: this.accessiOptions.emailOptions.from,
52
53
  to: email,
@@ -107,12 +107,4 @@ export interface IUserService {
107
107
  * @throws {Error} Se la query fallisce o si verifica un problema durante l'esecuzione.
108
108
  */
109
109
  getUserFilters(codiceUtente: string): Promise<IFiltriUtente[]>;
110
- /**
111
- * Verifica l'email di un utente utilizzando un token univoco.
112
- *
113
- * @param {string} token - Il token di verifica (`keyReg`) ricevuto via email.
114
- * @returns {Promise<void>} - Nessun valore di ritorno se la verifica ha successo.
115
- * @throws {Error} - Se il token è invalido o già usato, o se si verifica un errore nel database.
116
- */
117
- verifyEmail(token: string): Promise<void>;
118
110
  }
@@ -19,5 +19,4 @@ export declare class UserService implements IUserService {
19
19
  deleteUser(codiceCliente: string): Promise<void>;
20
20
  setGdpr(codiceUtente: string): Promise<any>;
21
21
  setStatoRegistrazione(statoRegistrazione: StatoRegistrazione, codiceUtente: string): Promise<any>;
22
- verifyEmail(token: string): Promise<void>;
23
22
  }
@@ -56,8 +56,9 @@ let UserService = class UserService {
56
56
  G.PAGDEF as pagina_default,
57
57
  G.JSON_METADATA as json_metadata
58
58
  FROM UTENTI U INNER JOIN UTENTI_CONFIG G ON U.CODUTE = G.CODUTE
59
+ WHERE STAREG <> ?
59
60
  ORDER BY U.CODUTE`;
60
- const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, []);
61
+ const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [StatoRegistrazione_1.StatoRegistrazione.DELETE]);
61
62
  return result.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
62
63
  }
63
64
  catch (error) {
@@ -181,8 +182,8 @@ let UserService = class UserService {
181
182
  deleteUser(codiceCliente) {
182
183
  return __awaiter(this, void 0, void 0, function* () {
183
184
  try {
184
- const query = `DELETE FROM UTENTI WHERE CODUTE = ?`;
185
- yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [codiceCliente]);
185
+ const query = `UPDATE UTENTI SET STAREG = ? WHERE CODUTE = ?`;
186
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [StatoRegistrazione_1.StatoRegistrazione.DELETE, codiceCliente]);
186
187
  }
187
188
  catch (error) {
188
189
  throw error;
@@ -192,8 +193,8 @@ let UserService = class UserService {
192
193
  setGdpr(codiceUtente) {
193
194
  return __awaiter(this, void 0, void 0, function* () {
194
195
  try {
195
- let query = ` UPDATE OR INSERT UTENTI_GDPR SET CODUTE = ? `;
196
- let params = [codiceUtente];
196
+ let query = ` UPDATE OR INSERT UTENTI_GDPR SET CODUTE = ?, GDPR = ? `;
197
+ let params = [codiceUtente, true];
197
198
  let result = yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, params);
198
199
  return result;
199
200
  }
@@ -215,23 +216,6 @@ let UserService = class UserService {
215
216
  }
216
217
  });
217
218
  }
218
- verifyEmail(token) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- try {
221
- // Controlliamo se il token esiste
222
- const result = yield Orm_1.Orm.query({}, "SELECT CODUTE FROM UTENTI WHERE KEYREG = ?", [token]);
223
- if (result.length === 0) {
224
- throw new Error("Token non valido o già usato.");
225
- }
226
- // Attiviamo l'account e rimuoviamo il token
227
- yield Orm_1.Orm.query({}, "UPDATE UTENTI SET STAREG = ?, KEYREG = NULL WHERE CODUTE = ?", [StatoRegistrazione_1.StatoRegistrazione.CONF, result[0].CODUTE]);
228
- }
229
- catch (error) {
230
- console.error("Errore nella verifica email:", error);
231
- throw new Error("Errore durante la verifica dell'email.");
232
- }
233
- });
234
- }
235
219
  };
236
220
  exports.UserService = UserService;
237
221
  exports.UserService = UserService = __decorate([
@@ -1,51 +1,177 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="it">
3
+
3
4
  <head>
4
5
  <meta charset="UTF-8">
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
7
  <title>Reset Password</title>
8
+ <style>
9
+ * {
10
+ box-sizing: border-box;
11
+ margin: 0;
12
+ padding: 0;
13
+ font-family: Arial, sans-serif;
14
+ }
15
+
16
+ body {
17
+ display: flex;
18
+ justify-content: center;
19
+ align-items: center;
20
+ height: 100vh;
21
+ background: linear-gradient(135deg, #0068ae, #004e80, #002c50);
22
+ color: #fff;
23
+ }
24
+
25
+ .container {
26
+ background: rgba(255, 255, 255, 0.15);
27
+ padding: 25px;
28
+ border-radius: 12px;
29
+ backdrop-filter: blur(12px);
30
+ box-shadow: 0px 4px 15px rgba(0, 0, 0, 0.3);
31
+ width: 380px;
32
+ text-align: center;
33
+ border: 1px solid rgba(255, 255, 255, 0.2);
34
+ }
35
+
36
+ h1 {
37
+ font-size: 24px;
38
+ margin-bottom: 15px;
39
+ color: #ffffff;
40
+ }
41
+
42
+ .form-group {
43
+ margin: 12px 0;
44
+ text-align: left;
45
+ }
46
+
47
+ label {
48
+ font-size: 14px;
49
+ font-weight: bold;
50
+ display: block;
51
+ margin-bottom: 5px;
52
+ color: #ffffff;
53
+ }
54
+
55
+ input {
56
+ width: 100%;
57
+ padding: 12px;
58
+ border: none;
59
+ border-radius: 6px;
60
+ font-size: 14px;
61
+ margin-top: 5px;
62
+ background: rgba(255, 255, 255, 0.15);
63
+ color: #ffffff;
64
+ border: 1px solid rgba(255, 255, 255, 0.3);
65
+ }
66
+
67
+ input:focus {
68
+ outline: none;
69
+ border: 2px solid #ffffff;
70
+ background: rgba(255, 255, 255, 0.2);
71
+ }
72
+
73
+ .error {
74
+ color: #ff6b6b;
75
+ font-size: 12px;
76
+ margin-top: 5px;
77
+ display: none;
78
+ }
79
+
80
+ button {
81
+ background: linear-gradient(90deg, #0080ff, #0068ae);
82
+ border: none;
83
+ padding: 12px;
84
+ font-size: 16px;
85
+ border-radius: 6px;
86
+ width: 100%;
87
+ color: #ffffff;
88
+ cursor: pointer;
89
+ font-weight: bold;
90
+ transition: all 0.3s ease;
91
+ box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.2);
92
+ }
93
+
94
+ button:hover {
95
+ background: linear-gradient(90deg, #0095ff, #0070c0);
96
+ transform: scale(1.05);
97
+ }
98
+ </style>
7
99
  </head>
100
+
8
101
  <body>
9
- <h1>Reimposta la tua password</h1>
10
- <form id="resetForm">
11
- <input type="hidden" id="token" value="">
12
- <input type="hidden" id="redirectUrl" value="">
13
- <label for="password">Nuova Password:</label>
14
- <input type="password" id="password" required>
15
- <button type="submit">Aggiorna Password</button>
16
- </form>
102
+ <div class="container">
103
+ <h1>Reimposta la tua password</h1>
104
+ <form id="resetForm">
105
+ <input type="hidden" id="token" value="">
106
+ <input type="hidden" id="redirectUrl" value="">
107
+
108
+ <div class="form-group">
109
+ <label for="password">Nuova Password:</label>
110
+ <input type="password" id="password" required>
111
+ <p class="error" id="passwordError">La password deve avere almeno 6 caratteri.</p>
112
+ </div>
113
+
114
+ <div class="form-group">
115
+ <label for="confirmPassword">Conferma Password:</label>
116
+ <input type="password" id="confirmPassword" required>
117
+ <p class="error" id="confirmError">Le password non corrispondono.</p>
118
+ </div>
119
+
120
+ <button type="submit">Aggiorna password</button>
121
+ </form>
122
+ </div>
123
+
17
124
  <script>
18
- document.addEventListener("DOMContentLoaded", function() {
125
+ document.addEventListener("DOMContentLoaded", function () {
19
126
  const urlParams = new URLSearchParams(window.location.search);
20
127
  const token = window.location.pathname.split("/").pop();
21
- const redirectUrl = urlParams.get("redirectUrl") || "/"; // Default: Home
128
+ const redirectUrl = urlParams.get("redirectUrl") || "/";
22
129
 
23
130
  document.getElementById("token").value = token;
24
131
  document.getElementById("redirectUrl").value = redirectUrl;
25
-
26
- document.getElementById("resetForm").addEventListener("submit", async function(event) {
132
+
133
+ document.getElementById("resetForm").addEventListener("submit", async function (event) {
27
134
  event.preventDefault();
28
135
  const password = document.getElementById("password").value;
136
+ const confirmPassword = document.getElementById("confirmPassword").value;
137
+ const passwordError = document.getElementById("passwordError");
138
+ const confirmError = document.getElementById("confirmError");
139
+
140
+ // Reset messaggi di errore
141
+ passwordError.style.display = "none";
142
+ confirmError.style.display = "none";
143
+
144
+ // Validazioni
145
+ if (password.length < 6) {
146
+ passwordError.style.display = "block";
147
+ return;
148
+ }
29
149
 
30
- if (!password) {
31
- alert("Inserisci una nuova password.");
150
+ if (password !== confirmPassword) {
151
+ confirmError.style.display = "block";
32
152
  return;
33
153
  }
34
-
35
- const response = await fetch(`/api/accessi/reset-password/${token}`, {
36
- method: "POST",
37
- headers: { "Content-Type": "application/json" },
38
- body: JSON.stringify({ newPassword: password })
39
- });
40
-
41
- const data = await response.json();
42
- alert(data.message || "Password aggiornata con successo!");
43
-
44
- if (response.ok) {
45
- window.location.href = redirectUrl;
154
+
155
+ // Effettua la richiesta API
156
+ try {
157
+ const response = await fetch(`/api/accessi/auth/confirm-reset-password/${token}`, {
158
+ method: "POST",
159
+ headers: { "Content-Type": "application/json" },
160
+ body: JSON.stringify({ newPassword: password })
161
+ });
162
+
163
+ const data = await response.json();
164
+ alert(data.message || "Password aggiornata con successo!");
165
+
166
+ if (response.ok) {
167
+ window.location.href = redirectUrl;
168
+ }
169
+ } catch (error) {
170
+ alert("Errore nel reset della password. Riprova più tardi.");
46
171
  }
47
172
  });
48
173
  });
49
174
  </script>
50
175
  </body>
176
+
51
177
  </html>
@@ -13,8 +13,8 @@ exports.StatoRegistrazione = exports.AccessiModule = void 0;
13
13
  exports.initializeAccessiModule = initializeAccessiModule;
14
14
  const core_1 = require("@nestjs/core");
15
15
  const platform_express_1 = require("@nestjs/platform-express");
16
- const SwaggerConfig_1 = require("./swagger/SwaggerConfig");
17
16
  const AccessiModule_1 = require("./AccessiModule");
17
+ const SwaggerConfig_1 = require("./swagger/SwaggerConfig");
18
18
  function initializeAccessiModule(app, options) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
20
  try {
@@ -28,8 +28,8 @@ function initializeAccessiModule(app, options) {
28
28
  nestApp.setGlobalPrefix('api', {
29
29
  exclude: ['/swagger', '/swagger/(.*)']
30
30
  });
31
+ (0, SwaggerConfig_1.setupSwagger)(nestApp);
31
32
  yield nestApp.init();
32
- (0, SwaggerConfig_1.serveSwaggerDocs)(nestApp);
33
33
  console.log('Verifica API NestJS registrate:');
34
34
  const server = nestApp.getHttpAdapter().getInstance();
35
35
  const router = server.router;
@@ -1,2 +1,2 @@
1
- import { INestApplication } from '@nestjs/common';
2
- export declare function serveSwaggerDocs(app: INestApplication): void;
1
+ import { INestApplication } from "@nestjs/common";
2
+ export declare function setupSwagger(app: INestApplication): void;
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serveSwaggerDocs = serveSwaggerDocs;
3
+ exports.setupSwagger = setupSwagger;
4
4
  const swagger_1 = require("@nestjs/swagger");
5
- function serveSwaggerDocs(app) {
5
+ function setupSwagger(app) {
6
6
  const config = new swagger_1.DocumentBuilder()
7
- .setTitle('Accessi API')
8
- .setDescription('Documentazione delle API per la gestione degli accessi')
9
- .setVersion('1.0')
7
+ .setTitle("Accessi API")
8
+ .setDescription("API per la gestione degli accessi utenti")
9
+ .setVersion("1.0")
10
+ .addBearerAuth() // Per abilitare l'autenticazione JWT
10
11
  .build();
11
- const documentFactory = () => swagger_1.SwaggerModule.createDocument(app, config);
12
- swagger_1.SwaggerModule.setup('swagger', app, documentFactory);
13
- console.log('Swagger UI disponibile su http://localhost:3000/swagger/accessi');
12
+ const document = swagger_1.SwaggerModule.createDocument(app, config);
13
+ swagger_1.SwaggerModule.setup("swagger", app, document);
14
+ console.log("✅ Swagger disponibile su: http://localhost:3000/swagger");
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.3.94",
3
+ "version": "1.3.95",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",